Window프로그래밍
Window 프로그래밍 개요
NaZZU
2024. 10. 5. 18:50
AWT
- AWT (Abstract Windows ToolKit)
- 정의 : GUI를 구축하기 위한 클래스들의 모음
- 종류
- 사용자 Interface 클래스
- 그래픽 처리 클래스
- 구조
- Compoent : Window 환경의 Compoenet(Button, CheckBox, ---)
- java.awt 클래스로 객체 모델링
Component | Function |
Lable | 고정 문자열 표시 |
Button | 버튼 |
TextField | 1 line 문자열 입력 |
TextArea | 여러 line 문자열 입력 |
Checkbox | 체크박스, 옵션 버튼을 작성 |
Choice | Drop-down 리스트를 작성 |
Camvas | 그리기 공간 작성 |
List | 리스트 작성 |
Scrollbar | 스크롤바 작성 |
- 메서드
Method | Function |
Public Dimension getSize() | Component 현재의 크기를 Dimensoin 클래스 객체로 변환 |
Public void setForeground(Color c) Public void setBackground(Color c) |
Text 색 결정 Text 외의 색 결정 |
Public void setFont(Font f) | Font 설정 |
Public void setEnabled(boolean b) | false : inactive status |
void setBounds(int x, int y, int width, int hegith) void setSize(Dimension d) |
Component 위치 지정 Component 크기 지정 |
void setVisible(boolean b) | true : 화면에 출력 false : 화면에서 사라짐 |
Swing
- 정의 : 순수한 자바 언어로 지원되는 GUI 개발 도구
- 특성
- Plattform에 독립적이다
- 새로운 Component 제작이 쉽다
- ToolTip Function을 제공
- AWT Component를 제공
- AWT vs Swing
- AWT : plattform에 종속적인 c언어 기반으로 작성
- Swing : 100% Java로 구현되어 Plattform에 독립적
- Swing의 클래스 구조
- java.lang.Object
- java.lang.Component
- java.awt.Container
- javax.swing.JComponent
Event
- 정의 : 윈도우 컴포넌트가 클릭되었을 때 발생하는 메시지
- 구성
- Event Source
- Event를 발생시키는 Button, Mouse, Keyboard, --- 등의 Component
- Event Class
- 특정 Component에 따라 발생하는 Event를 분류한 것
- Event Handler
- Event 처리를 위한 Class
- Event Source
Event Class | 설 명 |
ActionEvent | Component가 활성화 될 때 발생 |
AdjustmentEvent | 스크롤바와 같이 조정 가능한 Component에서 조정이 있을 때 발생 |
ContainerEvent | Container에 Component가 추가/삭제 되는 경우 발생 |
FocusEvent | Component에 focus가 들어왔을 때 발생 |
ItemEvent | List, choice, --- 등의 Component에서 선택 항목이 선택될 때 발생 |
KeyEvent | 키보드 입력에 의해서 발생 |
MouseEvnet | 마우스 움직임에 의해서 발생 |
PaintEvent | Component가 그려져야 할 때 발생 |
TextEvent | Text Component의 내용이 변화할 때 발생 |
WindowEvent | Window 활성화, 또는 종료할 때 발생 |
Event Handler
- Listner Interface
- 각 Event를 처리하기 위해, 준비된 mothod를 선언한 Interface
- Evnet + Listner
- 예제
class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
System.out.println(“Action Event가 발생했습니다.”);
}
}