One approach is to do the following: Use the selected state to indicate whether to show or hide the Icon. Use the enabled state to indicate that a pair has been matched. Code outline: /** Handle ItemEvents.
*/ @Override public void itemStateChanged(ItemEvent e) { GameButton gb = (GameButton) e.getItem(); gb.setState(); } /** Remove a and be from play. */ private void retirePair(GameButton a, GameButton b) { a. SetSelected(true); a.
SetEnabled(false); b. SetSelected(true); b. SetEnabled(false); } class GameButton extends JToggleButton { ... public void setState() { if (this.isSelected() ||!this.isEnabled()) { this.
SetIcon(icon); } else { this. SetIcon(hidden); } } }.
Quartaela this is your solution +1 – mKorbel Oct 24 at 19:28 thank for your post I will try to realize this. – quartaela Oct 24 at 19:41.
1) for JToggleButton is better to implement ItemListener 2) here is SSCCE import java.awt. *; import java.awt.event. *; import javax.swing.
*; public class ButtonsIcon extends JFrame { private static final long serialVersionUID = 1L; private Icon errorIcon = UIManager. GetIcon("OptionPane. ErrorIcon"); private Icon infoIcon = UIManager.
GetIcon("OptionPane. InformationIcon"); private Icon warnIcon = 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(2, 2, 4, 4)); JButton button = new JButton(); button. SetBorderPainted(false); button.
SetBorder(null); button. SetFocusable(false); button. SetMargin(new Insets(0, 0, 0, 0)); button.
SetContentAreaFilled(false); button. SetIcon((errorIcon)); button. SetRolloverIcon((infoIcon)); button.
SetPressedIcon(warnIcon); button. SetDisabledIcon(warnIcon); add(button); JButton button1 = new JButton(); button1. SetBorderPainted(false); button1.
SetBorder(null); button1. SetFocusable(false); button1. SetMargin(new Insets(0, 0, 0, 0)); button1.
SetContentAreaFilled(false); button1. SetIcon((errorIcon)); button1. SetRolloverIcon((infoIcon)); button1.
SetPressedIcon(warnIcon); button1. SetDisabledIcon(warnIcon); add(button1); button1. SetEnabled(false); 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); final JToggleButton toggleButton1 = new JToggleButton(); toggleButton1. SetIcon((errorIcon)); toggleButton1.
SetRolloverIcon((infoIcon)); toggleButton1. SetPressedIcon(warnIcon); toggleButton1. SetDisabledIcon(warnIcon); toggleButton1.
AddItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (toggleButton1.isSelected()) { } else { } } }); add(toggleButton1); toggleButton1. SetEnabled(false); setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); pack(); setVisible(true); } }.
Thanks for your post I am working on it. : ) – quartaela Oct 24 at 15:30 I just used toggleButton part for check something bu it doesn't work. I am going to get crazy.
I just use simple toggleButton. SetPressedIcon(icon); and when I press the button there isnt any icons_? – quartaela Oct 24 at 15:53 test if Icon is/isn't null, because null Icon doesn't generated any Error, nothing else :-) – mKorbel Oct 24 at 15:56 2 Oooh, right you are.In fact I vaguely recall having been bitten by the same thing.
I think it was in early versions of the FileBro code. AFAIR it was trashgod that put me onto how to convert the icon to a BufferedImage that could then be used for an ImageIcon - using the Icon. PaintIcon(Component,Graphics,int,int) method.
– Andrew Thompson Oct 24 at 17:22 2 Part of my ongoing struggle to code the to the interface. :-) – trashgod Oct 24 at 19:15.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.