I'm back guys! This time I'm working on this project for class. I have to make a "point of sale" thingy. I worked on it using GuiGenie. My design has four buttons, and I want to design it in such a way that when I click one of the four buttons, it opens up into another form with buttons. For example, the first form has four buttons: From the Grill, Breaded Fried Cutlets, Sweet and Sour Chopsuey. So if I click "From the Grill" it shows another form.
Here's my code for the Main Menu form:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MyPanel extends JPanel {
private JLabel jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JButton jcomp4;
private JButton jcomp5;
private JButton jcomp6;
public MyPanel() {
//construct components
jcomp1 = new JLabel ("Welcome To Shirley's Coffee Shop");
jcomp2 = new JButton ("From the Grill");
jcomp3 = new JButton ("Breaded Fried Cutlets");
jcomp4 = new JButton ("Sweet and Sour");
jcomp5 = new JButton ("Chopsuey");
jcomp6 = new JButton ("Cashew Nut Specialties");
//adjust size and set layout
setPreferredSize (new Dimension (683, 428));
setLayout (null);
//add components
add (jcomp1);
add (jcomp2);
add (jcomp3);
add (jcomp4);
add (jcomp5);
add (jcomp6);
//set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds (200, 20, 495, 30);
jcomp2.setBounds (10, 95, 295, 50);
jcomp3.setBounds (315, 95, 295, 50);
jcomp4.setBounds (10, 170, 295, 50);
jcomp5.setBounds (315, 170, 295, 50);
jcomp6.setBounds (155, 245, 295, 50);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new MyPanel());
frame.pack();
frame.setVisible (true);
}
}
So if I click "From the Grill" I want it to open up this form:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MyPanel extends JPanel {
private JLabel jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JButton jcomp4;
private JButton jcomp5;
private JButton jcomp6;
public MyPanel() {
//construct components
jcomp1 = new JLabel ("From the Grill");
jcomp2 = new JButton ("Grilled Boneless Chicken Breast ");
jcomp3 = new JButton ("Grilled Butter Mahi Mahi Fish Fillet ");
jcomp4 = new JButton ("Grilled Alaska Salmon Fish Fillet ");
jcomp5 = new JButton ("Grilled Pork Chop ");
jcomp6 = new JButton ("Grilled Beef Short Ribs");
//set components properties
jcomp2.setToolTipText ("$10.25");
jcomp3.setToolTipText ("$10.95");
jcomp4.setToolTipText ("$10.95");
jcomp5.setToolTipText ("$11.25");
jcomp6.setToolTipText ("$11.25 ");
//adjust size and set layout
setPreferredSize (new Dimension (625, 403));
setLayout (null);
//add components
add (jcomp1);
add (jcomp2);
add (jcomp3);
add (jcomp4);
add (jcomp5);
add (jcomp6);
//set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds (265, 15, 495, 30);
jcomp2.setBounds (10, 95, 295, 50);
jcomp3.setBounds (315, 95, 295, 50);
jcomp4.setBounds (10, 170, 295, 50);
jcomp5.setBounds (315, 170, 295, 50);
jcomp6.setBounds (155, 245, 295, 50);
}
public static void main (String[] args) {
JFrame frame = new JFrame ("MyPanel");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new MyPanel());
frame.pack();
frame.setVisible (true);
}
}
Thanks guys! :)