Some Swing Controls
The user interface examples that we will look at in this
course use Java Swing controls. They tend to be more popular
than the older Java AWT (Abstract Windowing Toolkit) controls.
Swing controls tend to be more streamlined, faster, and more
stable over a wider variety of platforms than their AWT
counterparts.
Methods for Controls
JButton
public JButton(String text)
Creates a button control that displays the parameter string text.
 
JFrame
-
public JFrame(String text)
Creates a frame based user interface window
that displays the parameter string text in its title bar caption.
Usually the programmer extends the JFrame class to add extra
capability. The original JFrame constructor can then be called by
the line
super("Put your favorite titlebar caption here.");
This line must be the first line in the body of the constructor.
-
JFrame void setContentPane(Panel panel)
Set panel as the pane that shows the content of the
user interface. The "content" of a window is the panel
that displays all the controls that were
added to the panel.
-
JFrame void setSize(int width, int height)
Set the width and height of the user interface window.
-
JFrame void show()
Make the user interface visible.
 
JLabel
-
public JLabel(String text)
Creates a label control that displays the parameter string text.
 
JTextField
-
public JTextField(int fieldSize)
Creates a text field control that can accept
or display approximately fieldSize letters.
-
public String getText()
Get the current text in the TextField object and
return it as a string.
-
public void setText(String text)
Set the text in the TextField object
to the parameter string text.
 
JPanel
-
public JButton(String text)
Creates a panel to which buttons, labels, text fields and other controls can be added.
Controls are displayed on the panel in FlowLayout style.
The panel must be specified as the content pane of the frame to make the
controls on the panel visible and usable.
-
private void add(Component control)
Adds the control to the panel.