Chapter 11.1

Post on 23-Jun-2015

157 views 2 download

Tags:

Transcript of Chapter 11.1

SIMPLE GUI I/OChapter 11.1:

Graphical User Interface In Java, GUI-based programs are implemented by

using classes from the javax.swing and java.awt packages.

The Swing classes provide greater compatibility across different operating systems. They are fully implemented in Java, and behave the same on different operating systems.

Various Java GUI Componentsfrom the javax.swing package

Button

Label Text field

Check Box

Radio Button

Combo Box

Sample GUI Objects Various GUI components from the javax.swing

package.

AWT Class Hierarchy (java.awt package)

AWTEvent

Font

FontMetrics

Component

Graphics

Object Color

Canvas

Button

TextComponent

Label

List

CheckBoxGroup

CheckBox

Choice

Container Panel Applet

Frame

Dialog FileDialog

Window

TextField

TextArea

MenuComponent MenuItem

MenuBar

Menu

Scrollbar

LayoutManager

Swing Class Hierarchy (javax.swing)

Dimension

Font

FontMetrics

Component

Graphics

Object Color

Container

Panel Applet

Frame

Dialog

Window

JComponent

JApplet

JFrame

JDialog

Swing Components in the javax.swing package

Lightweight

Classes in the java.awt package

1

LayoutManager

*

GUI Classes Can be classified into three groups

Container classes○ Ex: JFrame, JPanel, Japplet○ To contain other components

Helper classes○ Graphics, Color, Font, etc○ Used by components and containers to draw

and place objectsComponent classes

○ JButton, JTextField, ETC are subclasses of JComponent

Container Classes

Dimension

Font

FontMetrics

Component

Graphics

Object Color

Container

Panel Applet

Frame

Dialog

Window

JComponent

JApplet

JFrame

JDialog

Swing Components in the javax.swing package

Lightweight

Heavyweight

Classes in the java.awt package

1

LayoutManager

*

JPanel Container classes can contain other GUI components.

Container Classes Used to contain other GUI components Window, Panel, Frame, Dialog and Applet

are the container classes for AWT components

To work with Swing components, use Component, Container, JFrame, JPanel,JDialog and JApplet

ContainerUsed to group components. A layout manager is used to position and place

components in containerEx. Frames, panels and applets

Container Classes Jframe

Is a window not contained inside another window. It is the container that holds other swing UI components

JpanelAn invisible container that holds UI componentsPanel can be nestedCan place panels inside a container that includes a panel

JdialogA pop-up windows or message box to receive additional

information from the user or provide notification that an event has occurred

JApplet – a subclass of Applet. Must extend JApplet to create a Swing-based applet

GUI Helper Classes

Dimension

Font

FontMetrics

Component

Graphics

Object Color

Container

Panel Applet

Frame

Dialog

Window

JComponent

JApplet

JFrame

JDialog

Swing Components in the javax.swing package

Lightweight

Heavyweight

Classes in the java.awt package

1

LayoutManager

*

JPanel The helper classes are not subclasses of Component. They are used to describe the properties of GUI components such as graphics context, colors, fonts, and dimension.

Swing GUI Components Component is a superclass of all the UI

classes JComponent is a superclass of all the

lightweight Swing components JComponent is an abstract class, cannot use

new JComponent to create an instance of Jcomponent

Use the constructor of subclasses of JComponent to create JComponent instances.

An instance of a subclass can invoke the accessible method defined in its superclass

Swing GUI Components – class hierarchy

JMenuItem

JCheckBoxMenuItem

AbstractButton

JComponent

JMenu

JRadioButtonMenuItem

JToggleButton JCheckBox

JRadioButton

JComboBox

JInternalFrame

JLayeredPane

JList

JMenuBar

JOptionPane

JPopupMenu

JProgressBar

JFileChooser

JScrollBar

JScrollPane JSeparator JSplitPane

JSlider

JTabbedPane

JTable JTableHeader

JTextField JTextComponent

JTextArea

JToolBar JToolTip

JTree

JRootPane

JPanel

JPasswordField

JColorChooser

JLabel

JEditorPane

JSpinner

JButton