AWT>TextArea
- appebd() : 텍스트의 끝에 문자열 추가
- insert() : TextArea의 x 위치에 문자열 추가 후, 나머지 텍스트를 오른쪽으로 이동
- replaceRange() : 시작과 끝 지점을 지정하여 전달된 문자열을 사용해 택스트 대치
*
import java.awt.*;
import java.awt.event.*;
public class TestTextArea extends Frame implements ActionListener {
Button btnExit;
Button btnAppend;
Button btnInsert;
Button btnReplace;
TextArea taLetter;
public TestTextArea() { //버튼 객체 생성
btnAppend = new Button("Append");
btnAppend.addActionListener(this);
btnInsert = new Button("Insert");
btnInsert.addActionListener(this);
btnReplace = new Button("Replace");
btnReplace.addActionListener(this);
btnExit = new Button("Exit");
btnExit.addActionListener(this);
//비어있는 TextArea 객체 생성
taLetter = new TextArea("", 10, 30, TextArea.SCROLLBARS_VERTICAL_ONLY);//TextArea영역에 텍스트 생성
taLetter.append("I am writing this letter to inform you that you");
taLetter.append(" havebeen drafted into the United States Army.");
taLetter.append(" You will report to Fort Bragg, North Carolina ");
taLetter.append("on July 20, 1966. You will be assigned to ");
taLetter.append("Vietnam.");
add(btnAppend);
add(btnInsert);
add(btnReplace);
add(btnExit);
add(taLetter);
this.setLayout(new FlowLayout());
//윈도우창 생성
addWindowListener(new WinCloser());
setTitle("Using a TextArea Object");
setBounds(100,100,400,400);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) { //각 버튼에 이벤트 적용
if(ae.getActionCommand().equals("Append"))
taLetter.append("\n\nSincerely, \n The DraftBoard"); //Sincerely라인추가
if(ae.getActionCommand().equals("Insert"))
taLetter.insert("Dear Steve, \n ",0); //인사말 추가
if(ae.getActionCommand().equals("Replace"))
taLetter.replaceRange("Dear Jerry, \n ", 0,12); //다른인사말로 교체/대치
if(ae.getActionCommand().equals("Exit"))
System.exit(0);
}
public static void main(String[] args) {
TestTextArea tta = new TestTextArea();
}
}class WinCloser extends WindowAdapter {
public void WindowClosing(WindowEvent e) {
System.exit(0);
}
}*