본문 바로가기

카테고리 없음

swing_01

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
package swing;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
 
public class Ex01 extends JFrame {
    
    JPanel contentPane; //4)
    JLabel label = new JLabel("성명"); // 6)
    JTextField txt = new JTextField(); //7)
    JButton button = new JButton(); //8
    
    JPanel p = new JPanel(new FlowLayout());//9
 
        
    public Ex01() {
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 3) 창 꺼짐
        
        contentPane = (JPanel)getContentPane(); // 5)
        
        p.add(label);     //10
        p.add(txt);//11
        p.add(button);//12
        
        setLayout(new BorderLayout()); // 14
        contentPane.add(BorderLayout.NORTH,p);  //13 p > //15 >BorderLayout
        
        ImageIcon image = new ImageIcon("img01.jpg"); // 17
        JLabel imgLabel = new JLabel(image); // 16
        
        contentPane.add(imgLabel); // 18 이미지 붙이기.
        
        setSize(300,400); //1)
        setVisible(true); // 2)
        
        }
 
 
public static void main(String[] args) {
    new Ex01();
    }
}
 
 
cs