Methods Summary |
---|
public static void | main(java.lang.String[] av)
// "main" method
Frame f = new Frame("Mouse Dragger");
if (av.length < 1) {
System.err.println("Usage: MouseDrag imagefile");
System.exit(1);
}
Image im = Toolkit.getDefaultToolkit().getImage(av[0]);
// create a MouseDrag object
MouseDrag j = new MouseDrag(im);
f.setLayout(new BorderLayout());
f.add(BorderLayout.NORTH,
new Label("Hello, and welcome to the world of Java"));
f.add(BorderLayout.CENTER, j);
f.add(BorderLayout.SOUTH, status = new Label());
f.addWindowListener(new WindowCloser(f));
f.pack();
status.setSize(f.getSize().width, status.getSize().height);
f.setVisible(true);
|
public void | mouseClicked(java.awt.event.MouseEvent e)Called when the mouse has been clicked on a component.
|
public void | mouseDragged(java.awt.event.MouseEvent e)
Point p = e.getPoint();
// System.err.println("mouse drag to " + p);
showStatus("mouse Dragged to " + p);
curX = p.x; curY = p.y;
if (inDrag) {
repaint();
}
|
public void | mouseEntered(java.awt.event.MouseEvent e)Called when the mouse enters a component.
|
public void | mouseExited(java.awt.event.MouseEvent e)Called when the mouse exits a component.
|
public void | mouseMoved(java.awt.event.MouseEvent e)
showStatus("mouse Moved to " + e.getPoint());
|
public void | mousePressed(java.awt.event.MouseEvent e)Called when the mouse has been pressed.
Point p = e.getPoint();
System.err.println("mousePressed at " + p);
startX = p.x; startY = p.y;
inDrag = true;
|
public void | mouseReleased(java.awt.event.MouseEvent e)Called when the mouse has been released.
inDrag = false;
System.err.println("SELECTION IS " + startX + "," +
startY + " to " + curX + "," + curY);
|
public void | paint(java.awt.Graphics g)
int w = curX - startX, h = curY - startY;
Dimension d = getSize();
g.drawImage(curImage, 0, 0, d.width, d.height, this);
if (startX < 0 || startY < 0)
return;
System.err.println("paint:drawRect @[" + startX +"," + startY +
"] size " + w + "x" + h);
g.setColor(Color.red);
g.fillRect(startX, startY, w, h);
|
public void | showStatus(java.lang.String s)
status.setText(s);
|