aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swing graphics problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing graphics problems" Watch "Swing graphics problems" New topic
Author

Swing graphics problems

luke smith
Greenhorn

Joined: Nov 15, 2008
Posts: 2
Hi guys,

I'm new to Java programming (and GUIs) and I can't figure out why my program is doing this. This is a very simple program that Starts out with a square rectangle at the top left of the screen, and when the user clicks on the screen it should redraw a new rectangle at the point where the screen is clicked. My program doesn't redraw, though. I inserted "System.out.println(x)" in the mouseClicked interface, which works correctly, so I know that the program is getting my mouseclicks, but it is not repainting correctly? Help please? Here's the code:




NewBoxDrawer class:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
basically, your NewBoxDrawer class never changes the x,y positions so
it simply repaints the same thing over and over.

your code modified - few comments added
luke smith
Greenhorn

Joined: Nov 15, 2008
Posts: 2
Thanks Michael. So, if I'm understanding correctly, when the mouseclicker gets the new x and y coordinates, they belong to the newbox class and not the newboxdrawer (source). So I need to explicitly pass them to the source class by calling setX and setY. Why wouldn't it be sufficient to write:



rather than creating a function to pass the variables and then setting them in the other class? If the variables are stored in the "source" class, can they only be modified within that class? It seems like writing new methods for each variable to be changed might get tedious in a program more complex than this simple example.

Thanks again,
Luke
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Why wouldn't it be sufficient to write:
> source.x = evt.getX();
> source.y = evt.getY();

the very best answer I can give you now is to try it, and see what happens.
you'll get more out of seeing the message generated (based on your original code).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Swing graphics problems