forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayoutDemo.java
92 lines (63 loc) · 1.65 KB
/
LayoutDemo.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
83
84
85
86
87
88
89
90
91
92
package layoutdemo;
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 c1,c2;
CardLayout cl;
public MyFrame()
{
super("CardLayout Demo");
CheckboxGroup cg=new CheckboxGroup();
c1=new Checkbox("One",true,cg);
c2=new Checkbox("Two",false,cg);
c1.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(c1);
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);
}
public void itemStateChanged(ItemEvent ie)
{
if(c1.getState())
cl.first(mainp);
else
cl.last(mainp);
}
}
public class LayoutDemo
{
public static void main(String[] args)
{
MyFrame f=new MyFrame();
f.setSize(500,500);
f.setVisible(true);
}
}