我正在尝试从 JTabbedPane 内的 JFileChooser 加载文件。我希望在单击“打开”按钮时加载文件,并在不同的窗格中显示文件。我希望我能很好地解释自己。我有一个 ActionListener 并尝试了一些事情,但似乎我正在使用的代码没有触发,因为它甚至不会打印到控制台。你能否看看我的代码,看看我哪里出错了。谢谢
class listener implements ActionListener{
public void actionPerformed (ActionEvent e)
{.......// other actions
else if (e.getSource() instanceof JFileChooser){
JFileChooser openFile = (JFileChooser)e.getSource();
String command = e.getActionCommand();
if (command.equals(JFileChooser.APPROVE_SELECTION)){
File selectedFile = openFile.getSelectedFile();
System.out.print("test if working");
tp.setSelectedIndex(0); //Index of JTab I wand file to load
loadSavedGame(selectedFile);
}
else if (resume.equals(JFileChooser.CANCEL_OPTION)) {
//frame.setVisible(true);
tp.setSelectedIndex(0);
}
}
}
}