how to access the jbutton that is in the other class?

-4

I have jbutton in the main class, so I put it as public to be able to access from another class. but you are not doing the right thing

public class piscarbt{

 tela t = new tela();
public void piscar(){

    t.jButton1.setBackground(Color.white);

}


}

I made this code and the color of jbutton does not change, remembering that in the main class it is public javax.swing.JButton jButton1;

I do not know what to do because it is already public

    
asked by anonymous 14.06.2016 / 07:23

1 answer

0

Make a button get in the main class:

public JButton getBotao() {
return seuBotao;
}

In the other instance class a the main:

ClassePrincipal controle = new ClassePrincipal():

And your code will look like this:

JButton botao = controle.getBotao();
t.botao.setBackground(Color.white);

Try and give feedback

    
14.06.2016 / 08:12