Results 1 to 3 of 3
  1. #1
    jj007 is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default Draw multiple class objects in one frame

    Hi for one of my college assignments I have to draw shapes in different classes using graphics 2d. They all display on screen using a main class that has the JFrame. However I have to create a class that adds each shape into an arraylist and draw on the same frame. My code draws each shape on a seperate frame. Can anybody help?

    Java Code:
    package work;
    import java.util.ArrayList;
    // Gui is the class that holds the code to draw a frame on screen.
    public class ArrayListShapes extends Gui {
    	public static void main(String[] args){
    //DrawShapes is an interface class that is implemented by the shape class which holds all the variables for the actual shape classes to inherit from.
    		ArrayList<drawShapes> drawableList = new ArrayList<DrawShapes>();
    // Draws two shapes by calling the class object
    		Circle circle = new Circle();
    		Rect rect = new Rect();

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power

    Default Re: Draw multiple class objects in one frame

    I don't see any drawing code.

    Start with the Swing tutorial on Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) for the basics of custom painting. Your code will need to access the ArrayList to paint each shape.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Draw multiple class objects in one frame

    What package(s) are you importing for your program?
    You have coded several classes that are not part of the Java SE classes.

Similar Threads

  1. How To Draw Objects Not On A JPanel
    By anthropamorphic in forum New To Java
    Replies: 18
    Last Post: 08-11-2011, 05:55 AM
  2. Multiple objects in a class help please
    By patcc2 in forum New To Java
    Replies: 12
    Last Post: 01-11-2011, 02:35 PM
  3. Draw rectangle in a frame
    By Mothrat in forum Java 2D
    Replies: 0
    Last Post: 12-13-2010, 10:52 AM
  4. Trying to Draw Multiple Components
    By habester in forum New To Java
    Replies: 1
    Last Post: 11-09-2009, 11:06 PM
  5. draw on desktop without Frame
    By AliveMyth in forum Java 2D
    Replies: 2
    Last Post: 02-10-2009, 06:35 AM

Posting Permissions

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