Join 136,796 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,323 people online right now. Registration is fast and FREE... Join Now!
ahhmm...sort of....im just a newbie in java...and i forgot the exact name of the layout
im still working on my code..i find it difficult using flowlayout so i am wondering how to use the other one...
You will have problem to JPanel.setLayout(layoutName); if you don't know it's name...
If you use a null layout you will have to set the bounds (x, y, width, height) of every component you put into it
For pizza order I would use a gGridLayout(10, 2); 10 lines 2 columns In the left column JLabels defining what is on the second column:
CODE
Pizza Size: Large Medium Small (RadioButton) Cheeze: CheckBox Peepperoni CheckBox .... Sub-Total: Price in JLabel Tax: Price in JLabel Total: Price in JLabel
public void bebang(){ setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("pizzaform"); setLayout(new BorderLayout()); // one line for each topping + 1 for quantity + 1 for total panel = new JPanel(new GridLayout(toppingList.length + 1 + 1, 2));
toppings = new JCheckBox[toppingList.length]; // adding the topping for(int i = 0; i < toppingList.length; i++) { panel.add(new JLabel(toppingList[i])); toppings[i] = new JCheckBox(); panel.add(toppings[i]); } quantity=new JComboBox(qty); panel.add(new JLabel("Quantity")); panel.add(quantity); add(panel, BorderLayout.CENTER);
JButton order = new JButton("Order"); order.addActionListener(this);
add(order, BorderLayout.SOUTH);
setVisible(true); setSize(200, 200); }
public void actionPerformed(ActionEvent arg0) { System.out.println("Order button has been pressed"); for(int i = 0; i < toppings.length; i++) System.out.println(toppingList[i] + " is " + toppings[i].isSelected()); System.out.println("Quantity is " + (quantity.getSelectedIndex() + 1)); }
i have another question...my teacher told us to use group button for the size choices...i dunno how to declare that in java...the sizes were small, medium,large and family size...
i have another question...my teacher told us to use group button for the size choices...i dunno how to declare that in java...the sizes were small, medium,large and family size...
im about to finnish this.... tnx in advance....
You will also have to put your RadioButton in their own panel so the N JRadio will be together
CODE
String[] sizeName = {"Small", "Medium", "Large"); JPanel radioPanel; JRadioButton[] radio; .... ButtonGroup group = new ButtonGroup(); radio = new JRadioButton[sizeName.length]; radioPanel = new JPanel(new GridLayout(1, radio.length)); for(int i = 0; i < radio.length; i++) { radio[i] = new JRadioButton(sizeName[i]); group.add(radio[i]); radioPanel.add(radio[i]); }
// add another row to my main panel containing // the label "size" on the left // the 3 radio on the right panel.add(new JLabel("Size:")); panel.add(radioPanel);
public JPanel panel1,panel2,panel3,panel4,panel5,panel6,panel7,panel8,panel9,panel10,panel11,p anel12,panel13;;
public JComboBox thecombo; public JRadioButton size,yes,no; public ButtonGroup pizzasize,crust,dscnt; public JRadioButton small,medium,large,famsize; public JRadioButton h,t,d; public JCheckBox sausage,pepperoni,cheese,ham,olive,mushroom,pineapple; public JLabel label1,label2,label3,toppings,c,discount1,discount2,discount3,totAMNT,tenamt,cha nge; public JTextArea lapad; public JButton reset,add; public JTextField dcount,tot,ten,cha; public JScrollPane iskrol; public JLabel webeei,out; public int mambo; public int num=0,number=0; public String istilo="",s=""; public double subtotal=0.0; public double price=0.0; public double total=0.0; public double D=0.0; public int bebang[]=new int[100];
public static void main(String[]args) { pizzafrenzy frenzy = new pizzafrenzy(); frenzy.bear();
}
public double tsekbaksA=0,disc=0.0,says=0.0; double tsekbaks=0.0;double tseksbaksB=0.0;double tseksbaksC=0.0;double tseksbaksD=0.0;double tseksbaksE=0.0;double tseksbaksF=0.0;double tseksbaksG=0.0; public void bear() { setTitle("Pizza Order Form"); setSize(340,600); setResizable(false); setLocationRelativeTo(null); setLayout(new GridLayout(0,1));
panel1 = new JPanel(new FlowLayout()); panel4 = new JPanel(new FlowLayout());
panel5 = new JPanel(new GridLayout(4,2)); panel6 = new JPanel(new BorderLayout()); panel2 = new JPanel(new BorderLayout());
RadioHandler rhandler=new RadioHandler(); label2 = new JLabel(" Size"); pizzasize = new ButtonGroup();
small = new JRadioButton("Small"); small.addActionListener(rhandler); medium= new JRadioButton("Medium"); medium.addActionListener(rhandler); large = new JRadioButton("Large"); large.addActionListener(rhandler); famsize = new JRadioButton("Family Size"); famsize.addActionListener(rhandler);
CheckboxHandler chandler=new CheckboxHandler(); toppings = new JLabel(" Toppings ");
sausage = new JCheckBox("Sausage "); sausage.addItemListener(chandler); pepperoni = new JCheckBox("Pepperoni"); pepperoni.addItemListener(chandler); cheese = new JCheckBox("Cheese"); cheese.addItemListener(chandler); ham = new JCheckBox("Ham"); ham.addItemListener(chandler); olive = new JCheckBox("Olive"); olive.addItemListener(chandler); mushroom = new JCheckBox("Mushroom"); mushroom.addItemListener(chandler); pineapple = new JCheckBox("Pineapple"); pineapple.addItemListener(chandler);
c=new JLabel("Crust"); h = new JRadioButton("Hand-tossed"); h.addActionListener(rhandler); t = new JRadioButton("Thin-crust"); t.addActionListener(rhandler); d = new JRadioButton("Deep Dished"); d.addActionListener(rhandler);