Professional Documents
Culture Documents
Advanced Java Programming: Lecture 1: Introduction To GUI Programming
Advanced Java Programming: Lecture 1: Introduction To GUI Programming
Advanced Java Programming: Lecture 1: Introduction To GUI Programming
• Internationalization
Allows developers to build applications that can interact with users
worldwide in their own languages and cultural conventions.
• For example, the same program can use either the Java or the Windows
look and feel.
• Additionally, the Java platform supports the GTK+ look and feel, which
makes hundreds of existing look and feels available to Swing programs.
• The Synth package allows you to create your own look and feel.
• For this reason, Swing’s approach is called either the Model Delegate
architecture or the Separable Model architecture.
• Because the view (look) and controller (feel) are separate from the model, the look
and feel can be changed without affecting how the component is used within a
program.
• The first represents the model and second represents the UI delegate.
• Models are defined by interfaces. For example, the model for a button is defined by
the ButtonModel interface.
• UI delegates are classes that inherit ComponentUI. For example, the UI delegate for
a button is ButtonUI.
• Thus, although event handlers are defined by our program, they are
called on a thread that was not created by the program.
• So all Swing GUI components must be created and updated from the
event dispatching thread, not the main thread of the application.
• Programs that ignore this rule may function correctly most of the
time, but are subject to unpredictable errors that are difficult to
reproduce.
Constructors:
• JPanel()
Creates a new JPanel with default flow layout.
• JPanel(LayoutManager layout)
Create a new JPanel with the specified layout manager.
• PanelUI getUI ()
Returns the look and feel (L&F) object.
JScrollPane(Component comp)
• Selecting a tab causes the component associated with that tab to come
to the forefront.
• If you want similar functionality without the tab interface, you can
use a card layout instead of a tabbed pane.
Adding Tabs:
• Colors are made of red, green, and blue components, each represented
by an int value that describes its intensity, ranging from 0(lightest
shade) to 255(darkest shade). This is known as the RGB model.
public FlowLayout ()
public FlowLayout (int alignment)
public FlowLayout (int alignment, int H_Gap, int V_Gap)
Methods:
first() / last()/ next()/ previous(): is used to make the first/ last/
next/ previous card visible.
• The icon and text associated with a label can be set by these
methods:
void setIcon(Icon icon)
void setText(String str)
JTextField
• JTextField allows us to edit one line of text.
JTextField(int cols)
JTextField(String str, int cols)
JTextField(String str)
• This number is used along with metrics provided by the field's current
font to calculate the field's preferred width.
• It does not limit the number of characters the user can enter.
Lovely Professional University, Punjab (India)
JTextArea
• A JTextArea is a multi-line area that displays plain text.
JTextArea ()
JTextArea (String str)
JTextArea (int rows, int cols)
JTextField (String str, int rows, int cols)
• For security reasons, a password field does not show the characters
that the user types.
• Instead, the field displays a character different from the one typed,
such as an asterisk ‘*’.
JToggleButton(String str)
JCheckBox(String str)
• JTable does not provide any scrolling capabilities of its own. Instead,
we normally wrap a JTable inside a JScrollPane.
• The first is ListModel. This interface defines how access to the list
data is achieved.
• A combo box normally displays one entry, but it will also display a
drop-down list that allows a user to select a different entry.
JComboBox(Object[ ]items)