I'm working on a big GUI, using NetBeans since it simplified the initial container design... but now I need to link all the components to actions and events... which I'm not very experienced with.
I made a dummy GUI that does similar, but far fewer functions like my real project. Can someone help me design the actions/events for this little dummy gui, and explain how they work, so I can use that as a guide...?
The dummy project has two
java files. A Scan class (Scan.java) will be used to parse a 'patient' text file, and create a
String with info from that file (Scan.patient), as well as store the original pathname (Scan.path).
http://deviantone.com/javagui/Scan.java You can create a Scan object by giving the constructor a File or String (file path) argument. You can then call the patient or path vars. The dummy 3 line patient file:
http://deviantone.com/javagui/dummy.txt Now the hard part, the GUI from NetBeans... the syntax is a little bloated since it's machine generated, but shouldn't be too hard to figure out.
http://deviantone.com/javagui/dummyGui.java The GUI is meant to parse whatever text file opened (for the purposes of this dummy gui, only dummy.txt will ever be browsed to, since the program can handle only 3 lines) into C:\output.txt (which you can create and leave blank beforehand).
What I need:
(1) The Open button (JButton openButton) needs to call a file chooser, where a user can browse to our dummy text file. dummyGui.java should then make a Scan object using this file.
(2) Once opened, the file path should appear in the JLabel pathLabel (you can use another gui component instead of a JLabel if you want, I just didn't know what would be the appropriate one for this sort of operation)
(3) You can select Yes/No or input some text into the combo box (JComboBox statusCombo) as well as input stuff into a text field, let's say a date (JTextField dateField). This information will also be written into output.txt
(4) Once you hit the Write button, Scan.patient, and the contents of statusCombo and dateField should be written into output.txt (it doesn't matter what line contains what, for simplicity maybe make statusCombo first, then dateField, then Scan.patient which is 2 lines)... I just need to see how to make a button do such an operation using another Object (Scan) as well as user input...
So far, I have looked through the API and File Chooser examples, and I've added the following to my code:
- instance variable to the dummyGui.java: File file; for the file that file chooser will get.
- also added openButton.addActionListener(this); to the initComponents() method.
- and another method:
But when I run the GUI, and hit Open, the button gets pressed in and then the window freezes while no file browser shows ... =/