aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Using Swing to Create Data Entry Forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using Swing to Create Data Entry Forms" Watch "Using Swing to Create Data Entry Forms" New topic
Author

Using Swing to Create Data Entry Forms

Robert Gann
Greenhorn

Joined: Jul 27, 2005
Posts: 3
I'm starting with Swing programming, so I hope that I am not wasting bandwidth on something trivial. However, I'm really stuck.

I'm creating a Swing application involving students. I've created a JFrame and populated it with JComboBoxes, JCheckBoxes, JRadioButtons and the appropriate event handlers. I read a list of students from a file and populate a JComboBox. When the application is run, the results are written to a file. This all works fine. The "Submit" button causes the data to be written to the file.

I have two questions. First, the handler for the "Submit" button merely writes the data to the file. However, it does not change the values of the various Swing components back to their default values. I'd like to uncheck the JCheckBoxes, etc. Can anyone tell me how to do so?

The second question is related. I'm going to want a second version of this program for editing student information. In other words, I'd like to select the student from a JComboBox and read the information from a file. Then, I'd like to use a from with JCheckBoxes, JComboBoxes, etc to edit that student's record and write it to a file.

Many thanks for any assistance you can render. I'm trying to do this quickly and am floundering.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> However, it does not change the values of the various Swing components back
> to their default values. I'd like to uncheck the JCheckBoxes, etc.

create a reset() method where you set all your initial values, then call reset()
at the end of the submit button's actionPerformed()


> I'd like to select the student from a JComboBox and read the information from a file.

create a Student class and read in all of the data from the file as Student
objects. Store the students in an ArrayList, or Hashmap if you have id's etc

Include in the Student class a toString() which returns the student's name,
or whatever it is you want displayed in the comboBox, then add the student
objects to the comboBox.

Add a listener to the comboBox, so that when a student is selected, the
various textfields/checkboxes/whatever are filled with that student's data.

The edit button removes the currently selected student from the collection,
calls add() (method for adding a new student), then iterates the student
collection saving the student information to a file (overwriting existing
file - or to a temp file, then delete student file, rename temp etc)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using Swing to Create Data Entry Forms