java - error message with JButton and JFileChooser -
i want have button jfilechooser action. code wrote:
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()); } { } } }
but problem when run it, got long error message part of:
exception in thread "awt-eventqueue-0" java.lang.unsupportedoperationexception: not supported yet. @ main.main$1.actionperformed(main.java:200) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:2018) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2341) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:402)
the actionlistener
here explicitly throwing unsupportedoperationexception
. move jfilechooser
functionality actionlistener
:
input_button.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { jfilechooser inputfile = new jfilechooser(); inputfile.setfileselectionmode(jfilechooser.files_and_directories); if (inputfile.showopendialog(myframe) == jfilechooser.approve_option) { file file1 = inputfile.getselectedfile(); string fullpathtemp = (string) file1.getabsolutepath(); ... } } });
Comments
Post a Comment