import java.awt.*; import javax.swing.*; import java.awt.event.*; public class TestMouse { private JFrame f; private TextField tf; private String title = "TestMouse"; public TestMouse() { f = new JFrame(title); tf = new TextField(30); } public void launchFrame() { Label label = new Label("Click and drag the mouse"); f.getContentPane().add(label, BorderLayout.NORTH); f.getContentPane().add(tf, BorderLayout.SOUTH); f.addMouseMotionListener(new MouseHandler()); f.addMouseListener(new MouseHandler()); f.pack(); f.setSize(400, 200); f.setVisible(true); } public static void main(String args[]) { TestMouse guiApp = new TestMouse(); guiApp.launchFrame(); } }