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);
}
}
}

Comments

Sign in to comment.
Hawkee   -  Nov 12, 2010
blackvenomm, this is Java, not Javascript. They're quite different.
 Respond  
blackvenomm666   -  Nov 12, 2010
O_O oo like i said still learning about computer stuffs muh bad
 Respond  
SunnyD   -  Nov 12, 2010
I'm working on setting up a site so you won't have to download stuff to run it, but I use Textpad & JDK to compile and use.

EDIT: Setup a website, link's in the description!
 Respond  
blackvenomm666   -  Nov 12, 2010
i know nothing bout javascript atm soooo umm where the fark would this go?
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.