GUI Components |
The following methods can be applied to any Component:
void setFont (Font f) void setFont (String fs) void setForeground (Color c) void setBackground (Color c)
To construct a font use:
new Font (String name, int style, int size)
Find out the font names on the computer in Eclipse as follows:
Be sure that the string you pass in setFont or to create a new font is spelled and capitalized exactly as shown in the list of fonts.
Style can be one of Font.BOLD, Font.ITALIC, Font.PLAIN, or Font.BOLD + Font.ITALIC.
The specific components we have considered:
new JButton (String s)
String getText ( ) void setText (String s)
ActionListener
void addActionListener (ActionListener al)
void actionPerformed (ActionEvent e)
new JComboBox<String> ( ) void addItem (String item)
The <String> must be omitted in the constructor in Java 6 (or below), but included in Java 7 or greater.
To find out which item was selected, use:
Object getSelectedItem ( )
To find out the index of the item that was selected, use:
int getSelectedIndex ( )
ActionListener
void addActionListener (ActionListener al)
void actionPerformed (ActionEvent e)
new JLabel (String s)
new JLabel (String s, int align)
align is one of JLabel.RIGHT, JLabel.LEFT, JLabel.CENTER
void setText (String s)
String getText ( )
no listeners available for JLabels
new JSlider (int orientation, int minimum, int maximum, int initialValue)
orientation is one of JSlider.HORIZONTAL or JSlider.VERTICAL
void setValue (int newVal)
To find out the current value, use:
int getValue ( )
ChangeListener
addChangeListener (ChangeListener al)
void stateChanged (ChangeEvent e)
new JTextField (String s)
void setText (String s)
To find out the value typed, use:
String getText ( )
ActionListener
addActionListener (ActionListener al)
void actionPerformed (ActionEvent e)
GUI Components |