Jump to content
ole1990

Verificação invocação metodo

Recommended Posts

ole1990

Boa tarde,

Tenho este código:

public class Picture
{
    private Square wall;
    private Square window;
    private Triangle roof;
    private Circle sun;
    private Circle sun2;

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

    /**
     * Draw this picture.
     */
    public void draw()
    {
        wall = new Square();
        wall.moveVertical(80);
        wall.changeSize(100);
        wall.makeVisible();
        
        
        window = new Square();
        window.changeColor("black");
        window.moveHorizontal(20);
        window.moveVertical(100);
        window.makeVisible();

        roof = new Triangle();  
        roof.changeSize(50, 140);
        roof.moveHorizontal(60);
        roof.moveVertical(70);
        roof.makeVisible();

        sun = new Circle();
        sun.changeColor("yellow");
        sun.moveHorizontal(180);
        sun.moveVertical(-10);
        sun.changeSize(60);
        sun.makeVisible();
        sunset();
        sun.slowMoveVertical(-50);
        
        sun2 = new Circle();
        sun2.changeColor("blue");
        sun2.moveHorizontal(100);
        sun2.moveVertical(-5);
        sun2.changeSize(50);
        sun2.makeVisible();
        sun2.slowMoveVertical(-50);
        
        //sunset = slowMoveVertical;
}
    /**
     * ponto 8 da parte 2
     */
    public void sunset()
    {       
sun.slowMoveVertical(-50);
    }
    /**
     * Change this picture to black/white display
     */
    public void setBlackAndWhite()
    {
        if(wall != null)   // only if it's painted already...
        {
            wall.changeColor("black");
            window.changeColor("white");
            roof.changeColor("black");
            sun.changeColor("blue");
        }
    }

    /**
     * Change this picture to use color display
     */
    public void setColor()
    {
        if(wall != null)   // only if it's painted already...
        {
            wall.changeColor("red");
            window.changeColor("black");
            roof.changeColor("green");
            sun.changeColor("yellow");
        }
    }
    

}

o meu objectivo era fazer com que o objecto "sun" comece a descer quando é invocado o metodo "public void sunset()"

Será que o meu código está a funcionar correctamente, ou alguem me consegui dizer como posso verificar isso com o software "BlueJ"?

Share this post


Link to post
Share on other sites
ole1990

Affinal consegui resolver está aqui a solução ao meu problema caso possa ajudar alguem um dia.

public class Picture
{
    private Square wall;
    private Square window;
    private Triangle roof;
    private Circle sun;
    private Circle sun2;//criação do objecto "sun2"

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

    /**
     * Draw this picture.
     */
    public void draw()
    {
        wall = new Square();
        wall.moveVertical(80);
        wall.changeSize(100);
        wall.makeVisible();
        
        
        window = new Square();
        window.changeColor("black");
        window.moveHorizontal(20);
        window.moveVertical(100);
        window.makeVisible();

        roof = new Triangle();  
        roof.changeSize(50, 140);
        roof.moveHorizontal(60);
        roof.moveVertical(70);
        roof.makeVisible();

        sun = new Circle();
        sun.changeColor("blue");//mudei a cor do sol tal como pedido no ponto 5 da parte 2
        sun.moveHorizontal(180);
        sun.moveVertical(-10);
        sun.changeSize(60);
        sun.makeVisible();
        sunset();//Chama o metodo sunset
        
        /**
     * ponto 6 da parte 2
     */
        sun2 = new Circle();
        sun2.changeColor("yellow");
        sun2.moveHorizontal(140);
        sun2.moveVertical(-20);
        sun2.changeSize(50);
        sun2.makeVisible();
       
        
        ;
}
    /**
     * ponto 8 da parte 2
     */
    public void sunset()
    {       
sun.slowMoveVertical(+300);
    }
    /**
     * Change this picture to black/white display
     */
    public void setBlackAndWhite()
    {
        if(wall != null)   // only if it's painted already...
        {
            wall.changeColor("black");
            window.changeColor("white");
            roof.changeColor("black");
            sun.changeColor("blue");
        }
    }

    /**
     * Change this picture to use color display
     */
    public void setColor()
    {
        if(wall != null)   // only if it's painted already...
        {
            wall.changeColor("red");
            window.changeColor("black");
            roof.changeColor("green");
            sun.changeColor("yellow");
        }
    }
    

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.