สวัสดีครับ ผมจะสร้างการสั่งอาหารขึ้นมาอะครับแต่พอผมติกทุกอย่างแล้วมันไม่คำนวณเงินออกมาไห้ผมควรทำอย่างไรอะครับ
นี้รูปประกอบครับ
http://www.mx7.com/view2/AeCBUXhWmXzCXaAL
นี้ครับcode
import java.awt.EventQueue;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BBQ2 extends JFrame
{
JCheckBox cbox1 = new JCheckBox("Bacon 2$");
JCheckBox cbox2 = new JCheckBox("pork 2$");
JCheckBox cbox3 = new JCheckBox("Beef 2$");
JRadioButton radio101 = new JRadioButton("Size 1 1$");
JRadioButton radio102 = new JRadioButton("Size 2 2$");
JRadioButton radio103 = new JRadioButton("Size 3 3$");
JRadioButton radio201 = new JRadioButton("Coke 2$");
JRadioButton radio202 = new JRadioButton("Tea 2$");
JRadioButton radio203 = new JRadioButton("Water 1$");
JLabel label01 = new JLabel("");
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
BBQ2 frame = new BBQ2();
frame.setVisible(true);
}
});
}
public BBQ2()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 300, 250);
setTitle("BBQ2");
getContentPane().setLayout(null);
// Panel 1
JPanel panel1 = new JPanel();
panel1.setBounds(0, 0, 100, 100);
panel1.setBorder(BorderFactory.createTitledBorder("Topping"));
panel1.setLayout(new GridLayout(0, 1));
panel1.add(cbox1);
panel1.add(cbox2);
panel1.add(cbox3);
getContentPane().add(panel1);
// Panel 2
JPanel panel2 = new JPanel();
panel2.setBounds(100, 0, 100, 100);
panel2.setBorder(BorderFactory.createTitledBorder("Size"));
panel2.setLayout(new GridLayout(0, 1));
ButtonGroup radiogroup1 = new ButtonGroup();
radiogroup1.add(radio101);
radiogroup1.add(radio102);
radiogroup1.add(radio103);
panel2.add(radio101);
panel2.add(radio102);
panel2.add(radio103);
getContentPane().add(panel2);
// Panel 3
JPanel panel3 = new JPanel();
panel3.setBounds(200, 0, 100, 100);
panel3.setBorder(BorderFactory.createTitledBorder("Drink"));
panel3.setLayout(new GridLayout(0, 1));
ButtonGroup radiogroup2 = new ButtonGroup();
radiogroup2.add(radio201);
radiogroup2.add(radio202);
radiogroup2.add(radio203);
panel3.add(radio201);
panel3.add(radio202);
panel3.add(radio203);
getContentPane().add(panel3);
// Panel 4
JPanel panel4 = new JPanel();
panel4.setBounds(0, 100, 300, 50);
panel4.setBorder(BorderFactory.createTitledBorder(""));
panel4.setLayout(new GridLayout(0, 1));
JButton button01 = new JButton("Process Selection");
button01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
String st= "";
if(cbox1.isSelected()){ st=st+"2$"; }
if(cbox2.isSelected()){ st=st+"2$"; }
if(cbox3.isSelected()){ st=st+"2$"; }
label01.setText(st); }
});
panel4.add(button01);
getContentPane().add(panel4);
// Panel 5
JPanel panel5 = new JPanel();
panel5.setBounds(0, 150, 300, 50);
panel5.setBorder(BorderFactory.createTitledBorder(""));
panel5.setLayout(new GridLayout(0, 1));
panel5.add(label01);
getContentPane().add(panel5);
}
}
ใครมีความรู้เรื่องjavaช้วยหน่อยครับ
นี้รูปประกอบครับ http://www.mx7.com/view2/AeCBUXhWmXzCXaAL
นี้ครับcode
import java.awt.EventQueue;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BBQ2 extends JFrame
{
JCheckBox cbox1 = new JCheckBox("Bacon 2$");
JCheckBox cbox2 = new JCheckBox("pork 2$");
JCheckBox cbox3 = new JCheckBox("Beef 2$");
JRadioButton radio101 = new JRadioButton("Size 1 1$");
JRadioButton radio102 = new JRadioButton("Size 2 2$");
JRadioButton radio103 = new JRadioButton("Size 3 3$");
JRadioButton radio201 = new JRadioButton("Coke 2$");
JRadioButton radio202 = new JRadioButton("Tea 2$");
JRadioButton radio203 = new JRadioButton("Water 1$");
JLabel label01 = new JLabel("");
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
BBQ2 frame = new BBQ2();
frame.setVisible(true);
}
});
}
public BBQ2()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 300, 250);
setTitle("BBQ2");
getContentPane().setLayout(null);
// Panel 1
JPanel panel1 = new JPanel();
panel1.setBounds(0, 0, 100, 100);
panel1.setBorder(BorderFactory.createTitledBorder("Topping"));
panel1.setLayout(new GridLayout(0, 1));
panel1.add(cbox1);
panel1.add(cbox2);
panel1.add(cbox3);
getContentPane().add(panel1);
// Panel 2
JPanel panel2 = new JPanel();
panel2.setBounds(100, 0, 100, 100);
panel2.setBorder(BorderFactory.createTitledBorder("Size"));
panel2.setLayout(new GridLayout(0, 1));
ButtonGroup radiogroup1 = new ButtonGroup();
radiogroup1.add(radio101);
radiogroup1.add(radio102);
radiogroup1.add(radio103);
panel2.add(radio101);
panel2.add(radio102);
panel2.add(radio103);
getContentPane().add(panel2);
// Panel 3
JPanel panel3 = new JPanel();
panel3.setBounds(200, 0, 100, 100);
panel3.setBorder(BorderFactory.createTitledBorder("Drink"));
panel3.setLayout(new GridLayout(0, 1));
ButtonGroup radiogroup2 = new ButtonGroup();
radiogroup2.add(radio201);
radiogroup2.add(radio202);
radiogroup2.add(radio203);
panel3.add(radio201);
panel3.add(radio202);
panel3.add(radio203);
getContentPane().add(panel3);
// Panel 4
JPanel panel4 = new JPanel();
panel4.setBounds(0, 100, 300, 50);
panel4.setBorder(BorderFactory.createTitledBorder(""));
panel4.setLayout(new GridLayout(0, 1));
JButton button01 = new JButton("Process Selection");
button01.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
String st= "";
if(cbox1.isSelected()){ st=st+"2$"; }
if(cbox2.isSelected()){ st=st+"2$"; }
if(cbox3.isSelected()){ st=st+"2$"; }
label01.setText(st); }
});
panel4.add(button01);
getContentPane().add(panel4);
// Panel 5
JPanel panel5 = new JPanel();
panel5.setBounds(0, 150, 300, 50);
panel5.setBorder(BorderFactory.createTitledBorder(""));
panel5.setLayout(new GridLayout(0, 1));
panel5.add(label01);
getContentPane().add(panel5);
}
}