CIS279-BASFORD-06/07/01

Java Programming
CIS279
Tori Basford
tori@bly.net

Assignment(s):
CIS 279 Homework 1, parts b and c: Adding a Listener / Creating Bars of different Colors

Exercise(s):

  1. None

Quiz 3:

  1. Worth: ?? Points
  2. Covers: Writing a program to place a JButton on the screen and setting the color and text of it.

Review: Java Basics
Outside of a method, you can only put declaration statements.

Java demands that every variable MUST be initalized. Object and Class variables are automatically initialized to zero or false or NULL.

The standard Java Classes are located in "java.lang.*" and are imported by default.

Components, continued:
Everything on the screen is a Component with extra stuff added. The basic Component contains

Layout Managers:
A Layout Manager Object is a collection of methods to size and position components.

To change the Layout Manager:

  1. Create a new LayoutManager object and some particular type.
  2. Use the setlayout(LayoutManager Object) method to change the LayoutManager for a particular component.
  3. Finally Java looks in class variables

By default, Java basically does the following comands:
LayoutManager lm = new FlowLayout();
panel object.setLayout(lm);

To change a BorderLayout, you use the object.setLayout(new BorderLayout()) function. If a Component has a BorderLayout, it can contain a max of 5 items in the North, South, East, West, and Center portions. The portion is specified in the add function.

For Example: jp.add(jb1, BorderLayout.NORTH); would add the component jb1 to the panel jp, and would align it to the top of the panel.

More on the ColorBar class:
The ColorBar class will recieve a value to show whether the ColorBar deals with Red, Green or Blue.

The value for what coresponds to each color will be stored in the static variables RED_SIGNAL, BLUE_SIGNAL, and GREEN_SIGNAL. So, if you've chosen character data, for example, then you'r econstructor will be ColorBar(char c) {. For now, just store the color.
example:
ColorBar cb1 = new ColorBar(ColorBar.BLUE);



[ return ]