Chapter 8. SWT: Text, Buttons, Lists, and Nonrectangular Windows
Introduction
IBM created the Standard Widget Toolkit (SWT) as a replacement for the Abstract Windowing Toolkit (AWT) and Swing in Java. The SWT is a fully featured GUI API, and it comes built into Eclipse. There’s a lot to cover in this and in the following two chapters. We’re going to see some impressive code.
Java has had a long history of supporting GUIs. One of the early efforts
was Java applets, and you can see an example in an Eclipse
project,
Applet, in Example 8-1.
Example 8-1. An example applet
package org.cookbook.ch08;
import java.applet.Applet;
import java.awt.*;
public class AppletClass extends Applet {
public void init( )
{
setBackground(Color.white);
}
public void start( )
{
}
public void paint(Graphics g)
{
g.drawString("Greetings from Applets.", 40, 100);
}
public void stop( )
{
}
public void destroy( )
{
}
}Launch this applet from Eclipse by selecting Run→ Run As→ Java Applet. You can see the results in Figure 8-1.

Figure 8-1. A Java applet launched from Eclipse
As an early GUI offering, Sun wrote the AWT in a few weeks and it was quite a success in its time. The AWT was easy to use and enabled Java developers to create rudimentary GUIs.
The AWT used the underlying operating system’s controls. In Windows, for example, you’d see a Windows text box; on the Macintosh, you’d see a Mac text box. In fact, because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access