BlueJ Review


Premium Content - Free Preview

In the next few nodes, we'll review using BlueJ and Object-Oriented programming (OOP), and we'll learn some new stuff too. To get started, open up another project: Shapes. It can be found in examples/shapes in the folder where BlueJ is installed or in the one you downloaded.

The Shapes Project will let you display graphics through its Canvas class. You don't need to know how Canvas works internally to be able to interact with it, which is one of the benefits of OOP.

BlueJ Interface

Before you get started, Click on View > Show Terminal so you can view the code for the actions you do in BlueJ. If the class rectangles have diagonal grey lines on them, click "Compile" to compile them. (You should have already clicked on Options > Record Method Calls.)

  1. Using the BlueJ interface, create a Circle instance circle1. You can then inspect it to see the default values of its instance variables.
  2. Invoke its makeVisible() method. This should cause a window to pop up with a circle in it.
  3. Invoke other methods on the circle, such as moveRight() and changeColor(). Notice what happens to the circle. You can now inspect the Circle again to see how its variables have changed.

shapes


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Comments

  • public Picture()
    {
    // initialise instance variables

        circle1.moveUp();
        circle1.moveHorizontal(50);
        circle1.changeColor("yellow");
    
    cont...
  • You need to create circle1 first (See the animation above).

  • Hi. When you compile circle, create a new instance of circle and then compile Picture, it deletes your instance of circle. So circle1 is deleted before it compiled Picture.

    How do I stop it from deleting my instance?

  • Only code that it's the actual source code file is saved. As mentioned, double-click on a Class icon to edit its source code.

  • Many issues with compiling? I imported the missing classes but still many other errors in Canvas.java, can't get it to work!

Contact Us
Sign in or email us at [email protected]