CIS279-BASFORD-06/04/01

Java Programming
CIS279
Tori Basford
tori@bly.net

Assignment(s):
None

Exercise(s):

  1. See handout (AWT/Swing classes)

Quiz 2:

  1. Worth: 45 Points
  2. Covers: printing, variables, static variables, objects, object methods, accessor methods, passing arguments, for loops, etc.

Accounts:
User accounts should be set up now. The name is your first initial and your last name, and the password is '123456'. Upon logging in, you will have to set a new password. You also need to copy the shortcuts to JDK to the desktop. The correct ones are located in "d:\jdk1.31\ShortcutsD\PimaEast".

The Dog Class: An Example:
class Dog {
    static int a;
    int b;
    public static void main() {
        int c;
        System.out.println(fx());
        ...
    }
    static int fx() {
        ...
    }
    double fy() {
        ...
    }
}


In this example, static int a, method main(), and method fy() are located in the class. int b and method fy() are in the Dog object, which is NOT created until someone calls new Dog();.
Static methods and variables can call other static variables and methods, but can NOT call non-static items.
Each Dog object can be called an instance of the class Dog. Calling new Dog() is called 'instantiating the class'.

The toString() function:
Every object has a function called toString() which is used by Java to convert the object to a string for printing. If a toString() function is not written by the programmer, Java makes one automatically.

More on the Abstract Windows Toolkit:
If you use anything from the Abstract Windows toolkit (awt), Java starts some independent threads. To stop all threads and return to the DOS prompt, press Control-C.

To load the AWT, you have to import the classes in the package by using the import java.awt.*; command.

After importing the AWT, you have access to the following classes:

You can also import the improved versions in the package 'javax.swing' by the command import javax.swing.*;. These improved versions do not replace the original AWT classes (although it does include some of the AWT classes), but are located in other renamed classes: example:
JButton jb1 = new JButton();
jb1.setText("Ok");
String s = jb1.getText();


Panels contain buttons, labels, checkboxes, and other such items. Panels are created with the new JPanel() object method. Items are added to the panel via the JPanel.add(object) method. Panels can be put into other panels.

The final (outer) panel is set into a JFrames in order to be displayed. This is done with the JFrame.setContent.Pane(object).

By default, a JFrame is 0 by 0 in size. Size of JFrames can be set with the JFrame.setSize(int x,int y) object method. The current size of the frame can be found by the JFrame.getSize() object method.

By default, a JFrame is invisible. This is changed by the JFrame.setVisible(boolean); object method. The current visibility of the JFrame can be found by the JFrame.getVisible object method.

example:
JPanel jp = new JPanel();
JP.add(jb1);
JFrame jf = new JFrame();
jf.setContent(jp);
jf.setSize(200,200);
jf.setVisible(true);



[ return ]