0% found this document useful (0 votes)
18 views6 pages

OOPR212 PrelimsReviewer

The document outlines the main aspects of user interfaces, focusing on UI elements, layouts, and behavior, particularly in the context of Java Swing. It details various components such as frames, labels, buttons, text fields, and layout managers, along with their constructors and functionalities. Additionally, it explains how to manage component behavior and layout within a graphical user interface.

Uploaded by

perk30 69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

OOPR212 PrelimsReviewer

The document outlines the main aspects of user interfaces, focusing on UI elements, layouts, and behavior, particularly in the context of Java Swing. It details various components such as frames, labels, buttons, text fields, and layout managers, along with their constructors and functionalities. Additionally, it explains how to manage component behavior and layout within a graphical user interface.

Uploaded by

perk30 69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OOPR212 (PRELIMS)

*Every user interface considers the following three main aspects:

1. UI elements : These are the core visual elements the user eventually sees and interacts with.

2. Layouts: They define how UI elements should be organized on the screen and provide a final look and
feel to the GUI GraphicalUserInterface.

3. Behavior: These are events which occur when the user interacts with UI elements.

*Graphical user interface components:

1. Frames—Windows that can include a title bar; menu bar; and Maximize, Minimize, and Close buttons

The constructor of the class should handle the following tasks:

-Call a superclass constructor to give the frame a title and handle other setup procedures.

-Set the size of the frame’s window, either by specifying the width and height in pixels or by
letting Swing choose the right size.

-Decide what to do if a user closes the window.

-Display the frame.

*The JFrame class has two constructors: JFrame() and JFrame(String). One sets the

frame’s title bar to the specified text, and the other leaves the title bar empty. You also

can set the title by calling the frame’s setTitle(String) method.

*The size of a frame can be established by calling the setSize(int, int) method with the

width and height as arguments.

*Another way to set the size of a frame is to fill the frame with the components it will

contain and then call the frame’s pack() method. This resizes the frame based on the

size of the components inside it.

*Frames are invisible when they are created. You can make them visible by calling the

frame’s setVisible(boolean) method with the literal true as an argument.

*When a frame is displayed, the default behavior is for it to be positioned in the upper-left

corner of the computer’s desktop. You can specify a different location by calling the
setBounds(int, int, int, int) method. The first two arguments to this method are

the (x,y) position of the frame’s upper-left corner on the desktop. The last two arguments

set the width and height of the frame.

*To change this, you must call a frame’s setDefaultCloseOperation() method with one

of four static variables of the JFrame class as an argument:

-EXIT_ON_CLOSE—Exit the application when the frame is closed.

-DISPOSE_ON_CLOSE—Close the frame, remove the frame object from memory, and

keep running the application.

-DO_NOTHING_ON_CLOSE—Keep the frame open and continue running.

-HIDE_ON_CLOSE—Close the frame and continue running.

Component

A Container is the abstract base class for the non menu user-interface controls of SWING.

Component represents an object with graphical representation

Container - Interface elements that can hold other components

A Container is a component that can contain other SWING components.

JComponent

A JComponent is a base class for all swing UI components. In order to use a swing component that
inherits from JComponent, component must be in a containment hierarchy whose root is a top-level
Swing container.

2. JLabel

Labels—Text or graphics that provide information. A JLabel object is a component for placing text in a
container.

To create a label, you can use the following constructors:

JLabel(String)—A label with the specified text

JLabel(String, int)—A label with the specified text and alignment

JLabel(String, Icon, int)—A label with the specified text, icon, and alignment
3. JButton

Buttons - Clickable regions with text or graphics indicating their purpose. This class creates a labeled
button.

Constructors you can use for buttons include the following:

JButton(String)—A button labeled with the specified text

JButton(Icon)—A button that displays the specified graphical icon

JButton(String, Icon)—A button with the specified text and graphical icon

4. JTextField

Text fields and text areas—Windows that accept keyboard input and allow text to be edited

A text field is a location on an interface where a user can enter and modify text using the Keyboard

Constructors for text fields include the following:

JTextField()—An empty text field

JTextField(int)—A text field with the specified width

JTextField(String, int)—A text field with the specified text and width

Password fields are text fields that hide the characters a user is typing into the field. They

are represented by the JPasswordField class, a subclass of JTextField. The JPasswordField


constructor methods take the same arguments as those of its parent class.

