- Okay, now it is time to make a big
jump. We need to go from a simple application to a serious one
that is more representative of the kinds of applications you
will build in real life.
- To do so, we will take advantage of
the AWT class package that is distributed with the JDK.
- As I said in the pre-requisite article
Web Programming 101, one of the big benefits of using Java is
the ability it gives you to create web-based graphical user
- GUIs are one of the nicest things about
modern-day programming. Instead of forcing the user to deal
with strange command-line input such as in this
can present the user with a user-friendly interface such as that
designed by Macintosh and then taken for Windows. GUIs make using
a computer fun instead of a skill.
- For the rest of the day we will focus
on using the Java AWT packages to build user interfaces.
- However, before we can
begin, we need to understand how you can get information about
all of the functionality available to you from the AWT libraries
because there is no way that we can go over all the methods,
fields and constructors of all the java objects (This is
literally a book's worth of information).
- Fortunately, you don't need to buy a
book to know everything you need to about java user-interface
design! All you need to do is understand how to use the online
API reference that is generated by a java utility called
- Hopefully you downloaded the
documentation when you downloaded the JDK. But if not, it is
Of particular interest to you will be the java.awt package
in which you will find the majority of classes that we will
discus in this tutorial.
- As we said, the online documentation
provides everything you need to know about
all of the objects java gives you to build user interfaces.
Specifically, it provides you with the public API you will use.
- Let's look at the documentation for the AWT
Button, widget for example.
Decrypting the Inheritance Hierarchy
- You will also notice about a dozen
methods that you can use to manipulate the button object.
- All public methods are available to you
using dot notation and the parameters you need to pass to them
are listed. For example, you know that if you use the setLabel()
method, you will have to pass a string as a parameter.
Notice also that if you click on the method, you will get a detailed
description including its return type.
Using the Online Documentation by Example
|Actually, you could bypass the import statement
by referring to the absolute path of Button such as
java.awt.Button myButton = new java.awt.Buttton();
However, the import statement will save you a lot of typing
since it creates a shortcut for you.
public class TestFrame
public static void main(String args)
Frame f = new Frame();
Button b = new Button("Hello Cyberspace");
Previous Page |