Вы находитесь на странице: 1из 3

JAVA GRAHICAL USER INTERFACE

Java Swing import javax.swing.*;

A graphical user interface (GUI is pronounced


“GOO-ee”) allows a user to interact visually with a
program. GUI gives a program a distinctive “look” and
“feel” enabling user to get familiar with the
application’s environment and learn its features more
quickly. Prior to the development of object-oriented
applications, user need to type in commands to get
the computer to function. With the advent of
technology, applications with graphical-based
interfaces emerged. GUI’s enable users to become
more productive using the application rather than
spending more time trying to remember which
keystroke or sequence of command to perform.

Java Abstract Window Toolkit (AWT)

import java.awt.*;

COMPONENTS DESCRIPTION
JButton javax.swing.JButton a “push button”.
javax.swing.JLabel display area for a short text or an image, or
JLabel
both.
javax.swing.JCheckBox an item that can be selected or
JCheckBox deselected. By convention, any number of check boxes in a
group can be selected.
javax.swing.JRadioButton an item that can be selected or
deselected. Used with the ButtonGroup object to create a
JRadioButton
group of buttons in which only one button at a time can be
selected.
javax.swing.JComboBox a component that combines a button
JComboBox
or editable field and a drop-down list.
javax.swing.JTextField a lightweight component that allows the
JTextField
editing of a single line of text.
javax.swing.JPasswordField a lightweight component that
allows the editing of a single line of text where the view
JPasswordField
indicates something was type, but doesn’t show the original
characters.
Difference between AWT and Swing
There are many differences between java awt and swing that are given below.

No. Java AWT Java Swing


Java swing components are platform-
1) AWT components are platform-dependent.
independent.
2) AWT components are heavyweight. Swing components are lightweight.
3) AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel.
Swing provides more powerful components
4) AWT provides less components than Swing. such as tables, lists, scrollpanes, colorchooser,
tabbedpane etc.
AWT doesn't follows MVC(Model View
Controller) where model represents data, view
5) Swing follows MVC.
represents presentation and controller acts as an
interface between model and view.

Form Properties and Events

COMMON PROPERTIES DESCRIPTION


Title Text in the form’s title bar
Font text displayed on the form and the default font of
Font
controls to be added to the form.
Foreground Color Color of the text.
Background Color Color of the form background.
Event Handling

The GUI allows the user to interact with the program by generating events. These interactions can
be evoked by moving the mouse, clicking the mouse, selecting menu, typing in a textbox, closing a
window, and others. These interactions pass through events handlers, calling a method as
triggered by the event.

Label, TextBoxes, Buttons and Menus

Label is normally used to hold text on the form. Although there are several ways to display text,
the Label control enables you to post messages on the form that can be changed by setting the
Label’s text property.

TextBox is used either displays a text or accept input from the user. Like for example, the
username textbox allows user to input their usernames and the password textbox allows users to
enter password.

A Button is a corner stone of almost all java application. With this control, user can be activated an
event that calls a method or a procedure.

Menus java.swing.JMenuBar;

Menus are essential element of GUIs. It is used to organized set of related commands without
cluttering the interface. Menus contains commands called menu items. Other menu may contain
additional submenus within a menu.

Вам также может понравиться