button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button1.setEnabled(false);
}
});button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button1.setEnabled(true);
}
});
public void actionPerformed(ActionEvent e) {
button1.setEnabled(false);
}
});button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button1.setEnabled(true);
}
});
类似的再设置button2.
ActionListener l = new ActionListener(){
public void actionPerformed(ActionEvent e){
JButton button = (JButton)e.getSource();
for(int i=0;i<12;i++){
if(buttons[i]==button){
buttons[i].setEnabled(false);
}else{
buttons[i].setEnabled(true);
}
}
}
};
JButton buttons = new JButton[12];
for(int i=0;i<12;i++){
buttons[i] = new JButton("");
buttons[i].addActionListener(l);
}