Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selection rectangle on image

 
Prathyusha Tummepalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiii... I have a similar problem like this...

I created a frame which will have a label to show an image and i am able to display the image. User needs to select some part of the image as rectangle,Here i am able to draw rectangle but it is disappearing when i stop the mouse dragging only.. Here is my code.. Could you please help me what is my mistake and what i need to add?
As I am new to graphics, can you please give me the code clearly which is need to be added or modified...

Thanks In advance

 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it was a similar problem, either or both of the solutions offered in the thread this was removed from should have sufficed.

When posting code, please UseCodeTags <- link

Here i am able to draw rectangle but it is disappearing when i stop the mouse dragging only.
Well, that's what the code is written to do. Di you write that code or copy it from somewhere without understanding it?

As I am new to graphics, can you please give me the code clearly which is need to be added or modified.

No, this is a forum, NotACodeMill <- link

What we will do is help you to understand what the code does, and make the changes yourself. Start by adding the code tags, and trying to understand what the code does. Refer to the API for java.awt.Rectangle to see what result is specified when you call the method you used, and the documentation for MouseListener to correctly understand when each method is called.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additionally, unless and until you reach a level of understanding the painting mechanism in Swing and AWT far above that of the average coder, do not use getGraphics() of a Component.
 
Prathyusha Tummepalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry.. i do not know how to use these code tags..

As you have mentioned in the earlier thread, i was saving the reference of the rectangle.. still I am getting the problem. so I didnt get where i am doing the mistake..
I actually asked you to tell me where is the problem so that i can change it.
I wil once again go through the Rectangle API,

Thanks for your suggesion..
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think line 40 in your posted code does, and when?
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I urge you to learn and follow the coding conventions, particularly in respect of consistent indents and vertical whitespace (blank lines).
 
Prathyusha Tummepalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I had the example it is displaying all the rectangles drawn. But i need only one rectangle and if I redraw another rectangle the first one must disapper so i thought it is saving the points of all the rectangle and i modified it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic