JAVA awt Event Handling:Mouse Event Example 2 MouseAdapter
MouseAdapter
******************************************************************
import java.awt.event.*;
import java.awt.*;
class MyFrame extends Frame
{
Label xText = new Label();
Label yText = new Label();
MyFrame()
{
this.setVisible(true);
this.setTitle("Key Event Example");
this.setBackground(Color.yellow);
this.setSize(500,500);
this.setLayout(new FlowLayout());
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
this.add(yText);
this.add(xText);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
xText.setText("x="+me.getX());
yText.setText("y="+me.getY());
}
});
this.setSize(500,500);
}
}
class MouseEventEx2
{
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}
No comments:
Post a Comment