Tipo, preciso clicar no no botao resete e mudar a img no button1… segue meu codigo onde nao entendi pq nao funciona:
[code]import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
class teste implements ActionListener {
public JButton button1, resete;
public JLabel titu;
public teste() {
}
public void aparencia(){
String iconex = “iconjogo.gif”;
ImageIcon icone1 = new ImageIcon(iconex);
JFrame frame = new JFrame();
Border empty;
empty = BorderFactory.createEmptyBorder();
Container cons = frame.getContentPane();
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
frame.setLayout(layout);
//c.insets = new Insets(5,5,5,5);
c.anchor = GridBagConstraints.CENTER;
JButton resete = new JButton("Reset");
c.weightx=1.0;
c.gridwidth = 4;
c.gridx=0;
c.gridy=3;
c.fill = GridBagConstraints.BOTH;
cons.add(resete, c);
JButton botao = new JButton("OK");
c.gridwidth = 1;
c.gridx=0;
c.gridy=2;
c.fill = GridBagConstraints.NONE;
cons.add(botao, c);
JButton botao2 = new JButton("Novo");
c.fill = GridBagConstraints.NONE;
c.gridwidth = 1;
c.gridx=3;
c.gridy=2;
cons.add(botao2, c);
//icons
JButton button1 = new JButton();
c.fill = GridBagConstraints.NONE;
c.gridx=0;
c.gridy=0;
button1.setIcon(icone1);
button1.setBorder(empty);
cons.add(button1, c);
//
JButton button2 = new JButton();
c.gridx=1;
c.gridy=0;
button2.setIcon(icone1);
button2.setBorder(empty);
button2.setName("button2");
//addCompForBorder(button2, "empty border", simpleBorders);
cons.add(button2, c);
//
frame.setSize(600,600);
frame.setVisible(true);
resete.addActionListener(this);
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public void actionPerformed(ActionEvent e){
button1.setIcon(new ImageIcon("iconcirculo.gif"));
}
}
public class corpo {
public static void main(String args[]) {
teste a = new teste();
a.aparencia();
}
}
[/code]
Se possivel uma soluçao e explicaçao pq o meu nao funfa