08
10


CardLayoutT.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
//CardLayout 을 사용하여 컴포넌트를 여러장으로 쌓는다... 인데, 필자는 왠지 작동이 되지 않는다.
 
import java.awt.*;
import java.awt.event.*;
 
public class CardLayoutT{
    //변수 생성
    private Frame f;
    private Button b1,b2,b3,b4;
    private CardLayout card;
    
    //호출할 함수 작성
    public CardLayoutT(){
        
        //프레임 생성
        f=new Frame("CardLayout Test");
        
        //카드 레이아웃 선언
        card = new CardLayout();
        
        //프레임의 레이아웃 세팅을 카드레이아웃으로 지정한다
        f.setLayout(card);
        
        //버튼생성
        b1=new Button("btn1");
        b2=new Button("btn2");
        b3=new Button("btn3");
        b4=new Button("btn4");
        
        //윈도우 종료
        f.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });
        //각각의 패널에 버튼을 하나씩 넣고, 버튼이 표시될 위치를 지정
        Panel panel1=new Panel();
        panel1.add(b1);
 
        Panel panel2=new Panel();
        panel2.setLayout(new BorderLayout());
        panel2.add(b2, "West");
        
        Panel panel3=new Panel();
        panel3.setLayout(new BorderLayout());
        panel3.add(b3, "East");
        
        Panel panel4=new Panel();
        panel4.setLayout(new BorderLayout());
        panel4.add(b4, "South");
        
        //프레임에 패널을 추가한다
        f.add(panel1, "First");
        f.add(panel2, "Second");
        f.add(panel3, "Third");
        f.add(panel4, "Fourth");
        
        //첫 번쨰 패널을 띄운다
        card.show(f, "First");
        
        //프레임 사이즈 및 표시
        f.setSize(300200);
        f.setVisible(true);
        
        //두 번째 패널부터 띄우는 데에 시간 격차를 둔다
        for(int i=0;i<999999999;i++){}
        card.show(f, "Second");
        for(int i=0;i<999999999;i++){}
        card.show(f, "Third");
        for(int i=0;i<999999999;i++){}
        card.show(f, "Fourth");
    }
    
    public static void main(String[] args){
        CardLayoutT ct=new CardLayoutT();
    }
}
cs



<실행결과>

-fail-

반응형
COMMENT