
CISC 370 Lecture Notes for Class No. 13 March 21, 2000
| Course Home | Prev Lect | Next Lect | Example Progs | Exercise Solns | CoreJava Progs Documentation |
Gen'l Docs | Java 2 APIs | Java Glossary | Term Proj Info |
1. The Color Mixer application, described below and in the accompanying code, generates six listener objects, one for each of the three scroll bars and one for each of the three text fields. Rewrite the application using only two listener objects, one for the three scroll bars and one for the three text fields. To do this, make use of the method getSource() and the instance variables for the scroll bars and text fields that are defined for the class ScrollTest.
To prepare programming assignments for submission, do the following for each exercise.
script // Produces a file named typescript whoami date pwd cat *.java javac *.java // mainFile should be the name of the file containing java mainFile // your main() method exit // to exit script
Now print the typescript file for submittal at the beginning of lecture.
On strauss, you can use xv as demoed in lecture to grab and print a copy of the graphics output from your Java programs that should be handed-in with your assignment.
Things to notice about this example.
public Scrollbar(int orientation,
int value,
int visible,
int minimum,
int maximum)
Constructs a new scroll bar with the specified orientation, initial
value, page size, and minimum and maximum values.
The orientation argument must take one of the two values SwingConstants.HORIZONTAL, or SwingConstants.VERTICAL, indicating a horizontal or vertical scroll bar, respectively. SwingConstants is an interface that contains named constants used by various Swing classes. Interfaces can define constants in addition to specifying prototypes for methods.
If the specified maximum value is less than the minimum value, it is changed to be the same as the minimum value. If the initial value is lower than the minimum value, it is changed to be the minimum value; if it is greater than the maximum value, it is changed to be the maximum value.
Parameters:
orientation - indicates the orientation of the scroll bar.
value - the initial value of the scroll bar.
visible - the size of the scroll bar's bubble, representing the visible
portion; the scroll bar uses this value when paging up or
down by a page. This is for use when a scroll bar is
used for scrolling on a page. Scrollbar components are
not used much for such applications anymore since the
JScrollPane class was introduced in Java 2.0.
minimum - the minimum value of the scroll bar.
maximum - the maximum value of the scroll bar.
In our application the third param, visible, has nothing to do
with the visible portion of the page that is visible, but does
effect how finely we can control the scrollbar. Smaller values give
more finely grained control.
For more information about scroll bars, see Horstmann & Cornell, Vol I, pp. 441-5.
Text fields, used for text input in GUIs, are described on pp. 386-393.
Back to the
CISC 370 homepage.
This page has been accessed
times since 25 Mar 2000.
Corrections, suggestions and comments to Bob Caviness
Copyright
2000 B. F. Caviness