I have an upcoming assignment Here is the List of things to accomplish which is difficult to understand in the first place.
Here is one way to say it.
have two buttons in the SOUTH frame. One says Get Student Names, which when clicked will read in the Student Names File and display the lines in the textArea; and one that says "Get Student Grades" that when clicked will display the student Id, names, and average grade in the text area. Include the student object from P_Supplemental_9 with an arraylist for the grades.
1 frame with BorderLayout 2 buttons on Panel
1 Panel with GridLayout to put the two buttons on in the SOUTH region
1 FileChooser in a new frame
1 TextArea in the CENTRAL region
1 Label telling what the program does in the NORTH region
here is another
for P_Supplemental_11. When the first button is pressed, it should open up the FileChooser that's explained on page 329 in the book. With this, choose the studentNames.txt file and read it into the JTextArea.
When the second button is pressed, it should have you browse to the studentScores.txt file, import it, do the magic, and display the same output as P_Supplemental_9 in the JTextArea.
Here is my entire code:
So my first question is how do I get The two buttons to display next to eachother in the SOUTH of the frame in the BorderLayout
And second how do attach the JFile chooser to the buttons?
If you've read the tutorial I gave you on how to use JFileChooser (and seems like you did read some of it), then you know how to choose a file, open it and read its content (that code you already have).
The only thing you have to do now is to replace the code that prints lines to the console:
with appropriate method that would append each line to JTextArea in your GUI. Check the API for JTextArea#append(String str) method and that would solve your problem.
Joined: Nov 06, 2012
All right got that done i will have to work on making the out put fit in the frame better but got it to print inside the GUI
Now Im going to need advice on this; When the second button is pressed, it should have you browse to the studentScores.txt file, import it, do the magic, and display the same output as P_Supplemental_9 in the JTextArea.
Instructor also clarified thusly; When the first file is read in, you will want to not just display it but add it to the student arraylist at that time. When the second file is read in, you will run the collect grades method (for each student) and add that to the corresponding student object.
This kind of splits up the code from P_Supplemental_9 but should help you understand the differences between working with the console and the GUI.
Seeing as how I don't know any magic I cant even pull my thumb off properly. Im going to keep reading but If their is any advice you guys could give to keep nudging me in the right direction it would be appreciated.
These are the baby steps I have taken so far Thanks Kemal
From the description you gave, you should extend the code you already have. Since I don't know what are the formats of files you are reading, I will make an assumption.
Suppose the first file (containing data about students) is formatted as:
In this case your Student class should have these three fields. You would read the file just as you did in the code you already have, but in addition you would have to parse each line you read to extract values for each of these fields (see java.util.StringTokenizer). Once you have extracted all three values from the current line you read, you would instantiate a Student class with those values.
Until you provide more details about how files are structured, I can't give you any more hints, but what I wrote above would be some basic idea on how to handle that task.
It sort of adds the two files together and prints out the student names and Average grades which is what the code in P_Supplemental_9 does, I just need to make it so it does the same action by clicking the two buttons in the GUI from the code that i originally posted. So in the end the print out looks like this.
3305 Smith Henry 86.50 avg,
5555 Eddy Olivia 90.33 avg,
8915 Johnson Luke 92.00 avg,
Inside the GUI text box
I hope that makes some sense.
Joined: Nov 06, 2012
How do i change this so it is all a String?
Joined: Nov 06, 2012
Where and how do I use StringBuilder in my code? I know that that is what I need to do and I think it is the last step. here is where i need to use it for the jtxtAfileContents.setText line
and I know it it needs to be set like this
but I just dont know where or how to set the method for it