1
我有兩個獨立工作的工作類。我想合併它們,但我沒有工作位置來添加public void (String Name){
。我不斷收到「刪除此」或「添加}」。通過Java中的方法組合類
代碼,我有:
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循環的一部分運行。
@TylerSchroder,同樣,修復您的縮進。不好的縮進正是爲什麼這種問題很難被發現。 – CandiedOrange 2015-04-05 16:14:09
@Eran我曾嘗試過,但是,它拋出所有其他}。 – 2015-04-05 22:34:16