forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowLayoutDemo.java
82 lines (61 loc) · 2 KB
/
FlowLayoutDemo.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package flowlayoutdemo;
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ItemListener
{
Button b1,b2,b3;
TextField t1,t2,t3;
Panel p1;
Panel p2;
Panel cp;
Panel mainp;
Checkbox c,c2;
CardLayout cl;
public MyFrame()
{
super("CardLayout Demo");
CheckboxGroup cg=new CheckboxGroup();
c=new Checkbox("ONE",true,cg);
c2=new Checkbox("TWO",false,cg);
c.addItemListener(this);
c2.addItemListener(this);
b1=new Button("one");
b2=new Button("two");
b3=new Button("three");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
cp=new Panel();
cp.add(c);
cp.add(c2);
p1=new Panel();
p1.add(b1);
p1.add(b2);
p1.add(b3);
p2=new Panel();
p2.add(t1);
p2.add(t2);
p2.add(t3);
mainp=new Panel();
cl=new CardLayout();
mainp.setLayout(cl);
mainp.add("ONE",p1);
mainp.add("TWO",p2);
add(cp,BorderLayout.NORTH);
add(mainp,BorderLayout.CENTER);
}
@Override
public void itemStateChanged(ItemEvent e) {
if(c.getState())
cl.first(mainp);
else
cl.last(mainp);
}
}
public class FlowLayoutDemo {
public static void main(String[] args) {
MyFrame f=new MyFrame();
f.setSize(500,500);
f.setVisible(true);
}
}