home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.2 KB | 53 lines |
- import javax.swing.*;
- import java.awt.event.*;
-
- import java.awt.*;
-
- public class MouseLocation extends JPanel
- {
- public MouseLocation()
- {
- setToolTipText("xxx");
- setBackground(Color.white);
- }//constructor
-
- public String getToolTipText(MouseEvent event)
- {
-
- int x = event.getX();
- int y = event.getY();
- String str = "(" + x + "," + y + ")";
-
- return str;
- }//getToolTipText
-
-
- public static void main(String s[])
- {
- JFrame f = new JFrame("MouseLocation Example");
- MouseLocation panel = new MouseLocation();
-
- f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- f.setForeground(Color.black);
- f.setBackground(Color.lightGray);
- f.getContentPane().add(panel,"Center");
- f.setSize(300,300);
- f.setVisible(true);
- f.addWindowListener(new WindowCloser());
- }//main
-
- }//class MouseLocation
-
- class WindowCloser extends WindowAdapter
- {
- public void windowClosing(WindowEvent e)
- {
- Window win = e.getWindow();
- win.setVisible(false);
- win.dispose();
- System.exit(0);
- }//windowClosing
- }//class WindowCloser
-
-
-