Java Programming
CIS279
Tori Basford
tori@bly.net
Assignment(s):
CIS 279 Homework 1, Part a: ColorBar
Exercise(s):
Review: Java Basics, Objects
Java is polymorphic. You can have several methods with the same name, but with different inputs.
There are three places methods and variables can be:
Resolving Symbols:
Abstract Methods:
The class AdjustmentListener contains a partial, incomplete version of adjustmentValueCahgned called an abstract (or incomplete) method.
In order to use the AdjustmentListener (or even compile the program), you have to replace the abstract method with a new one.
AdjustmentListener al = new AdjustmentListener() {
    public void adjustmentValueChanged(AdjustmentEvent ae) {
        ...
    }
}
This creates an AdjustmentListener object but replaces some of it's methods.
Note: You can only replace existing methods. You can NOT add new ones.
The ColorBar class - an example of Extending Classes:
|
class ColorBar
    JScrollBar jsb;     JPanel display;     ColorBar() {         JScrollBar jsb = new JScrollBar(JScrollBar.HORIZONTAL);         jsb.setPreferredSize(new Dimension(120,20));         JPanel display = new JPanel();         display.setPreferredSize(new Dimension(50,50));         display.setBackground(Color.yellow);         this.add(jsb);         this.add(diplay);     } } |
The Layout Manager:
The Layout Manager decides where to put each component and how big to make it. It first manages when the setVisible() method is called. It also manages sizes and locations when the window is resized or when components are changed. It manages by calling the component's setSize() and setLocation() methods.
There are different layout managers which allow different levels of control.