import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DemoMouseMotionListener extends JFrame implements MouseMotionListener
{
TextField tf=new TextField(60);
DemoMouseMotionListener()
{
setTitle("Contoh Reaksi Mouse");
setLocation(200,100);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMouseMotionListener(this);
}
void KomponenVisual()
{
getContentPane().setLayout(null);
getContentPane().add(tf);
tf.setBounds(10,10,250,20);
setVisible(true);
}
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[])
{
DemoMouseMotionListener med=new DemoMouseMotionListener();
med.KomponenVisual();
}}
**OutPut**
No comments:
Write comments