Mrs. Howe's GUI-Cookbook for Java
If
you choose not to use a pre-set Layout and use the “null” option.
You must use methods,
.setSize(
# , # ) and
.setLocation(
# , # )
before
you add these objects to the window (Pane.)
Constructors:
JButton( “String caption”);
JButton(“picturefilename”);
JButton(“String caption”, “picturefilename”);
Methods
.setText (“String caption”);
.setIcon(“picturefilename”);
.requestFocus();
JCheckBox
Constructors:
JCheckBox( “String text”,true
or false);
JCheckBox(“picturefilename”,true
or false);
JCheckBox(“String text”, “picturefilename”,true
or false);
Methods
.isSelected();
.setSelected(true or false);
.setText(“String text”);
.setIcon(“picturefilename”);
JComboBox
Constructors:
JComboBox( arrayname );
Methods
.getSelectedIndex()
.getSelectedItem();
.setSelectedIndex(int);
.setSelectedItem(“String text”);
JLabel
Constructors:
JLabel( “String Caption”
);
JLabel( “picturefilename”
);
Methods
.setText(“string text”)
.setIcon(“picturefilename”);
JRadioButton
Constructors:
JRadioButton( “String text”);
JRadioButton( “String text”true
false”);
JRadioButton( “picturefilename”);
JRadioButton( “picturefilename”,true
false);
JRadioButton( “String
text”,“picturefilename”,true false);
Methods
.isSelected();
.setSelected(true or false);
.setText(“String text”);
.setIcon(“picturefilename”);
JSlider
import javax.swing.event.*;
Constructors:
JSlider( SwingConstants.VERTICAL, min, max, value now);
Methods
.getInverted(true false);
.getSelectedItem();
.setMajorTickSpacing(int);
.setMinorTickSpacing(int);
.getValue();
.set PaintLabels(true false);
.set PaintTicks(true false);
.setValue();
JTextArea
Constructors:
JTextArea( “String text”);
JTextArea(rows, cols);
JText(“String text”, rows, cols);
Methods
.setEditable(true false);
.getCaretPosition();
.append( “String text”);
.insert(
“String text”,pos);
.setText(
“String text”);
.setBackground(
Color.color);
.setForeground( Color.color);
.setFont(“fontname”);
.setText(
“String text”);
.requestFocus();
.getText();
.selectAll();
.setCaretPosition(pos);
.moveCaretPosition(pos);
JTextField
Constructors:
JTextArea( “String text”);
JTextArea( cols);
JText(“String text”, cols);
Methods
.setEditable(true false);
.setText(
“String text”);
.setBackground(
Color.color);
.setForeground( Color.color);
.setFont(“fontname”);
.setText(
“String text”);
.requestFocus();
.getText();
.selectAll();
.setCaretPosition(pos);
.moveCaretPosition(pos);
JToggleButton (Like
command button--changes appearance)
Constructors:
JToggleButton( “String
text”true false”);
JToggleButton( “picturefilename”);
JToggleButton( “picturefilename”,true
false);
JToggleButton( “String
text”,“picturefilename”,true false);
Methods
.isSelected();
.setSelected(true or false);
.setText(“String text”);
.setIcon(“picturefilename”);
************************
ACTION CODE
************************
For Buttons....using anonymous inner class. (Similar to click event)
import java.awt.event.*; remember this header
nameofbutton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
CODE YOU WANT TO HAVE HAPPEN ON CLICK
}
});
************************
MOUSE CODE
************************