This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes drawing in graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "drawing in graphics" Watch "drawing in graphics" New topic

drawing in graphics

Shae Oommen

Joined: Apr 12, 2006
Posts: 13
I am trying to draw a number of circles and a line. The circles are drawn by clicking the mouse button whereever it needs to be placed. Once the circles are drawn, I can right click the mouse to disable circle drawing and enable line drawing. But the circles disappear. When i draw the circles, it comes without any problem. Same with line. But both dont appear on the screen together.

public void this_mouseClicked(MouseEvent e) {//opened
if(vector_drawing_enabled) {//line drawing
if(e.getButton() == MouseEvent.BUTTON1) {
if(!drawing_active) {
drawing_active = true;
else {
vector_list.add(new Point2d(last_point));
else if(e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) {
drawing_active = false;
}//vector drawing closed
if(obstacle_drawing_enabled)//circle drawing
if(e.getButton() == MouseEvent.BUTTON1) {
obstacle_points.add(new Point2d(last_point));
}//closed if
if(e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) {
obstacle_drawing_enabled =false;
vector_drawing_enabled = true;

}//else if closed

}//obstacle drawing closed

}//mouseclicked closed

Please help
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Well, I would imagine the problem is in your paint()/paintComponent() method, not here. The paint method is probably just not drawing circles when you're in line-entering mode.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: drawing in graphics
jQuery in Action, 3rd edition