BLOGGER TEMPLATES AND TWITTER BACKGROUNDS �

^_^ PENAMPAKAN ^_^

Jumat, 15 April 2011

Membuat Text.class


1.        
 
ini scriptnya :
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Text extends Applet {
  
    TextField textField=new TextField();
    TextArea textArea=new TextArea();
    Button masukkan=new Button("masukkan");
    Button hapus=new Button("hapus");
    Button keluar=new Button("keluar");
    Label judul=new Label ("Text");
    Label judul2=new Label ("Text Area");
   
        public void init(){
        setLayout(null);
        judul.setBounds(10,10,100,25);
        judul2.setBounds(10,80,100,25);
        textField.setBounds(115,10,250,25);
        textArea.setBounds(115,80,250,150);
       
        masukkan.setBounds(115,240,75,25);
        hapus.setBounds(210,240,75,25);
        keluar.setBounds(300,240,75,25);
        masukkan.addActionListener(new ButtonHandler());
        hapus.addActionListener(new ButtonHandler());
        keluar.addActionListener(new ButtonHandler());
        //pasang komponen pada label
        add(judul);
        add(judul2);
        add(textField);
        add(textArea);
        add(masukkan);
        add(hapus);
        add(keluar);
    }
   
class ButtonHandler implements ActionListener{
  public void actionPerformed(ActionEvent ev)
  {
      String s=ev.getActionCommand();
      //bila tombol masukkan diklik, tambahkan text
      //dari textfield ke dlm textarea
      if(s.equals("masukkan")) {
          String text=textArea.getText()+textField.getText()+'\n';
          textArea.setText(text);
        }
        //bila tombol hapus dklik bersihkan textarea
        else if(s.equals("hapus")) textArea.setText("");
           else if (s.equals("keluar")) textField.setText("");
        }
    }
}

0 komentar: