Ace High
12-14-2004, 02:32 PM
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();
}
}
}
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();
}
}
}