Java Programming
CIS279
Tori Basford
tori@bly.net
Assignment(s):
None
Exercise(s):
Clarification:
EVERY object has a toString() method which println calls. Therefore, any object can be printed with the System.out.println() method. However, not every object has a pr() function.
Replacing Methods:
When you create an object, you can choose to replace some of it's methods by putting the replacements in a set of braces {} following the new operator.
example:
JLabel l1 = new JLabel();
l1.setText("one");
JLabel l2 = new JLabel() {
    public void setText(String s) {
        System.out.println("NO");
    }
}
Components:
A Component is something that shows up on the screen in the AWT or the Swing classes.
Each Component has the following properties:
Other static Variables:
Inside the class Math, there is a static variable PI containing the value of Pi (3.14...).
Borders:
The class Border is defined inside the package javax.swing.border. So, in order to use it, we have to import the java.awt package and the javax.swing package, along with the javax.swing.border package.
Java will NOT (by default) import subdirectories in imported Classes.
Borders are not created with the new.Border method. They are created with the class method BorderFactory.createLineBorder(color, size). There are also other types of borders (Bevel, Abstract, Empty) which are made with different methods. Borders are then applied to compoents with the object.setBorder(border object) method.
example:
Border b = BorderFactory.createLineBorder(Color.yellow, 5);
JLabel lab1 = new JLabel('Stuff');
lab1.setBorder(b);
Component Events
When something in a Component happens, it creates an event. In order to react to it, we have to have a listen method.
For example, to 'listen' to a JScrollBar, we have to attach a AdjustmentListener object. This is done with the JScrollBar.addAdjustmentListener(object) method.
example:
AdjustmentListener al = new AdjustmentListener() {
    public void adjustmentValueChanged(AdjustmentEvent ae) {
        System.out.println("SB moved");
    }
}
JScrollBar jsb = new JScrollBar();
jsb.addAdjustmentListener(al);
Note: In order to use these Event Listeners, we have to import the java.awt.event.* package.