한 줄의 입력을 받을 때는 TextField 컴포넌트를 사용
여러 줄의 입력을 받을 때는 TextArea 컴포넌트를 사용
Component
|
TextComponent
| |
TextField TextArea
1) 텍스트 필드
생성자
public TextField() { this("", 0); }
public TextField(String text) { this(text, text.length()); }
public TextField(int columns) { this("", columns); }
public TextField(String text, int columns)
2) 텍스트 영역
생성자
public TextArea() { this("", 0, 0, SCROLLBARS_BOTH); }
public TextArea(String text) { this(text, 0, 0, SCROLLBARS_BOTH); }
public TextArea(int rows, int columns) { this("", rows, columns); }
public TextArea(String text, int rows, int columns) { this(text, rows, columns,
SCROLLBARS_BOTH); }
public TextArea(String text, int rows, int columns, int scrollbars)
레이블과 텍스트 필드, 텍스트 영역, 버튼 컴포넌트를 사용
OK버튼을 클릭했을 때 텍스트 영역에 정보를 출력
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LabelTextTest extends Applet {
TextField tf1 = new TextField("name", 25);
TextField tf2 = new TextField(8);
TextArea ta = new TextArea(3, 40);
Button bt1 = new Button("OK");
String s1 = new String();
String s2 = new String();
Public void init() {
add(new Label("Enter your name"));
add(tf1);
add(new Label("Enter your password"));
add(tf2);
bt1.addActionListener(new ButtonListener());
tf2.setEchoChar('*');
add(ta);
add(bt1);
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
ta.setText("name : ");
ta.append(tf1.getText() + "\n");
ta.append("password : " + tf2.getText());
getAppletContext().showStatus(ta.getText());
}
}
}
html문서는 생략 -_ -a
'MySelf' 카테고리의 다른 글
mp3업로드 불가능 ㅅㅂ (0) | 2007.04.16 |
---|---|
시험공부... (0) | 2007.04.16 |
Malice Mizer - ILLUMINATI... (0) | 2007.04.15 |
CP명령어를 만들어 봅시다~ (0) | 2007.04.15 |
텍스트 컴포넌트 (1) | 2007.04.15 |
테터 초기화?! (0) | 2007.04.15 |