• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing information to a class that displays a GUI.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jonathan Haybok
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic