Mouse Applet
Platform: Java
Published Nov 12, 2010
Updated May 15, 2012
Basically demonstrates mouse events within an applet, continuously draws cross hairs to pinpoint the mouse's coordinates. Clicking and dragging creates a new set of coordinates on which cross hairs are drawn.
Constructive criticism and suggestions welcome as always.
Updates:
-Removed useless code
Picture was huge so here is the link lol:
http://img404.imageshack.us/img404/4084/appletw.png
Edit: You can test/play with the Mouse Applet at
http://www.SunnyD.site90.com/Mouse.php -- Website is down until I can either 1.) get my shoot together and make a page for it, or 2.) get my shoot together and get a website up.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class App extends Applet implements MouseMotionListener {
int h, w, mx, my, mySave, mxSave;
boolean isDrag;
public void init() {
setSize(800,600);
setBackground(Color.black);
h = getSize().height;
w = getSize().width;
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e) {
isDrag = true;
mxSave = e.getX();
mySave = e.getY();
repaint();
e.consume();
}
public void mouseMoved(MouseEvent e) {
mx = e.getX();
my = e.getY();
repaint();
showStatus("Red:(" + e.getX() + "," + e.getY() + ") Blue:(" + mxSave + "," + mySave + ")");
e.consume();
}
public void paint(Graphics p) {
p.setColor(Color.red);
p.drawLine(mx,my,mx,0);
p.drawLine(mx,my,0,my);
p.drawLine(mx,my,mx,h);
p.drawLine(mx,my,w,my);
p.drawRect(mx-20,my-20,40,40);
if (isDrag = true) {
p.setColor(Color.blue);
p.drawLine(mxSave,mySave,mxSave,0);
p.drawLine(mxSave,mySave,0,mySave);
p.drawLine(mxSave,mySave,mxSave,h);
p.drawLine(mxSave,mySave,w,mySave);
p.drawRect(mxSave-20,mySave-20,40,40);
}
}
}