| CIT
594 Assignment
4: GUI Building in NetBeans Spring 2008, David Matuszek |
.jar filesCreate a GUI in NetBeans that can be used to control an animation.
Define an animation (at least "bouncing ball", but feel free to do something more interesting.)
Package your program as an executable .jar file, including your source files.
First, use NetBeans visual GUI editor to create the GUI for your project.
Start by creating a new project, but instead of choosing Java Application,
choose Java Desktop Application. Name your project Animation,
and name your main class animation.Animation. This will start
you in the GUI builder. Use it to create an interface that looks like this:
![]() |
|---|
| (Click to view larger image) |
Start by clicking in the center of the large area to select it. Then right-click
it and set the layout to BorderLayout. Drag a JPanel to the SOUTH
area, and using the information area on the right, find the name of
this JPanel and change it to controlPanel. Drag another JPanel
to the CENTER area, and name it displayPanel. Drag the appropriate
components to the control panel and, for each component, set its text to
the text you want on the component, and give it a meaningful name (for example,
runButton).
Hint: When you get into a mess that you can't seem to get out of, select the project and delete it. Be sure to also delete the source files. Then you can start over. Using the GUI editor is tricky, so don't be too upset if it takes you several tries to get it right.
To attach a Listener to a button: Select and right-click the button,
choose
Properties, then action, then [...].
For Action:, choose Create New Action...,
then for Action's Method:, type in the name of a method. This
will bring you to the source code where the new method has been created.
Here's what the buttons are supposed to do:
New -- Create a new animation, with new values. For example, with the
bouncing ball animation, you might have a ball with a new size, color,
and velocity. Don't start the animation running. Step -- Make one single step of the animation; that is, move from one
still picture to the next. Run -- Run the animation. Pause -- Pause the animation. When the Run button
is clicked, the animation will resume from where it left off. (In the
picture this button is named "Stop", but I later decided "Pause" was
a better name.) Reset -- Do not create a new animation, but go back to the beginning
of this one. Don't start the animation running. The slider controls the speed of the animation, from very slow or stopped (at the left end) to very fast (at the right end). Do this by controlling the time between successive frames. Do not exceed 40 frames/second.
Implement the Exit and About... menu items. The About... menu item should
include your name as author.
Provide an animation, using the Model-View-Controller and Observer design patterns, and controlled by a Timer. You will probably want to review my Animation slides from CIT591, and you may want to download the BouncingBall.zip example code.
Do any animation you like. I recommend that you start with the basic bouncing ball animation, which is sort of the "Hello World" of animation programs. Once you get that running, you can either stop there, or replace it with something more interesting; at that point, all the basic structure will be in place.
Jar files are like zip files. In fact, jar files are zip files. The
difference is that a jar file can be executed
by double-clicking on it--if (1) you have Java properly installed
on your machine (try entering java -version in a DOS window),
and (2) if you have set up the jar file properly.
In Eclipse you would Export your program as a jar file,
and follow the prompts. In Netbeans there is already a jar file,
but you have to fiddle with it. In NetBeans, choose Help > Help Contents
> Java Applications > Building Java Applications > Building
a jar file.
Hint: After making the jar file, it's a good idea to make
a copy of it, rename
the copy to have the .zip extension instead of the .jar extension,
and unzip it to be sure everything is there that's supposed to be there.
If you are missing anything (especially source files), or if we can't run
your jar file, you will lose points.
NetBeans comes with a visual GUI editor, and Eclipse doesn't. However, you can download one, as a plugin, from http://www.eclipse.org/vep/WebContent/main.php. Using it is very similar to using the one in NetBeans; I don't know which one is less buggy.
Build a jar containing everything in the complete NetBeans project, including
all your source files, and submit via Blackboard
before midnight Thursday, February 14.