hi there i am trying to make a matching memory game which i use JToggleButton. the main thing is when i press to button it must show a picture and i must find the other same picture. so the problem is when i create a button without any icons i cant use other other methods for example .setRollOverIcon()
, .setPressedIcon()
etc. so i appreciated if you can help me . and thanks anyway :)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonsIcon extends JFrame {
private static final long serialVersionUID = 1L;
private ImageIcon errorIcon = (ImageIcon) UIManager.getIcon("OptionPane.errorIcon");
private ImageIcon infoIcon = (ImageIcon) UIManager.getIcon("OptionPane.informationIcon");
private ImageIcon warnIcon = (ImageIcon) UIManager.getIcon("OptionPane.warningIcon");
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ButtonsIcon t = new ButtonsIcon();
}
});
}
public ButtonsIcon() {
setLayout(new GridLayout(1, 1, 4, 4));
final JToggleButton toggleButton = new JToggleButton();
//toggleButton.setIcon((errorIcon));
toggleButton.setRolloverIcon((infoIcon));
toggleButton.setPressedIcon(warnIcon);
toggleButton.setDisabledIcon(warnIcon);
toggleButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (toggleButton.isSelected()) {
} else {
}
}
});
add(toggleButton);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
}