Assignment 1
"Hello World"

Write a 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 main loop.

Using Objects

Use object-oriented programming to encapsulate the parts of your program separately. In particular, 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).

Java Software

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 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.

Coding Style

For this assignment focus on writing readable code. In short this means:

Programming Practices

You should follow these general Java programming practices:

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.

Teaching Assistant

See the course home page for contact info.