The goal of this section is to come up with something that looks like this:
You might be tempted to just draw that and skip this section. Don't.
The Bean
Bean? WTF? A Bean is a visual component in Java - usually something
like a dialog window or your program's main window. The first step is to
create a new Project and Package for your Bean. Then add a
new Class to the package. That's a CLASS, NOT
an Applet. Set the Superclass to java.lang.Object.
I'm assuming you know how to do this. Make sure you check the
Compose the class visually box.
The Frame
Ok, we need to start with the container for all that other junk. There are
2 main components we can use here - JFrame and JDialog. There is
a subtle difference between these components. JFrame is a fully-functional
Windows window, where as JDialog is a popup-sort-of window. That sounds
pretty weak. Essentially, you should use a JFrame for the part of your
program that is always visible (unless it's minimized), while JDialog's
pop up when you need them, and disapear when you don't.
First find the JFrame button. It looks like this:
Now draw this:
The JScrollPanes
You could just plop down two JLists and everything would work fine. Fine,
that is, until you put enough things in the list to fill it up. Then anything
you added would be inaccessible, because JLists don't know how to scroll. See,
Swing components know how to draw themselves within a defined area. They
just don't know what part of themselves to draw. The JScrollPane is a component
that tells the JList which part of the list to draw within it's boundaries.
Find the JScrollPane button:
Now draw:
The JLists
Ok, time to add some lists to those ScrollPanes
Find the JList button:
Now draw:
The Rest
We also want a text field and two buttons with the labels "Add" and "Quit".
I think you can figure out how to do those yourself. What we want in the
end is something like this:
Now we have our basic dialog finished. However, if you were to click on
the Run button in VAJ, nothing would happen. We have to make some
connections first...
Part 2: A Connection Is Made
Back to the Tutorial
|