HOMEWORK 1: Getting Acquainted with Java Swing
This is an INDIVIDUAL assignment.
Objective
In this homework assignment, we want you to become familiar with the basics
of using Java Swing to create a GUI interface. Unlike in future assignments,
where you'll be extending Swing to do new things, here you'll only be
assembling already-provided Swing components to create a user interface.
Future assignments will build on this first assignment, so it's important
for you to get this one right and to understand what you have done.
PLEASE NOTE: You are NOT allowed to use any type of GUI builder tool for this assignment (anything that allows you to graphically lay out an interface and then automatically generates code for it). The reason is that this assignment is designed to get you up-to-speed on swing through writing some basic Swing code; if you're using a GUI builder, you're not getting that practice.
If you're unsure about the tools you're using, check with us first.
Description
During the course of this semester, we will be creating an interactive
photo album application. When completed, the application will allow
you to view photos, annotate them, and organize them in a variety of ways.
In this homework, we'll create the basic "shell" of the application. The
goal of this homework is to simply give you some practice writing basic
Swing GUIs (using existing components instead of creating your own), and
to make sure that your environment is set up correctly.
Your application must create a new window (a JFrame component) when it starts.
The components and behaviors that your application must provide in this
window are:
- A menu bar with the following menus:
- File:
- Import. Selecting this menu item should pop up a JFileChooser dialog box (see
here for details). Eventually (in future assignments), this will allow allows the user to select a new photo to import it, or select a folder to import all the photos in that folder, but for now the dialog box can do nothing, meaning that selecting either Open or Cancel should just dismiss it.
- Delete. Eventually this will delete any selected photos.
- Exit. This should quit the application.
- View: This menu should contain three radio-style buttons (see JRadioButtonMenuItem) that lets the user select
between three "view modes". These view modes should be mutually exclusive, meaning that when one is selected the
others are de-selected.
- Photo View. This should be the default selection. Eventually this will change the view mode to show a single photo.
- Grid View. Eventually this will change the view mode to show a grid of small "thumbnail" images of the imported phtos.
- Split View. Eventually this mode will show a single photo, with a "film strip" one-dimensional view of the imported photos below it.
- In the main portion of the window should be your content area. For
now (since we haven't written the content area component yet), this
can simply be a blank JPanel set to have a reasonable size.
- Along the bottom of the frame should be a label that will serve as a status bar, and be used to
display various messages.
- Along the left side of the frame will be a collection of tools that
will (eventually) operate on the content. These tools should include:
- A collection of toggle buttons (JToggleButton, but read on for more details), (at least 4, that we'll use to
tag the current photo eventually. You can come up with your own
tags for these, such as
"Vacation," "Family," "School," "Work," etc). Note that
the behavior I'm after here is that you should be able to "tag"
photos with zero or more of these flags. So, it's fine with me
if you want to use a different type of component that gives a
similar behavior but looks better (check boxes for instance).
- Two radio buttons that control which annotation mode you're in: Drawing or Text. When one of these is selected by the user, the other should be automatically unselected.
- Page forward and backward controls, which will eventually move through the imported photos
Your application must behave reasonably when resized, moved, etc. "Reasonably" means that the window should be resizable, but that panels that the various components should have minimum sizes so that control panels cannot be shrunk in a way that clips their contents. Likewise, enlarging the window should make the content size larger but not expand control panels unnecessarily. (Look at the way that most "standard" desktop apps behave when resizing, and ask if you have any questions.)
For all of the controls, selecting them should display a message in the
status label describing what control was just activated.
This should not be a hard assignment. Again, the main goal is to ensure
that you understand how to structure a basic Swing application, how
to write callbacks, and how to respond to events such as windows appearing
and disappearing (to change menu labels, for instance).
Deliverable
See here for instructions on how to submit your homework. These instructions will be the same for each assignment.