M
man4*.*
I've got 9 buttons that are presented with one icon, and when I press that
button I want to change it, but
I've complicated a little bit... (hope, you'll understand what I need, if
not, I'll send whole code)
button initialization:
JButton[] button = new JButton[9];
{for ( int i = 0; i < 9; i++)
button = new JButton(paint[0]);}
putted 9 ActionListeners:
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
for ( int i = 0; i < 9; i++)
cp.add(button);
for ( int i = 0; i < 9; i++)
button.addActionListener(new AL());
AL is a class that implements ActionListener,
also I've got 2 icons:
static Icon[] paint = {
new ImageIcon(path + "icon1.gif"),
new ImageIcon(path + "icon2.gif")};
i want each time I press a button to change from icon1 to icon2.
in actionPerformed method I followed yours advices and put
Object buttonSource = e.getSource();
but since my buttons are Array obj. I can't say:
buttonSource.setIcon(paint[1]);
button I want to change it, but
I've complicated a little bit... (hope, you'll understand what I need, if
not, I'll send whole code)
button initialization:
JButton[] button = new JButton[9];
{for ( int i = 0; i < 9; i++)
button = new JButton(paint[0]);}
putted 9 ActionListeners:
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
for ( int i = 0; i < 9; i++)
cp.add(button);
for ( int i = 0; i < 9; i++)
button.addActionListener(new AL());
AL is a class that implements ActionListener,
also I've got 2 icons:
static Icon[] paint = {
new ImageIcon(path + "icon1.gif"),
new ImageIcon(path + "icon2.gif")};
i want each time I press a button to change from icon1 to icon2.
in actionPerformed method I followed yours advices and put
Object buttonSource = e.getSource();
but since my buttons are Array obj. I can't say:
buttonSource.setIcon(paint[1]);