Hello, I'm going to put the important part of the code here and then I'll explain what I want to do.
Main:
public static JButton sala;
public static int contagemTurmas = 0;
botaoSalvar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
gerarTableTurma(turmaName.getText(), contagemTurmas, panelCriados);
}
});
sala.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println(sala.getText());
turmaName.setText(sala.getText());
}
});
Part that generates the various buttons from the vairavel sala
public static void gerarTableTurma(String turma, int posicao, JPanel panel)
{
sala = new JButton(turma); //turma = JTextArea
sala.setFont(new Font("Tahoma", Font.PLAIN, 30));
sala.setBounds(10, 11 + (contagemTurmas * 43), 792, 32);
panel.add(sala);
contagemTurmas ++;
panel.repaint();
}
I would like to take the event of a button, but I do not know the button, so I created several buttons in the same variable, so regardless of the button clicked, I would know which one would be just testing the variable sala
, like me Can I do this ?? since when I click on one of the buttons nothing happens