본문 바로가기
Dev/JAVA

[JAVA] 패널 생성하기

by E.Clone 2016. 8. 8.

생성한 프레임에 패널을 넣어보자.



PanelTest.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
import java.awt.*;
import java.awt.event.*;
 
public class PanelTest{
    
    private Frame frame;
    private Panel panel;
    
    public PanelTest(){
        frame=new Frame("Panel Test");
        panel = new Panel();
        frame.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent we){
                System.exit(0);
            }
        });
        frame.setBackground(Color.white);
        frame.setSize(400,300);
        
        panel.setBackground(Color.blue);
        panel.setSize(200,200);
        
        frame.setLayout(null);
        
        frame.add(panel);
        frame.setVisible(true);
        
    }
    
    public static void main(String[] args){
        PanelTest pt = new PanelTest();
    }
}
cs




<실행화면>



반응형