嗨我想让我使用3 JButtons的Java桌面应用程序。我想,当我点击任何JButton它应该改变该按钮的颜色,如果我点击任何其他JButton然后以前点击按钮应该像以前和最近点击按钮改变它的颜色,直到另一个JButton被点击如何使用JButton?
怎么可以我做到这一点
这里是我的按钮代码
b1 = new JButton("Ok");
b1.setBounds(800, 725, 100, 40);
b1.setForeground(Color.BLACK);
c.add(b1);
b2 = new JButton("Print");
b2.setBounds(925, 725, 100, 40);
b2.setForeground(Color.BLACK);
c.add(b2);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
b1.setBackground(Color.BLUE);
JOptionPane.showMessageDialog(frame,"Welcome to allhabad High Court");
}
});
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
b2.setBackground(Color.BLUE);
JOptionPane.showMessageDialog(frame,"Welcome to allhabad High Court");
}
});