Results 1 to 5 of 5

Thread: JavaHelp

  1. #1
    helloWorld564 is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default JavaHelp

    hi, im trying to create a java program for a assignment, in which i need four windows with buttons along the top that say, main page, client, residential and commercial, when you click one of the buttons it goes to said window, and inside i need to have panels with panels.

    this is my main concern, i cant seem to figure out how to have multiple panels in one window. i need to make it so client, has a client information panel, a search panel and a results panel.

    if anyone could help that would be greatly appreciated.

    this is the basic code i have so far

    package Assignment2;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.*;
    import javax.swing.*;
    import java.awt.*;


    /*
    * Author: John Stuby
    * ID: 000457330
    */
    public class clientWindow
    {
    //attributes
    private JTextField textTF;

    //Constructors
    public JPanel createClientWindow()
    {
    JPanel clientPanel = new JPanel();
    JLabel clientLabel = new JLabel("Client Management Screen",SwingConstants.CENTER);
    clientLabel.setForeground(Color.blue);
    clientLabel.setFont(new Font("Copperplate Gothic Bold",Font.BOLD,38));
    clientPanel.add(clientLabel);


    return clientPanel; //returns the clientPanels
    }

    }

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    first you'll have to create a main panel separatedly and add subpanels to it and then add subpanels to the main panel. then add the main panel to the frame )

    JFrame frame=new JFrame();
    frame.getContentPane().add(mainpanem);
    you got it?

  3. #3
    helloWorld564 is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    ok, thanks, that helps a lot. :)

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Please go to the top of this page and click Thread Tools, and then in the drop-down Menu click Mark This Thread As Solved so no one else comes here thinking there is still a problem.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The tutorials that will likely help you the most is the Sun Swing layout manager tutorial set. If you go through it and study the sample programs, you'll find arranging multiple JPanels to be a breeze. One caveat: most newbies to layouts either use the null layout and try to place components by absolute positioning or use one of the most complex layout managers, the GridBagLayout. I suggest that you not do either that you study the FlowLayout, BorderLayout, GridLayout, and BoxLayout in that order and that you nest JPanels each one using its own layout. Also look at the CardLayout which lets you easily swap JPanels or other JComponents.

    Come on back if this doesn't make sense or if you try to use these but run into a snag.

    Link: Laying Out Components Within A Container

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •