我想有一个JFileChooser动作的按钮。 这是我写的代码:
public class Main {
private static String fullPath;
private JFileChooser inputFile;
public static void main(String args[]) throws FileNotFoundException, IOException {
try {
GridBagConstraints gbc = new GridBagConstraints();
JButton inputButton = new JButton("Browse input file");
myPanel.add(inputButton, gbc);
inputButton.addActionListener(new ActionListener() {
public void ActionPerformed(ActionEvent e) {
JFileChooser inputFile = new JFileChooser();
inputFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
File file1 = inputFile.getSelectedFile();
String fullpathTemp = (String) file1.getAbsolutePath();
fullPath = fullpathTemp;
}
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
} finally {
}
}
}
但问题是,当我运行它,我还有很长的错误消息的一部分:
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
at main.Main$1.actionPerformed(Main.java:200)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)