02 Juli 2009

//Text.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Text extends Applet{

//Inisialisasi
TextField textField = new TextField();
TextArea textArea = new TextArea();
Button insert = new Button ("Insert");
Button clear = new Button ("Clear");

public void init(){
setLayout (null);

//MEmbuat ukkura textField serta textarea
textField.setBounds(10,10,200,25);
textArea.setBounds(10,50,200,75);

//Memasukkan serta menghapus input
insert.setBounds(10,140,75,25);
clear.setBounds(100,140,75,25);
insert.addActionListener(new ButtonHandler());
clear.addActionListener(new ButtonHandler());

add(textField);
add(textArea);
add(insert);
add(clear);}

//Mendeteksi dan menerapkan perintah
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent ev){
String s=ev.getActionCommand();
if(s.equals("Insert")){
String text =textArea.getText()+textField.getText();
textArea.setText(text);
}
else if(s.equals ("Clear")) textArea.setText("");
}
}
}

Tidak ada komentar:

Posting Komentar