aspose file tools*
The moose likes Beginning Java and the fly likes Passing information to a class that displays a GUI. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing information to a class that displays a GUI." Watch "Passing information to a class that displays a GUI." New topic
Author

Passing information to a class that displays a GUI.

Jonathan Haybok
Greenhorn

Joined: Mar 12, 2009
Posts: 16
I'm trying to make a program that has methods to manipulate student information in one class (student address, grades etc.), creates several Student objects in the driver class and then uses another class to format a GUI where all the information can be well organized and displayed to the user.

I'm totally stuck as to how to create a class that would create the GUI and let me pass parameters to it.
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
Do you know how to write methods like getString() and stuff like that? Just make a public getString() method in your Student class and then call it from the GUI class when you want to display it.


Studying for SCJP 6
Jonathan Haybok
Greenhorn

Joined: Mar 12, 2009
Posts: 16
Here are my other 2 classes. I've never done a getString() method, how would I use it? The very last comment is where I'm having the bulk of my trouble:



Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
Ok, then do you know how to do it using System.out.println? It looks like you only have to display the info once, which means you don't really have to do a Swing gui and get data from another class more than once. Do you know how to use a JOptionPane? Here's the API from Sun. Here's how you can use it:

and here's Sun's tutorial on it.
Jonathan Haybok
Greenhorn

Joined: Mar 12, 2009
Posts: 16
Eric Daly wrote:Ok, then do you know how to do it using System.out.println? It looks like you only have to display the info once, which means you don't really have to do a Swing gui and get data from another class more than once. Do you know how to use a JOptionPane? Here's the API from Sun. Here's how you can use it:

and here's Sun's tutorial on it.


Thanks for your help. I should have mentioned that the project specifically states that I need to use a GUI layout manager.

I'm just now realizing that my average comes out as 0 in every single case. As you can see I needed to overload two methods to get an average, but for some reason it's wrong?
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
For your averages, it looks you never called any of the average methods in your code, so the default value for average will be zero for each student, until you set an average grade. By the way you set up your average methods to take in either 2 or 3 int values to be averaged, which makes whatever test scores you set earlier pointless. The average method is only working with the values passed in when you call the average method. Maybe you should have just one average method with no parameters, and it can average the test scores that are stored in the Student object. Otherwise your code looks good.
As for Swing, you might want to just make a JFrame and add either JTextFields or JLabels, it really doesn't matter. Check out Sun's Swing Tutorial, especially HelloWorldSwing.java. Maybe just do a bunch of JLabels and add them all to your JFrame.
 
 
subject: Passing information to a class that displays a GUI.