javax.swing question

Soldato
Joined
22 Oct 2005
Posts
2,884
Location
Moving...
I've been given an assignment where I have to develop a Java applications making use of the javax.swing UI. The basic spec is:
-There must be 4 classes: (The stuff in brackets are what it must do/contain)
Person (Contains info on the person, name/email etc)
Contacts (Array of contacts)
PersonPanel (extends JPanel)
ContactsGUI (extends JFrame and implements appropriate listeners)

Now it's the last 2 parts I dont understand, the GUI basically needs to have one window, a toolbar at the top and bottom with some simple buttons (next contact/add contact etc) with a picture of the contacts and details in the middle. I understand the very basics of java and the swing interface but I cant seem to find a tutorial or something similar that has 2 classes to create this one window. It doesn't make sense to me.

Could someone either explain to me what kind of thing I should have in each of the latter classes, or point me in the direction of a good guide?

Thanks very much.
 
Basically you will have your ContactsGUI containing a member object of a Person panel. The content pane of a JFrame is where your PersonPanel will go. I would use a BorderLayout in this case as well to arrange the different widgets.

For example,

Code:
public class ContactsGUI extends JFrame
{
       private PersonPanel personPane = new PersonPanel();

       public ContactsGUI() 
       { 
            this.add(personPane,BorderLayout.CENTER); 
       }
}
 
Last edited:
Thanks Una, but it says that ContactsGUI and PersonPenal must be 2 classes, I'm new to java and I dont really know very much at all but in all the projects I have done so far when it says use X number classes, I have created X number of different classes in the source package. So in this case I would create a personPanel.class and a ContactsGUI.class.

Is this completely wrong then? Sorry I really am useless :o !

(I hope I am wrong because I currently have the exact code you wrote above :D )
 
There are two classes in the example I showed above. ContactsGUI and PersonPanel all its doing is instantiating person panel from ContactsGUI. I just never showed the code for PersonPanel.

In your ContactsGUI.java you would have the code above.

In PersonPanel.java you would have something like,

Code:
public class PersonPanel extends JPanel
{

}

Its pretty simple really, If you have a JPanel you must add it to a Container Object (JFrame/Frame etc..). This means you must have a reference to it what ever way you do it.
 
Last edited:
Back
Top Bottom