08
10


TextFieldT.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//TextField 변수형을 사용하여 프레임에 텍스트필드를 만든다
 
import java.awt.*;
import java.awt.event.*;
 
public class TextFieldT{
    //프레임, 텍스트필드 변수 선언
    private Frame f;
    private TextField tf1, tf2;
    
    //호출할 함수 작성
    public TextFieldT(){
        //프레임 생성
        f = new Frame("TestField Test");
        //윈도우 종료
        f.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });
        //텍스트필드 생성
        tf1=new TextField("empty",15);
        tf2=new TextField(15);
        
        //안내문구와 텍스트필드를 배치할 패널 생성
        Panel p1 = new Panel();
        p1.setLayout(new GridLayout(2,1,0,20));
        p1.add(new Label("ID",Label.RIGHT));
        p1.add(new Label("PW",Label.RIGHT));
        
        Panel p2=new Panel();
        p2.setLayout(new GridLayout(2,1,0,20));
        p2.add(tf1);
        p2.add(tf2);
        
        Panel p3=new Panel();
        p3.add(p1);
        p3.add(p2);
        
        //프레임에 p3을 추가
        f.add(p3, "Center");
        
        //텍스트 필드에 현재 입력된 문자열을 화면에 표시한다
        System.out.println(" ID : "+tf1.getText());
        System.out.println(" PW : "+tf2.getText());
        
        //프레임 사이즈 설정 및 화면에 표시
        f.setSize(300150);
        f.setVisible(true);
    }
    
    //main함수
    public static void main(String[] args){
        TextFieldT tft=new TextFieldT();
    }
}
cs


<실행결과>




반응형
COMMENT