GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Hey ranchers...a lil help here plz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hey ranchers...a lil help here plz" Watch "Hey ranchers...a lil help here plz" New topic
Author

Hey ranchers...a lil help here plz

omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Hi everyone

I have this code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/* <APPLET code = "Draw.class" HEIGHT = 300 WIDTH = 300></APPLET> */

public class Draw extends Applet
{

int x;
int y;
String draw="";

public void init()
{
MouseAction ma = new MouseAction();
addMouseMotionListener(ma);
}

public void paint(Graphics g)
{
g.drawString(draw,x,y);
}
public class MouseAction extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent me)
{
x = me.getX();
y = me.getY();
draw = "*";
repaint();
}

}
}

I wanted the * to get drawn (printed) wherever the mouse moves. What i get is the * moves wherever the mouse pointer moves....what am i missing here?...would appreciate your help....Many thanks in advance.


Have a sip of Java !!!
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Hello
What you are doing here is: each time the mouse is moved, co-ordinates of mouse-cursor position are retrieved, and a '*' is drawn at that position.

What you need to do is: You need to store all the co-ordinates where the mouse has moved and draw a '*' at all that positions using a loop.
You can use array or some type of Collection to store the co-ordinates


Hakuna Matata!
omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Thanks Pranav.....this is what i have been actually thinking of....regards
 
GeeCON Prague 2014
 
subject: Hey ranchers...a lil help here plz