*
The moose likes Swing / AWT / SWT and the fly likes Using mouse clicks to draw on a JFrame, problem probably with coordinates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using mouse clicks to draw on a JFrame, problem probably with coordinates" Watch "Using mouse clicks to draw on a JFrame, problem probably with coordinates" New topic
Author

Using mouse clicks to draw on a JFrame, problem probably with coordinates

michael perkins
Greenhorn

Joined: Apr 11, 2011
Posts: 5
I'm having problems drawing a rectangle, circle, and a straight line of a JFrame. I'm pretty sure I'm getting my coordinates off and I've spent hours trying to fix it which usually leads me to messing it up even more. If I somewhat fix one part of it, it just ends up messing up another part, so if anyone could help me out and show me what I am messing up it would be very much appreciated. The polygon part can be ignored, I will work on it once I get my coordinates fixed. Sorry if its a little long, I didn't know if I needed to attach all or just the part I'm having problems with so I went with the first. Thanks again.


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Never use getGraphics of a Component, and don't perform custom painting in a top level window but rather in a JPanel or JComponent that is then added to the window.


luck, db
There are no new questions, but there may be new answers.
michael perkins
Greenhorn

Joined: Apr 11, 2011
Posts: 5
Darryl Burke wrote:Never use getGraphics of a Component, and don't perform custom painting in a top level window but rather in a JPanel or JComponent that is then added to the window.


I know I needed a JPanel to do the painting on, but believe it or not that was the way my teacher recommended so I left out the extra work. I wish I had a teacher that knew java, but I've asked her many questions and she hasn't been able to answer any of them. I asked her the question I asked here before I posted it here and she couldn't help me. But thanks for pointing that out, I wish I had a more formal exposure but there's not much I can do about it.
 
Don't get me started about those stupid light bulbs.
 
subject: Using mouse clicks to draw on a JFrame, problem probably with coordinates
 
Similar Threads
drawing arrows
How to make rectangle drawn to be vissible when a new rectangle is drawn
drawRect() issues
clickable line
How to use menu event