Page 411 - CITS - Computer Software Application -TT
P. 411
COMPUTER SOFTWARE APPLICATION - CITS
The code in Listing 4 adds the creation of two buttons to the code presented in Listing 3. The creation is performed
in the init() method because it is automatically called during applet initialization. Therefore, no matter how the
program is started, the buttons are created, because init() is called by either the browser or by the main() method.
Figure 6 contains the resulting applet.
import java.awt.*;
public class Example3 extends java.applet.Applet
{
public void init()
{
add(new Button(“One”));
add(new Button(“Two”));
}
public Dimension preferredSize()
{
return new Dimension(200, 100);
}
public static void main(String [] args)
{
Frame f = new Frame(“Example 3”);
Example3 ex = new Example3();
ex.init();
f.add(“Center”, ex);
f.pack();
f.show();
}
}
Introduction to AWT UI controls, hierarchy and their features
Introduction to AWT UI controls
Java AWT (Abstract Window Toolkit) is an API to develop Graphical User Interface (GUI) or windows-based
applications in Java.
Java AWT components are platform-dependent i.e. components are displayed according to the view of operating
system. AWT is heavy weight i.e. its components are using the resources of underlying operating system (OS).
The java.awt package provides classes for AWT API such as TextField, Label, TextArea, RadioButton, CheckBox,
Choice, List etc
Java AWT calls the native platform calls the native platform (operating systems) subroutine for creating API
components like TextField, ChechBox, button, etc.
For example, an AWT GUI with components like TextField, label and button will have different look and feel for the
different platforms like Windows, MAC OS, and Unix. The reason for this is the platforms have different view for
their native components and AWT directly calls the native subroutine that creates those components.
In simple words, an AWT application will look like a windows application in Windows OS whereas it will look like
a Mac application in the MAC OS.
398
CITS : IT&ITES - Computer Software Application - Lesson 116 - 119