Results 1 to 2 of 2
  1. #1
    thayalan is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    0

    Question Inserting multiple shapes using mouseListener

    Hi guys,

    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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

Similar Threads

  1. randomly moving shapes
    By marlon in forum New To Java
    Replies: 3
    Last Post: 10-05-2012, 10:37 AM
  2. Getting User Input to Drawing Shapes
    By mlfatty in forum AWT / Swing
    Replies: 2
    Last Post: 03-04-2009, 07:36 AM
  3. Colors and shapes.
    By Torgero in forum New To Java
    Replies: 14
    Last Post: 10-13-2008, 06:25 PM
  4. Help with basic shapes in java
    By carl in forum Java 2D
    Replies: 1
    Last Post: 08-01-2007, 12:40 AM
  5. Help, basic shapes using java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 09:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •