Rabu, 14 Maret 2012

Mouse Event pada Listener

     Halo semuanya, kali ini saya akan membagikan lagi salah satu fitur GUI yang ada di JAVA. itu adalah Mouse Event pada Listener. Event-Listener adalah pattern yang sangat penting dan banyak digunakan dalam aplikasi. Semua event dalam Swing menggunakan pattern ini secara extensive. Event Listener adalah class yang mengimplementasikan interface <type>Listener. Di bawah ini adalah salah satu contoh projectnya, langsung aja deh cekidot :
Ini adalah Tampilannya :



Ini adalah Syntax dari contoh project diatas : 
package testjeni2;
import java.awt.*;
import java.awt.event.*;

public class MouseEventsDemo extends Frame implements
MouseListener, MouseMotionListener {
TextField tf;
public MouseEventsDemo(String title){
super(title);
tf = new TextField(60);
addMouseListener(this);
}
public void launchFrame() {
/* Menambah komponen pada frame */
add(tf, BorderLayout.SOUTH);
setSize(300,300);
setVisible(true);
}
public void mouseClicked(MouseEvent me) {
String msg = "Mouse clicked.";
tf.setText(msg);
}
public void mouseEntered(MouseEvent me) {
String msg = "Mouse entered component.";
tf.setText(msg);
}
public void mouseExited(MouseEvent me) {
String msg = "Mouse exited component.";
tf.setText(msg);
}
public void mousePressed(MouseEvent me) {
String msg = "Mouse pressed.";
tf.setText(msg);
}
public void mouseReleased(MouseEvent me) {
String msg = "Mouse released.";
tf.setText(msg);
}
public void mouseDragged(MouseEvent me) {
String msg = "Mouse dragged at " + me.getX() + "," +
me.getY();
tf.setText(msg);
}
public void mouseMoved(MouseEvent me) {
String msg = "Mouse moved at " + me.getX() + "," +
me.getY();
tf.setText(msg);
}
public static void main(String args[]) {
MouseEventsDemo med = new MouseEventsDemo("Mouse Events Demo");
med.launchFrame();
}
}

Sekian dari saya, bila ada kekurangan mohon dimaafkan, Thanks.

1 komentar:

faisljaenicke mengatakan...

Casino City - Mapyro
Find your Casino 충청남도 출장마사지 City, NV location with free parking, a 제천 출장샵 concierge, and Uber 제주 출장마사지 assistance. Las Vegas Hotel, Casino, Hotel, and Tower Suites in Downtown Las 제천 출장샵 Vegas. 창원 출장마사지

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best CD Rates