getContentPane()setSize, setVisible, setLocation....BorderLayout, FlowLayout, GridLayoutnew GridLayout(0, 5), new GridLayout(5,0) mean?add(component), remove(index), add(component, index)JPanel(), JPanel(layout)getText, setTextsetBackgroundpublic class XXX implements ActionListener {
.............
............
public void actionPerformed(ActionEvent e) {
// your codes
}
}
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// your codes
}
});
ComponentJButton button = (JButton)e.getSource();
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1) {
// do something
} else if( e.getSource() == button2) {
// do something
} ......
.....
}
String) of the sourcebutton.setActionCommand(String s) set the action command of the button to s.
If you don't set it, the default value is the text on the button.public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand();
if(action.equals(string1)) {
// do something
} else if (action.equals(string2)) {
// do something
} .....
.....