nea_iyut

Sabtu, 20 Juni 2009

Source java...

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

public class MousePaint extends Applet {
int last_x, last_y;

public void init(){

//Definisi dan registrasi objek MouseListener
this.addMouseListener(new MouseAdapter(){
public void Pressed(MouseEvent e){
last_x= e.getX();
last_y= e.getY();
}
});

//Definisi dan registrasi objek MouseMotionListener
this.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e) {
Graphics g = getGraphics();
int x = e.getX(), y = e.getY();
g.setColor(Color.black);
g.drawLine (last_x,last_y,x,y);
last_x = x; last_y=y;
}
});

//tombol untuk menghapus layar
Button b = new Button ("HAPUS!");
//Mendefinisikan dan registrasi tombol
b.addActionListener(new ActionListener(){
public void actionPerformade (ActionEvent e) {

//Membersihkan layar
Graphics g=getGraphics();
g.setColor(getBackground());
g.fillRect(0,0, getSize().width,getSize().height);
}
});
this.add(b);
}
}

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda