File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hey ranchers...a lil help here plz

 
omar salem
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pranav Pal
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
omar salem
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pranav.....this is what i have been actually thinking of....regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic