-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckBoxExample2 - Copy.java
51 lines (49 loc) · 1.12 KB
/
CheckBoxExample2 - Copy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javax.swing.*;
import java.awt.event.*;
public class CheckBoxExample2 extends JFrame implements ActionListener{
JLabel l;
JCheckBox cb1,cb2,cb3;
JButton b;
CheckBoxExample2()
{
l = new JLabel("Food Ordering System");
l.setBounds(50,50,300,20);
cb1 = new JCheckBox("Pizza @ 100");
cb1.setBounds(100,100,150,20);
cb2 = new JCheckBox("Burger @ 30");
cb2.setBounds(100,150,150,20);
cb3 = new JCheckBox("Tea @ 10");
cb3.setBounds(100,200,150,20);
b = new JButton("Order");
b.setBounds(100,250,80,30);
b.addActionListener(this);
add(l);
add(cb1);add(cb2);add(cb3);
add(b);
setSize(400,400);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
float amount = 0;
String msg = " ";
if (cb1.isSelected()){
amount+=100;
msg="Pizza: 100\n";
}
if (cb2.isSelected()){
amount+=30;
msg="Burger: 30\n";
}
if (cb3.isSelected()){
amount+=10;
msg="Tea: 10\n";
}
msg+="--------------------------------------\n";
JOptionPane.showMessageDialog(this,msg+"Total :"+amount);
}
public static void main(String[] agrs){
new CheckBoxExample2();
}
}