Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
What is Swing, Anyway?
-
So far this quarter we've been talking about objects. Everything in Java
is object based.
-
This includes Swing. JFrames, JPanels, JTextFields, JButtons are
all classes.
-
When we want to use them, we simply instantiate a new object of that type.
-
So, every button on your Swing GUI is an object of type JButton (or some
subclass thereof.)
-
Speaking of which, you can extend these components as you wish. Say
you wanted all buttons to have a blue background. You simply extend
the JButton class into a class of your choosing, say, JBlueButton.
Then, you change the background color attribute, and instantiate JBlueButton
objects every time you want a new blue button!
-
Like all objects, these objects have properties and methods. They
conform to the JavaBeans standard, so you will often find getter and setter
methods, or accessor and modifier methods.
-
All Swing components extend JComponent. This includes components
like JTextField and JButton, as well as JFrame and JPanel.
-
Why the 'J'?
-
Swing only came about in Java version 1.2. Before that, components
were AWT (Abstract Windowing Toolkit) components. These were named
simple names, like Button and TextField. To differentiate between
the two, Swing components generally start with the letter 'J'.
-
Swing components are much more object oriented than AWT components.
Swing has become the defacto standard for GUI development. But you
still occasionally see AWT components in older programs and in applets.
-
To use AWT components, import java.awt.*;. To use Swing components,
import javax.swing.*;.
-
What is a layout manager?
-
Layout managers arrange our components. Keep in mind, Java is written
to run on many platforms. The display is not the same on all platforms,
so your GUIs must be flexible. This is where layout management comes
in.
-
And then there is Model View Controller
Model View Controller



Created by: Brandan
Jones January 4, 2002