Java/Swing application program that creates a window
and then creates and displays several pushbutton widgets
and several other types of widgets
in the window.
Each button should have a different label.
When the user presses a button,
your program print a message on the standard output (i.e., the terminal window from which
you started your program).
The message should be different for each of the buttons.
In addition, one of the buttons should have a feature where
its own label changes each time the button is pushed.
The other widgets should also print a message on standard output when the
user interacts with them.
You may need to give your Main window a Layout object in order to show
more than one button or other widget.
Look at the "Workshop: Java Setup" page from the
lecture examples page
which is now updated to show you how to do this.
Your program will create the main window (i.e. the window that
contains the other widgets), create the widgets and lay them out, create any other data
objects you need, and install listeners for your widgets as
needed. Then, it lets the Java window system take over, providing the
Use object-oriented programming to encapsulate the parts of your
each of your widgets should be a separate object,
of a class that you define.
It should inherit from the corresponding Swing widget
and add the routines and data specific to your widget.
That is, anything you need to know about the widget
from one callback to another,
beyond the information already maintained by Swing
(such as the message to be printed for each button).
You should use Java and Swing, version 1.8, 1.9, or 1.10 (a.k.a. Java 8, 9, 10).
We are using version 220.127.116.11 in class demos,
but the programs also run on 1.8.
If you haven't already,
download the Java software from the link on the
course home page and run on your own machine.
See this page for some additional notes on installation.
You can also run Java on the unix machines in the lab,
from the unix command line; or the Windows machines in the
lab, where Java should should already be installed.
If there are any
incompatibilities, your code should ultimately compile and run on the
machine the TA uses for grading. We will use this first assignment to discover any incompatibilities we didn't know about.
For this assignment focus on writing readable code. In short this means:
- Be neat
- Keep indentation consistent and meaningful
- Comment your code where it might be confusing
- Include a header comment at the top of each file with your name,
email, and a brief description of the class in the file.
- Include a readme file with your submission (even if this is simple for now)
- Use reasonable names for classes, variables, and functions
You should follow these general Java programming practices:
Make all instance variables of your classes protected or private.
If you need access outside of the class, provide it with set
Avoid most global variables or widely-accessible public variables;
pass the data you need explicitly.
Put each class in a separate .java file.
And, finally, on your Java programs, for uniformity, please
name your Java class that has your main program in it
Main, in file
Coding style will count more as the semester progresses.
How to Submit Your Programs
Follow the procedure here to submit your assignment.
See the course home page for contact info.