我想创建一个Java桌面应用程序,其中我使用了两个按钮。我想在这些按钮上添加悬停效果。我的要求是:当我点击任何一个按钮时,它应该改变其背景颜色。
我该如何实现?
以下是我的代码:
public class Party1Party2 extends JFrame
{
JButton b1;
JButton b2;
Container pane;
public Party1Party2()
{
getContentPane().setBackground(new java.awt.Color(255, 255, 255));
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(frame, "Welcome to allhabad High Court");
}
});
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
JOptionPane.showMessageDialog(frame, "Welcome to allhabad High Court");
}
});
}
}