티스토리 뷰
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 |
import java.awt.*;
import java.awt.event.*;
class HwFrame extends Frame{
static TextField tf1,tf2,tf3; static Label L1,L2;
HwFrame(){
tf1=new TextField("");
L1=new Label("+");
tf2=new TextField("");
L2=new Label("=");
tf3=new TextField("");
}
void addComponent(){
setLayout(new FlowLayout());
add(tf1);add(L1);add(tf2);
add(L2);add(tf3);
}
}
class A extends HwFrame{
public static void main(String args[]){
HwFrame f=new HwFrame();
f.setBounds(200,200,300,300);
f.addComponent();
f.setVisible(true);
tf3.addFocusListener(new B(tf1,tf2,tf3));
}
}
class B implements FocusListener{
TextField tf1,tf2,tf3;
B(TextField tf1,TextField tf2,TextField tf3){
this.tf1=tf1;this.tf2=tf2;this.tf3=tf3;
}
public void focusGained(FocusEvent e){
int a=Integer.parseInt(tf1.getText());
int b=Integer.parseInt(tf2.getText());
String c=(a+b+"");
tf3.setText(c);
}
public void focusLost(FocusEvent e){
tf3.setText("");
}
}
|
cs |
setVisible(true) - Frame 클래스에 있는 창만드는 메서드(맨마지막)
add - Frame 클래스에 있는 버튼만드는 메서드
BorderLayout - java.awt에있는 클래스
setLayout - Frame 클래스에 있는 메서드
LayoutManager - 인터페이스이자 setLayout의 메개변수
(인터페이스가 메개변수--> new 자식()
FlowLayout - java.awt에있는 클래스(순서대로 배열)
setLabel - button에 있는 메서드
getLabel - button에 있는 메서드(반환형 있음)
setBackground-button에 있는 메서드
color - java.awt에 있는 클래스
컴퍼넌트 - Textfield,button
Textfield - java.awt에있는 클래스
getText - Textfield에 있는 메서드(반환형 있음)
Button - java.awt에있는 클래스
0x --> 16진수 10진수 변경
이벤트등록
컴포넌트.addXXXListener (new 이벤트처리자());
이벤트처리자 - class , 인터페이스를 상속, 오버라이딩
addXXXListener - 메서드
XXXListener - 인터페이스 (객체생성불가,오버라이딩)
Label 컴포넌틑
class 클래스이름 extends Frame{
컴포넌트선언
생성자(){
컴포넌트 초기화 및 생성
}
메서드(기능)
ex) void 컴포넌트를붙이다(){}
ex) void 컴포넌트에이벤트를등록하다(){}
}
class 호출클래스{
메인메서드
주소생성
메서드호출
}
'LANGUAGE > JAVA' 카테고리의 다른 글
[JAVA] DB연동 (0) | 2017.11.15 |
---|---|
[JAVA] Exception (1) | 2017.11.15 |
[JAVA] 내부클래스 (0) | 2017.11.15 |
[JAVA] 자바의 진수표현 (0) | 2017.11.15 |
[JAVA] 상수 & 인터페이스 (0) | 2017.11.15 |
댓글