Ok.. bare with me, not sure how to word this.
I am writing a program that stores airplane data. My problem right now is trying to figure out how to get the navigation to work.
My program loads my "menu page". All I want to do is figure out how to load different content in the same container when I click a button.
For instance, right now I am working on just getting displaySeating( ) to work. I have a button on my "menu page" that I want to clear all the menu buttons and show a "new page" that has seating information.
I've tried to use removeAll() to remove all the components, but I haven't gotten it to work.
Here is my code so far... it isn't close to finished, but here it is so far.
I am writing a program that stores airplane data. My problem right now is trying to figure out how to get the navigation to work.
My program loads my "menu page". All I want to do is figure out how to load different content in the same container when I click a button.
For instance, right now I am working on just getting displaySeating( ) to work. I have a button on my "menu page" that I want to clear all the menu buttons and show a "new page" that has seating information.
I've tried to use removeAll() to remove all the components, but I haven't gotten it to work.
Here is my code so far... it isn't close to finished, but here it is so far.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Airplane extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
private JLabel menu, selOption, seatingMenu;
private JRadioButton newPlane, displaySeating, assignSeat, cancelSeat, removeSeats, exit;
private JButton submit, back;
private ButtonGroup menuOptions;
private SubmitButtonHandler subHandler;
private boolean npTF, dsTF, asTF, csTF, rsTF, eTF;
private JTextArea seatingMenuTA;
public Airplane(){
Container c = getContentPane();
c.setLayout(null);
setTitle("");
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void mainMenu(){
Container c = getContentPane();
c.setLayout(null);
//JLabels
menu = new JLabel("Main menu");
selOption = new JLabel("Select an option");
//JRadioButtons
newPlane = new JRadioButton("Get new Plane");
displaySeating = new JRadioButton("Display seating");
assignSeat = new JRadioButton("Assign a seat");
cancelSeat = new JRadioButton("Cancel a seat");
removeSeats = new JRadioButton("Remove all seating");
exit = new JRadioButton("Exit program");
//JButtons
submit = new JButton("Submit");
subHandler = new SubmitButtonHandler();
submit.addActionListener(subHandler);
//set size
newPlane.setSize(150, 30);
displaySeating.setSize(150, 30);
assignSeat.setSize(150, 30);
cancelSeat.setSize(150, 30);
removeSeats.setSize(150, 30);
exit.setSize(150, 30);
menu.setSize(150, 30);
selOption.setSize(150,30);
submit.setSize(150, 30);
//set location
newPlane.setLocation(100, 30);
displaySeating.setLocation(100, 60);
assignSeat.setLocation(100, 90);
cancelSeat.setLocation(100, 120);
removeSeats.setLocation(100, 150);
exit.setLocation(100, 180);
menu.setLocation(0, 0);
selOption.setLocation(0,30);
submit.setLocation(100, 210);
//add graphic objects
c.add(newPlane);
c.add(displaySeating);
c.add(assignSeat);
c.add(cancelSeat);
c.add(removeSeats);
c.add(exit);
c.add(menu);
c.add(selOption);
c.add(submit);
//button group
menuOptions = new ButtonGroup();
menuOptions.add(newPlane);
menuOptions.add(displaySeating);
menuOptions.add(assignSeat);
menuOptions.add(cancelSeat);
menuOptions.add(removeSeats);
menuOptions.add(exit);
setTitle("Main Menu");
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void displaySeatingMenu(){
Container c = getContentPane();
c.setLayout(null);
seatingMenu = new JLabel("Seating Chart");
seatingMenu.setSize(150, 30);
seatingMenu.setLocation(150, 0);
c.add(seatingMenu);
back = new JButton("Back to Menu");
back.setSize(150, 30);
back.setLocation(120, 210);
c.add(back);
seatingMenuTA = new JTextArea(40, 10);
seatingMenuTA.setSize(150,150);
seatingMenuTA.setLocation(100, 30);
//seatingMenuTA.append("\n\n\n\n\n\n\n\n\n\n");
c.add(seatingMenuTA);
setTitle("Seating Chart");
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}//end displaySeating
private class SubmitButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
if(npTF == true){
}
if(asTF == true){
}
if(dsTF == true){
}
if(csTF == true){
}
if(rsTF == true){
}
if(eTF == true){
}
else{
}
}//end actionPerformed
}//end SubmitButtonHandler
public void itemStateChanged(ItemEvent e){
if(e.getSource() == newPlane){
npTF = true; dsTF = false; asTF = false; csTF = false; rsTF = false; eTF = false;
}
if(e.getSource() == displaySeating){
npTF = false; dsTF = true; asTF = false; csTF = false; rsTF = false; eTF = false;
}
if(e.getSource() == assignSeat){
npTF = false; dsTF = false; asTF = true; csTF = false; rsTF = false; eTF = false;
}
if(e.getSource() == cancelSeat){
npTF = false; dsTF = false; asTF = false; csTF = true; rsTF = false; eTF = false;
}
if(e.getSource() == removeSeats){
npTF = false; dsTF = false; asTF = false; csTF = false; rsTF = true; eTF = false;
}
if(e.getSource() == exit){
npTF = false; dsTF = false; asTF = false; csTF = false; rsTF = false; eTF = true;
}
}//end itemStateChanged
public static void main(String[] args){
char[][] seating = new char[7][8];
Airplane plane = new Airplane();
plane.mainMenu();
}//end main
}//end Airplane
Comment