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
- Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
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.
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.