After you have created a password field, call its setEchoChar(char) method to obscure input by
replacing each input character with the specified character.

5. JTextArea

Text areas, editable text fields that can handle more than one line of input

TextArea includes the following constructors:

JTextArea(int, int)—A text area with the specified number of rows and columns

JTextArea(String, int, int)—A text area with the specified text, rows, and columns

The setLineWrap(boolean) method determines whether text will wrap to the next line

when it reaches the right edge of the component. Call setLineWrap(true) to cause line

wrapping to occur.
The setWrapStyleWord(boolean) method determines what wraps to the next line—

either the current word (true) or the current character (false).

6. JScrollPane

Swing supports scrollbars through a new container that can be used to hold any compo-nent that can be
scrolled: JScrollPane.

A scrolling pane is associated with a component in the pane’s constructors:

JScrollPane(Component)—A scrolling pane that contains the specified component

JScrollPane(Component, int, int)—A scrolling pane with the specified component, vertical scrollbar
configuration, and horizontal scrollbar configuration

Scrollbars are configured using static class variables of the ScrollPaneConstants inter-face. You can use
each of the following for vertical scrollbars:

VERTICAL_SCROLLBAR_ALWAYS

VERTICAL_SCROLLBAR_AS_NEEDED

VERTICAL_SCROLLBAR_NEVER

7. JColorChooser

A JColorChooser provides a pane of controls designed to allow a user to manipulate and

select a color.

Check boxes and radio buttons—Small squares or circles that can be selected or deselected

Check boxes (the JCheckBox class) appear as labeled or unlabeled boxes that contain a check mark when
they are selected and nothing otherwise. Radio buttons (the JRadioButton class) appear as circles that
contain a dot when selected and are also empty otherwise.

8. JCheck Box

A JCheckBox is a graphical component that can be in either an on true or off false state.

The following constructors are available for the JCheckBox class:

JCheckBox(String)—A check box with the specified text label

JCheckBox(String, boolean)—A check box with the specified text label that is selected if the second
argument is true

JCheckBox(Icon)—A check box with the specified graphical icon


JCheckBox(Icon, boolean)—A check box with the specified graphical icon that is selected if the second
argument is true

JCheckBox(String, Icon)—A check box with the specified text label and graphical icon

JCheckBox(String, Icon, boolean)—A check box with the specified text label and graphical icon that is
selected if the third argument is true

9. JRadioButton

The JRadioButton class is a graphical component that can be in either an on true or off

false state in a group.

To organize several radio buttons into a group, allowing only one to be selected at a time,

create a ButtonGroup class object, as demonstrated in the following statement:

ButtonGroup choice = new ButtonGroup();

The ButtonGroup object keeps track of all radio buttons in its group. Call the group’s

add(Component) method to add the specified component to the group.

Drop-down lists—Groups of related items that can be selected from drop-down menus or scrolling windows

10. Combo Boxes

The Swing class JComboBox can be used to create combo boxes, components that present

a drop-down menu from which a single value can be selected. By hiding the menu when

the component is not being used, it takes up less space in a graphical user interface.

The following steps show how a combo box can be created:

1. The JComboBox() constructor is used with no arguments.

2. The combo box’s addItem(Object) method adds items to the list.

11. List

Lists can be created and filled with the contents of an array or a vector. The following

constructors are available:

JList()—Create an empty list.

JList(Object[])—Create a list that contains an array of the specified class (such as String).
JList(Vector)—Create a list that contains the specified java.util.Vector object.

Swing Layout

Layout means the arrangement of components within the container.

A layout manager determines how components will be arranged when they are added to a container.

1. BorderLayout
 The borderlayout arranges the components to fit in the five regions: east, west, north,
south and center.
2. CardLayout
 The CardLayout object treats each component in the container as a card. Only one card
is visible at a time.
3. FlowLayout
 The FlowLayout is the default layout. It layouts the components in a directional flow.
4. GridLayout
 The GridLayout manages the components in form of a rectangular grid.
5. GridBagLayout
 This is the most flexible layout manager class.The object of GridBagLayout aligns
thecomponent vertically, horizontally or along their baseline without requiring the
components of same size.
6. GroupLayout
 The GroupLayout hierarchically groups components in order to position them in a
Container.
7. SpringLayout
 A SpringLayout positions the children of its associated container according to a set of
constraints.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy