File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hey ranchers...a lil help here plz" Watch "Hey ranchers...a lil help here plz" New topic

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

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


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
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
I agree. Here's the link:
subject: Hey ranchers...a lil help here plz
It's not a secret anymore!