-
Mouse E
at the moment my applet displays a big black circle but i want the applet to draw a white circle where the mouse is. the mouse will point to the centre of the circle. i want to decide how big my circle will be where i want the top left corner of the mouse to be.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.Rectangle;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.Color;
public class MouseE extends Applet
{
public MouseE()
{
x1 = -1; // initialise (x1,y1) and (x2,y2) to -1
y1 = -1; // the value '-1' is OUTSIDE the applet
x2 = -1; // so, if, in the program, these variables are less than zero
y2 = -1; // we KNOW that they don't currently represent a point on the image
class MousePressListener implements MouseListener
{
// do-nothing methods
public void mousePressed(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
public void mouseClicked(MouseEvent event){}
public void mouseExited(MouseEvent event){}
public void mouseEntered(MouseEvent event)
{
x1 = event.getX();
y1 = event.getY();
repaint();
}
}
MouseListener listener = new MousePressListener();
addMouseListener(listener);
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
Ellipse2D.Double circle = new Ellipse2D.Double(0,0, 300, 300);
g2.draw(circle);
g2.fill(circle);
}
public double x1;
public double y1;
public double x2;
public double y2;
}
-
The circle parameters represent the topLeft and the diameter(s), so if your
mousePosition is going to be at the center then your circle should be drawn, in the
appropriate mouseEvent(mousePressed, mouseMoved) like:
g.drawOval(event.getX()-diameter/2, event.getY()-diameter/2, diameter, diameter);
For an ellipse you must use diameterX & diameterY, this should work if you use the
Graphics2D also.
eschew obfuscation
Similar Threads
-
By Chris Eastwood in forum VB Classic
Replies: 4
Last Post: 03-28-2002, 01:26 PM
-
By Eugene in forum VB Classic
Replies: 4
Last Post: 12-19-2000, 12:52 PM
-
By Eugene in forum VB Classic
Replies: 0
Last Post: 12-19-2000, 11:13 AM
-
By Michael Culley in forum VB Classic
Replies: 2
Last Post: 12-10-2000, 01:56 PM
-
By Paul Harris in forum VB Classic
Replies: 0
Last Post: 03-13-2000, 04:07 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks