• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hey ranchers...a lil help here plz

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic