/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; /** * * @author gtee */ public class GetMousePositionTest extends JApplet { @Override public void stop() { super.stop(); //To change body of generated methods, choose Tools | Templates. } @Override public void start() { super.start(); //To change body of generated methods, choose Tools | Templates. } @Override public void init() { super.init(); //To change body of generated methods, choose Tools | Templates. final JPanel mp = new JPanel(new BorderLayout()); final JLabel label = new JLabel("Coords"); JButton b = new JButton("Dummy"); mp.add(b, BorderLayout.NORTH); mp.add(label, BorderLayout.CENTER); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { super.mouseMoved(e); //To change body of generated methods, choose Tools | Templates. label.setText(getMousePosition().toString()); } }); setContentPane(mp); revalidate(); repaint(); } }