hey ,i am new to the site as java bluej , i have drawn a flag using bluej using many objects like circle and rectangle ...
i wanna combine the objects into one to move it together , what should i do ?
the code source:

/**
 * This class represents a simple picture. You can draw the picture using
 * the draw method. But wait, there's more: being an electronic picture, it
 * can be changed. You can set it to black-and-white display and back to
 * colors (only after it's been drawn, of course).
 *
 * This class was written as an early example for teaching Java with BlueJ.
 * 
 * @author  Michael Kölling and David J. Barnes
 * @version 2011.07.31
 */
public class DZFlag
{
    private MyRectangle greenRectangle;
    private MyRectangle whiteRectangle;
    private MyRectangle frame;
    private MyRectangle poteau;
    private Circle redCircle;
    private Circle whiteCircle;    
    private Arc arc;
    private Star star;



    /**
     * Constructor for objects of class Picture
     */
    public DZFlag()
    {
        // nothing to do... instance variables are automatically set to null
    }

    /**
     * Draw this picture.
     */
    public void draw()
    {
        poteau = new MyRectangle();
        poteau.makeVisible();
        poteau.changeSize(10,400);
        poteau.changeColor("blue");
        poteau.moveHorizontal(-280);
        poteau.moveVertical(-100);

        frame = new MyRectangle();
        frame.changeColor("black");
        frame.makeVisible();
        frame.changeSize(200,150);
        frame.moveHorizontal(-270);
        frame.moveVertical(-100);

        greenRectangle = new MyRectangle();
        greenRectangle.changeColor("green");
        greenRectangle.makeVisible();
        greenRectangle.changeSize(95,140);
        greenRectangle.moveHorizontal(-265);
        greenRectangle.moveVertical(-95);

        whiteRectangle = new MyRectangle();
        whiteRectangle.changeColor("white");
        whiteRectangle.makeVisible();
        whiteRectangle.changeSize(95,140);
        whiteRectangle.moveHorizontal(-170);
        whiteRectangle.moveVertical(-95);

        redCircle = new Circle();
        redCircle.makeVisible();
        redCircle.changeColor("red");
        redCircle.changeSize(75);
        redCircle.moveHorizontal(-128);
        redCircle.moveVertical(-35);

        whiteCircle = new Circle();
        whiteCircle.makeVisible();
        whiteCircle.changeColor("white");
        whiteCircle.changeSize(60);
        whiteCircle.moveHorizontal(-110);
        whiteCircle.moveVertical(-27);

        arc = new Arc();
        arc.makeVisible();
        arc.changeColor("green");
        arc.changeSize(50,55,90,180);
        arc.moveHorizontal(-115);
        arc.moveVertical(-24);

        star = new Star();
        star.makeVisible();
        star.changeSize(12);
        star.moveHorizontal(-229);
        star.moveVertical(-107);  
    }
}

Recommended Answers

All 2 Replies

you mean on your UI?

There's zero information in that code about where the flag is being drawn, so it's
hard or impossible to answer your question. Presumably the missing info is in the various shape classes (MyRectangle etc)?

It's also as far from Object Oriented as it's possible to be in Java. Instances of DZFlag are objects in as much as every instance of every class is an object, but all you have really is a method that overwrites all the instance variables each time it called, so it may as well be a static method with local variables and forget any pretense of being an object. It's going to need a major re-write to make it work like a proper object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.