Componenetes Swing

Páginas: 24 (5795 palabras) Publicado: 8 de julio de 2011
AWT and Swing

• Java 1.1 and below: used the AWT (Abstract Window Toolkit) and its components for building GUIs.
• Java 1.2 introduced the more flexible Swing API with Swing components as an improved alternative to the AWT components. Swing and AWT are quite intertwined as Swing relies on features of the AWT.

The major difference between AWT and Swing

• AWT components matchexactly the form of corresponding components in the operating system for the platform (computer) you are using, so their appearance is platform dependent.

• Components drawn using the Swing API may look the same regardless of the platform being used (platform independent), and they may have a different appearance from the components used by the operating system for that platform.

• Each AWTcomponent relies on a corresponding component in the platform's operating system (called a peer component) to draw it.

• Components in the Swing API use a pure Java method to draw itself so they are called lightweight components.

Categories of classes in Swing and AWT

• Swing GUI component classes: includes basic window objects like buttons, text fields, menu items. Also included arepanels and applets which act as containers (groupings) for the basic window objects.
• AWT Layout manager classes: Used to determine the placement of objects in a container
• AWT Event classes: Define the events that are generated when users do things such as click buttons, select menu items, and move the mouse.
• AWT Listener classes: Contain methods that are activated by the browser whenevents occur.

GUI Component classes

The GUI in Fig. 6.** enables the user to enter a distance value and then press a button to initiate a conversion operation. The GUI contains from top to bottom a label (the prompt string "input distance >>"), a text field for data entry with the number 100, two buttons that are used to select a conversion operation, and a text area for output. The outputshown in the text area appears after the user presses the button with label "Convert to kms".

Figure 6.2 A GUI for Converting Distances

|Object |Component type |Purpose |
|Label "Input distance>>" |JLabel |Provides information to the user|
|Text field with number 100 |JTextField |Place where user enters data (100) |
|Button with label "Convert to kms" |JButton |Starts conversion operation |
|Button with label "Convert to miles" |JButton |Starts conversion operation|
|Two-line text area at bottom of GUI |JTextArea |Place where user views results |

Figure 6.** shows part of the AWT and Swing class hierarchy. Several Swing classes at the bottom of the diagram (JLabel, JOptionPane, and so on) extend Swing class JComponent, which in turn extends AWT class Container. Also, classJApplet (from Swing) extends class Applet (from AWT), so you can see that the AWT and Swing APIs are intertwined.

Figure 6.** Part of AWT and Swing Hierarchy

Object
----------------------------------
Component java.awt

Container

Panel-----------------

Applet java.applet

-------------------------------------------------------------
JApplet JComponent javax.swing

JLabel JOptionPane JPanel AbstractButton JTextComponent

JButton JTextField JTextArea

JToggleButton

JCheckbox...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Swing
  • Swing
  • swinger
  • Swing
  • Swinger
  • swing
  • swing
  • componenetes de un automovil

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS