OOPR212 PrelimsReviewer
OOPR212 PrelimsReviewer
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.
1. Frames—Windows that can include a title bar; menu bar; and Maximize, Minimize, and Close buttons
-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.
*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
*The size of a frame can be established by calling the setSize(int, int) method with the
*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
*Frames are invisible when they are created. You can make them visible by calling the
*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
*To change this, you must call a frame’s setDefaultCloseOperation() method with one
-DISPOSE_ON_CLOSE—Close the frame, remove the frame object from memory, and
Component
A Container is the abstract base class for the non menu user-interface controls of SWING.
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.
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.
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
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
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
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—
6. JScrollPane
Swing supports scrollbars through a new container that can be used to hold any compo-nent that can be
scrolled: JScrollPane.
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
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.
JCheckBox(String, boolean)—A check box with the specified text label 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
To organize several radio buttons into a group, allowing only one to be selected at a time,
The ButtonGroup object keeps track of all radio buttons in its group. Call the group’s
Drop-down lists—Groups of related items that can be selected from drop-down menus or scrolling windows
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.
11. List
Lists can be created and filled with the contents of an array or a vector. The following
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
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.