source...1
//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("");
}
}
}

1 Komentar:
231 8
133 1
775 6
39 7
72 3
598 6
448 7
745 7
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda