Olá pessoal!!!
Não estou conseguindo fazer com que meus botoes sejam “ouvidos”
verja meu codigo abaixo…
import java.awt.Font;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ContadorGinastica {
private JFrame tela;
private JLabel labelTexto;
/**
* @throws InterruptedException
*/
private void Formulario() throws InterruptedException {
labelTexto = new JLabel ("teste");
JPanel painel = new JPanel();
painel.add(labelTexto);
tela = new JFrame("Contador Ginastica");
tela.add(painel);
JButton botaoA = new JButton("5");
JButton botaoB = new JButton("7");
JButton botaoC = new JButton("10");
JButton botaoD = new JButton("15");
JButton botaoE = new JButton("30");
botaoA.setActionCommand("5");
botaoB.setActionCommand("7");
botaoC.setActionCommand("10");
botaoD.setActionCommand("15");
botaoE.setActionCommand("30");
botaoA.addActionListener((ActionListener) this);
botaoB.addActionListener((ActionListener) this);
botaoC.addActionListener((ActionListener) this);
botaoD.addActionListener((ActionListener) this);
botaoE.addActionListener((ActionListener) this);
painel.add(botaoA);
painel.add(botaoB);
painel.add(botaoC);
painel.add(botaoD);
painel.add(botaoE);
painel.setSize(50, 100);
tela.add(painel);
tela.pack();
tela.setSize(800, 640);
tela.setVisible(true);
tela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Font fonte = new Font("Arial", Font.BOLD, 180);
labelTexto.setFont(fonte);
labelTexto.setHorizontalAlignment(JLabel.CENTER);
labelTexto.setVerticalAlignment(JLabel.BOTTOM);
tela.setLocation(80, 80);
int quantidade = 10;
for (int i = 0; i <= quantidade; i++) {
labelTexto.setText(i+"");
// tela.add(labelTexto);
Thread.sleep(1000);
}
public void (actionPerformed(ActionEvent e)) {
if ("5".equals(e.getActionCommand())) {
/// aqui vou implementar o codigo
}
}
}
public static void main(String[] args) throws InterruptedException {
new ContadorGinastica().Formulario();
}
}