COR Jframe

10 respostas
thibalta

Sou novato em java e preciso criar uma tela que a cada select ela dependendo do resultado ela muda de cor…

Tentei usar: this.getContentPane().setBackground(Color.ORANGE);
this.setVisible(true);

Mas ele da um erro : non-static variable this cannot be referenced from a static context

Como posso resolver esse problema???

Obrigado

10 Respostas

P

Esse seu this é uma classe?

ViniGodoy

Dê esse comando num método não estático.

thibalta

Mas ele está dentro do

public static void main(String args[]) {

}

ele fica verificando e era pra mudar a cor da tela se entrar no IF…

Como poderia fazer??

thibalta

Mas ele está dentro do

public static void main(String args[]) {

}

ele fica verificando e era pra mudar a cor da tela se entrar no IF…

Como poderia fazer??

ViniGodoy

Se vc criou o frame assim:

JFrame meuFrame = new JFrame();

Deveria ter chamado assim:

meuFrame.getContentPane().setColor(Color.ORANGE);

E não com this.

thibalta

ViniGodoy:
Se vc criou o frame assim:

JFrame meuFrame = new JFrame();

Deveria ter chamado assim:

meuFrame.getContentPane().setColor(Color.ORANGE);

E não com this.

Talves eu não esteja conseguindo explicar…

tenho um frame e nele mesmo estou tentando mudar a cor dele…
Mas para isso eu faço um select no banco de dados…

Segue o codigo… :

public static void main(String args[]) {

@Override
        public void run() {
            new InicioSeparacaoView().setVisible(true);
        }
    });

    try {

        verifica();

    } catch (DbfDatabaseException ex) {
        Logger.getLogger(InicioSeparacaoView.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public static void verifica() throws DbfDatabaseException {

long i = 0;
    boolean resposta = true;

    while (true) {
        i++;

        resposta = RomaneioDBFModel.verificaRomaneio();

        if (resposta == true) {
            System.out.println("Existe Romaneios I = " + i);

            if (i == 5) {
              //  getContentPane().setBackground(Color.ORANGE);   <-- ERRO
            } else if (i == 10) {
               // getContentPane().setBackground(Color.RED);  <-- ERRO
            } 


        } else {
            i = 0;
            System.out.println("NAO Existe Romaneios I = " + i);
            //FORM VOLTANDO AO NORMAL
        }

        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(InicioSeparacaoView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
ViniGodoy

Usa a tag code, senão fica impossível ler seu código:

ViniGodoy

Usa a tag code, senão fica impossível ler seu código:

thibalta
public static void main(String args[]) {


@Override
public void run() {
new InicioSeparacaoView().setVisible(true);
}
});

try {

verifica();

} catch (DbfDatabaseException ex) {
Logger.getLogger(InicioSeparacaoView.class.getName()).log(Level.SEVERE, null, ex);
}
}

public static void verifica() throws DbfDatabaseException {

long i = 0;
boolean resposta = true;

while (true) {
i++;

resposta = RomaneioDBFModel.verificaRomaneio();

if (resposta == true) {
System.out.println("Existe Romaneios I = " + i);

if (i == 5) {
// getContentPane().setBackground(Color.ORANGE); <-- ERRO
} else if (i == 10) {
// getContentPane().setBackground(Color.RED); <-- ERRO
}


} else {
i = 0;
System.out.println("NAO Existe Romaneios I = " + i);
//FORM VOLTANDO AO NORMAL
}

try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(InicioSeparacaoView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
ViniGodoy

Cadê a indentação do código?!?!?

Criado 19 de março de 2013
Ultima resposta 20 de mar. de 2013
Respostas 10
Participantes 3