자바 JFC 구성 및 일반 클래스 활용 JFC Component 클래스

자바 JFC 구성 및 일반 클래스 활용 JFC Component 클래스


JFC Component 클래스
JFC의 기본 작업영역을 지정하며 기본베이스이다

ex )

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
import java.awt.*;
import javax.swing.*;

class Round22_Ex01_Sub extends JFrame {// JFrame을 상속받는다
private Container con;
private JButton jl = new JButton("test");
private ImageIcon im, im1;

public Round22_Ex01_Sub() {
super("제목");
this.init();
this.start();
this.setIconImage(im.getImage());
this.setSize(300, 200);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension di = tk.getScreenSize();
Dimension di1 = this.getSize();
int xpos = ((int) di.getWidth() / 2 - (int) di1.getWidth() / 2);
int ypos = ((int) di.getHeight() / 2 - (int) di1.getHeight() / 2);
this.setLocation(xpos, ypos);
this.setVisible(true);
}

public void init() {
im = new ImageIcon("title.gif");
im1 = new ImageIcon("title.gif");
con = this.getContentPane();// 다중 Panel에서의 기본 작업영역 획득
con.setLayout(new BorderLayout());
// 현제의 프레임 레이아웃을 BorderLayout으로 설정
con.add("North", jl);
con.add("Center", new JButton("Test2", im1));
// Center영역에 image를 넣은 버튼 설정
// 폼 구성 영역 (초기화 영역)
}

public void start() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Frame의 x버튼을 눌렀을 때의 Event
// 이벤트나 기타 액션의 영역
}
}

public class Round22_Ex01 {
public static void main(String[] ar) {
Round22_Ex01_Sub es = new Round22_Ex01_Sub();
}
}

  • 이 예제는 AWT 컴포넌트와 비교해 볼때 각 컴포넌트에 이미지를 추가할 수 있다는 것을 보여준다
    컴포넌트에서 이미지를 사용하려는 경우에는 ImageIcon이라는 JFC의 클래스를 이용하여 로컬경로의
    이미지를 포함하는 객체를 생성할수 있고 JFC대부분의 컴포넌트들이 이를 이용하여 이미지를 가질수 있다
    지금은 버튼만으로 설명 했지만 다른 것들도 예외는 아니다
Share