GUI Components |
The following methods can be applied to any Component:
void setFont (Font f) 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:
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 ( ) void addItem (Object item)
To find out which item was selected, use:
String getSelectedItem ( )To find out the index of the item that was selected, use:
int getSelectedIndex ( )
ActionListener
void addActionListener (ItemListener il)
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 |