Results 1 to 2 of 2
- 03-14-2009, 07:48 AM #1Member
- Join Date
- Feb 2009
- Rep Power
Inserting multiple shapes using mouseListener
I am currently developing a module that allows users to click on a shape (eg. rectangle) option and then draw it on a canvas. The problem is every time i click to draw the second shape, the shape that is already in the canvas disappears and the new one appears. This disables the user from being able to add more than one shape in the canvas. I found out that every time before calling the repaint() method, the position and the size of the existing shapes have to be recorded since method repaint() will redraw the canvas. Is that true and if so any clue how to do it? Thanks.
This depends on how you declare your shapes and how your paint or paintComponent method draws the shapes. If it were my app, I'd declare an ArrayList of <Shape>, and whenever I wanted to add a Shape, I'd add one to the ArrayList. I'd then want my paint or paintComponent (depending if I'm coding in AWT or Swing respectively) to iterate through the list painting each Shape on the list.
- By marlon in forum New To JavaReplies: 3Last Post: 10-05-2012, 09:37 AM
- By mlfatty in forum AWT / SwingReplies: 2Last Post: 03-04-2009, 07:36 AM
- By Torgero in forum New To JavaReplies: 14Last Post: 10-13-2008, 05:25 PM
- By carl in forum Java 2DReplies: 1Last Post: 07-31-2007, 11:40 PM
- By coco in forum AWT / SwingReplies: 1Last Post: 07-31-2007, 08:52 PM