- Objects
- Classes
- Inheritance
-
Programming in Java on Your Computer - Classes and Objects in BlueJ
- Trying out Code in BlueJ
- The Code for Creating and Using Objects
- Source Code and Methods
- Accessors and Mutators
- Constructor Code
- Scope
- Inheritance
-
BlueJ Review - Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
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.)
- Using the BlueJ interface, create a Circle instance
circle1
. You can then inspect it to see the default values of its instance variables. - Invoke its makeVisible() method. This should cause a window to pop up with a circle in it.
- 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.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.
Comments
catypus
Oct 12, 9:03 PMpublic Picture()
{
// initialise instance variables
Doesn't work because it cannot find symbol "circle1". How do I make it work?
Learneroo
Oct 12, 9:08 PMYou need to create
circle1
first (See the animation above).catypus
Oct 12, 9:24 PMHi. 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?
Learneroo
Oct 12, 9:31 PMOnly code that it's the actual source code file is saved. As mentioned, double-click on a Class icon to edit its source code.
Rinon
Feb 7, 3:59 PMMany issues with compiling? I imported the missing classes but still many other errors in Canvas.java, can't get it to work!