在Java中通过方法组合类
我有两个独立工作的工人阶级。我想合并它们,但我没有工作位置来添加在Java中通过方法组合类,java,ms-word,Java,Ms Word,我有两个独立工作的工人阶级。我想合并它们,但我没有工作位置来添加公共void(字符串名){。我一直得到一个“remove this”或“add}” 我有: import java.io.File; import java.awt.event.*; import javax.swing.*; import java.awt.*; public class WordDocument extends JFrame { private JButton btnOpen; private JLabel j
公共void(字符串名){
。我一直得到一个“remove this”或“add}”
我有:
import java.io.File;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class WordDocument extends JFrame {
private JButton btnOpen;
private JLabel jLabel1;
private JTextField txtDocNumber;
public void SystemFiles() {
private static String DIR ="c:\\Users\\tyler's account\\folders\\JavaReaderFiles\\"; // folder where word documents are present.
public WordDocument() {
super("Open Word Document");
initComponents();
}
private void initComponents() {
jLabel1 = new JLabel();
txtDocNumber = new JTextField();
btnOpen = new JButton();
Container c = getContentPane();
c.setLayout(new java.awt.FlowLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Enter Document Number : ");
c.add(jLabel1);
txtDocNumber.setColumns(5);
c.add(txtDocNumber);
btnOpen.setText("Open Document");
btnOpen.addActionListener(new ActionListener() { // anonymous inner class
public void actionPerformed(ActionEvent evt) {
Desktop desktop = Desktop.getDesktop();
try {
File f = new File( DIR + txtDocNumber.getText() + ".doc");
desktop.open(f); // opens application (MSWord) associated with .doc file
}
catch(Exception ex) {
// WordDocument.this is to refer to outer class's instance from inner class
JOptionPane.showMessageDialog(WordDocument.this,ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
}
}
});
c.add(btnOpen);
}
public static void main(String args[]) {
WordDocument wd = new WordDocument();
wd.setSize(300,100);
wd.setVisible(true);
}
}
我不知道在哪里添加该方法。我曾尝试更改私有/公共类,并不断收到多个错误。我需要它作为IF循环的一部分运行
public void SystemFiles() {
看起来您启动了此方法,但没有使用
}
关闭它,也没有向其添加任何正文。@TylerSchroder,还有,请修复缩进。不良的缩进正是这种问题很难发现的原因。@Eran我试过了,但是,它每隔一次就抛出一次。