AWT>TextField
- addActionListener() : action이벤트가 발생했을때 통지를 받는다.
- setColumus() : 열의 수 설정
- setText() : 텍스트를 설정/수정한다.
- removeActionListener() : action 리스너 제거
- getListener() : 이 객체롸 연관된 모든 리스너를 배열로 반환
* 프레임에 TextField 객체를 위치시킨다.
import java.awt.*;
import java.awt.event.*;
public class TestTextFields extends Frame {
TextField tfield1;
TextField tfield2;
public TestTextFields(){
tfield1 = new TextField(15); //보여질 글자수를 미리 설정하여 생성한다.
tfield2 = new TextField(20);
tfield1.setEchoChar('*'); //모든 글자가 '*'로 찍히게 한다.
tfield2.setText("Some Sample Text"); //기본값을 출력하도록 한다.
tfield2.setFont(new Font("Couroer", Font.BOLD, 16)); //글꼴 지정
tfield2.setEditable(false); //텍스트 수정 불가
tfield2.select(12, 15); //지정된 텍스트를 블록지정한다.
Panel p1 = new Panel(); //패널생성
p1.add(tfield1); //패널 p1에 TextField1 추가
p1.add(tfield2); //패널 p1에 TextField2 추가
add(p1); //TestTextFields tp에 패널 추가
addWindowListener(new WinCloser());
setTitle("Using TextFields");
setBounds(100,100,300,300);
setVisible(true);
}
public static void main(String[] args) {
TestTextFields tp = new TestTextFields();
}
}
class WinCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
*