Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nothing displaying

    Hello, please could someone help with my problem. the program below is displaying nothing but the menu bar. It should also be displaying some textFields but i dont know why it isnt. I have tried using setVisible on the Panels but that didn't work either. Any help would be much appreciated

    Main Class -

    public class GUI
    {
    public static void main(String[] args)
    {
    JFrame frame = new JFrame();
    LessonsGUI blah = new LessonsGUI(frame);
    frame.setSize(600,600);
    frame.getContentPane().add(blah);
    frame.setVisible(true);
    }
    }

    GUI class -

    public class LessonsGUI extends JPanel implements ActionListener
    {
    private JMenuBar bar = new JMenuBar();

    private JMenu fileMenu = new JMenu("File");
    private JMenu optionsMenu = new JMenu("Options");

    private JMenuItem save = new JMenuItem("Save");
    private JMenuItem load = new JMenuItem("Load");
    private JMenuItem exit = new JMenuItem("Exit");
    private JMenuItem addBooking = new JMenuItem("Add Telephone Booking");
    private JMenuItem displayAll = new JMenuItem("Display all bookings");
    private JMenuItem displayOne = new JMenuItem("Select a booking to display");
    private JMenuItem deleteBooking = new JMenuItem("Delete a booking");

    private JPanel bookingPanelMain = new JPanel();
    private JPanel bookingPanelTop = new JPanel();
    private JPanel bookingPanelMiddle = new JPanel();
    private JPanel bookingPanelBottom = new JPanel();
    private JPanel bookingPanelTopLeft = new JPanel();
    private JPanel bookingPanelTopRight = new JPanel();

    private JButton addBookingButton = new JButton("Add Booking");

    private JTextField nameOfChild = new JTextField(20);
    private JTextField nameOfParent = new JTextField(20);
    private JTextField address1 = new JTextField(30);
    private JTextField address2 = new JTextField(30);
    private JTextField address3 = new JTextField(30);
    private JTextField postCode = new JTextField(8);
    private JTextField telephoneNo = new JTextField(12);
    private JTextField dd = new JTextField(2);
    private JTextField mm = new JTextField(2);
    private JTextField yyyy = new JTextField(4);

    public LessonsGUI(JFrame frame)
    {

    frame.setJMenuBar(bar);

    bar.add(fileMenu);
    bar.add(optionsMenu);

    fileMenu.add(save);
    fileMenu.add(load);
    fileMenu.add(exit);
    optionsMenu.add(addBooking);
    optionsMenu.add(displayAll);
    optionsMenu.add(displayOne);
    optionsMenu.add(deleteBooking);

    addBooking.addActionListener(this);

    frame.getContentPane().add(bookingPanelMain);

    bookingPanelMain.setLayout(new BorderLayout());

    bookingPanelMain.add("North", bookingPanelTop);
    bookingPanelMain.add("Center", bookingPanelMiddle);
    bookingPanelMain.add("South", bookingPanelBottom);

    bookingPanelTop.setLayout(new BorderLayout());

    bookingPanelTop.add("West", bookingPanelTopLeft);
    bookingPanelTop.add("East", bookingPanelTopRight);

    bookingPanelMiddle.setLayout(new FlowLayout());
    bookingPanelBottom.setLayout(new FlowLayout());

    bookingPanelTopLeft.add(nameOfChild);
    bookingPanelTopLeft.add(nameOfParent);
    bookingPanelTopLeft.add(telephoneNo);
    bookingPanelTopRight.add(address1);
    bookingPanelTopRight.add(address2);
    bookingPanelTopRight.add(address3);
    bookingPanelTopRight.add(postCode);

    repaint();



    }
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == addBooking)
    {


    validate();
    }
    }
    }

  • #2
    New Coder
    Join Date
    Nov 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Comment out this line in your main class.

    //frame.getContentPane().add(blah);
    You set this up in your next class. To your content pane you add the most background component. You then add everything else to that.

    Change your style of adding to components as well. Use something like this.

    bookingPanelMain.add(bookingPanelTop, BorderLayout.CENTER);

    The way you were doing it is obsolete. Check the api.


  •  

    Posting Permissions

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