1 Replies - 1317 Views - Last Post: 11 November 2007 - 03:18 AM Rate Topic: -----

#1 saint1970  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-November 07

canvases and mouse Events

Post icon  Posted 10 November 2007 - 08:17 PM

here my code:
import java.applet.Applet;
import java.awt.*;

public class CanvasDemo1 extends Applet 


BullsEyeCanvas c=new BullsEyeCanvas();

public void init()
class BullsEyeCanvas extends Canvas

int xpos=0, ypos=0, rings=4, radius=30;

public boolean mouseDown(Event e,int x, int y)

return true;
public void paint(Graphics g)
g.drawString("This is a canvas",105,20);
g.drawLine(xpos-20,ypos,xpos+20,ypos);//cross-hair cursor


he mouse is clicked


I don't know how:
- alter code so that cursor is bulls-eye (4 concentric circles on the tip of operating system cursor)
-alter code so that the bulls-eye cursor painted ont screen every time the mouse is clicked...
thank for any help

Is This A Good Question/Topic? 0
  • +

Replies To: canvases and mouse Events

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: canvases and mouse Events

Posted 11 November 2007 - 03:18 AM

If you don't mind that the cursor of the OS is there, simply create a mouselistener, attach it to your canvas, and draw the bullseye at the cursor's position when you receice a mouseClicked event.
To have your bullseye follow oyur mouse, you can use the MouseInfo class to get the cursor's position anytime.
More here
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1