Duvidas sobre Threads

Tenho alguns problemas com o funcionamento da classe paint em threads.
Primeiro, eu tenho um aplicativo que pinta em um painel um desenho, por exemplo em circulo, depois eu quero que um thread imprima outro desenho no mesmo painel, sendo esse segundo desenho executado por outro programa (arquivo) de pintura (chamado pelo thread dentro da classe run).
Assim, a duvida é o seguinte: Como eu faço para que o programa principal (no qual eu desenhei o primeiro círculo) imprima o segundo desenho executado pelo thread? Tem alguma instrução ou linha de comando que possibilita isso? Porque eu não estou conseguindo imprimir o segundo desenho sobre o outro. Já tentei adicionar um botão ao invés de desenhar a segunda figura, mas ele só aparece quando eu dou um click com o mouse no suposto lugar que deveria aparecer o botão.

Valeu.

Felix

Oi

Berlock, seguinte, nao tem comando pra isso nao… Mas vc pode fazer sim… é só tomar cuidado pra thread nao criar instancia nova do objeto ao inves de usar a que ja existe… Sobre o fato de nao aparecer antes de um clique, use o método show() que da certinho.

T+

Aproveitando a deixa…

Qual a real diferença entre o método setVisible() de um JFrame e o método show()???

Como usar o método show() no lugar do metodo setVisible()???

E porque o método setVisible() não pode ser chamado no construtor de uma classe?

Se não for pedir muito, poderia me esclarecer isso?

Tentando responder suas perguntas…

O método show() foi deprecado, ou seja, seu uso não é mais recomendado pela Sun. Isso ocorre quando são encontrados bugs no código ou, como neste caso, quando há maneiras melhores ou mais elegantes de fazer. No final das contas, use o setVisible() em vez do show(). Dá no mesmo, mas o setVisible() é mais elegante.

Em vez de chamar show(), chame setVisible(true). E só.

Sempre usei setVisible() no construtor da classe sem nenhum problema. Aliás, há 4 comandos que sempre chamo no final dos meus construtores de janelas:

// garanto que a JVM feche quando clico no X da janela
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

// ajusto o tamanho da janela
setSize(width, height);

// a posiciono no meio da tela
setLocation((screenWidth - width)/2, (screenHeight - height)/2);

// faço a janela ficar visível
setVisible(true);

Que erro que está acontecendo? Poste seu código e as mensagens de erro geradas.

Bem, primeiramente…
valeu pela resposta.

Bem, agora entendi porque o método show() não funciona corretamente no tiger 5.0 (pelo menos não consegui fazer funcionar).

Quanto ao setVisible(true) não sei se é coisa do Tiger (JDK 5.0), mas já aconteceu várias vezes comigo e com outros (inclusive ajudei um rapaz no fórum com o mesmo problema), quando chamado o método setVisible() dentro do construtor, a JVM exibe apenas o Frame e não exibes os outros componentes. Todo componentes Swing. Vou postar meu código e dá uma olhada nisso.

[code]
import java.awt.;
import javax.swing.
;

public class Clientes extends JFrame {

JLabel JLNome = new JLabel();
JLabel JLCodCli = new JLabel();
JLabel JLCPF = new JLabel();
JLabel JLRG = new JLabel();
JLabel JLEnd = new JLabel();
JLabel JLBairro = new JLabel();
JLabel JLCidade = new JLabel();
JLabel JLUF = new JLabel();
JLabel JLCep = new JLabel();
JLabel JLTel = new JLabel();
JLabel JLCel = new JLabel();
JLabel JLNasc = new JLabel();
JLabel JLObs = new JLabel();
JTextArea TAObs = new JTextArea();
JTextField tfCod = new JTextField();
JTextField tfCPF = new JTextField();
JTextField tfRG = new JTextField();
JTextField tfNome = new JTextField();
JTextField tfNasc = new JTextField();
JTextField tfEnd = new JTextField();
JTextField tfBairro = new JTextField();
JTextField tfCidade = new JTextField();
JTextField tfUF = new JTextField();
JTextField tfCEP = new JTextField();
JTextField tfCelular = new JTextField();
JTextField tfTel = new JTextField();
JButton JBNovo = new JButton();
JButton JBEditar = new JButton();
JButton JBExcluir = new JButton();
JButton JBConfirmar = new JButton();
JButton JBCancelar = new JButton();
JButton JBFechar = new JButton();

public Clientes() {
try {
iniciar();
this.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}
private void iniciar() throws Exception {
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(510,300);
this.setResizable(false);
this.setTitle("Cadastro de Clientes");
JLCodCli.setRequestFocusEnabled(false);
JLCodCli.setText("Código:");
JLCodCli.setBounds(new Rectangle(11, 18, 38, 15));
JLCPF.setRequestFocusEnabled(false);
JLCPF.setText("CPF:");
JLCPF.setBounds(new Rectangle(137, 18, 23, 15));
JLRG.setRequestFocusEnabled(false);
JLRG.setText("RG:");
JLRG.setBounds(new Rectangle(327, 18, 22, 15));
JLNome.setRequestFocusEnabled(false);
JLNome.setText("Nome:");
JLNome.setBounds(new Rectangle(11, 47, 34, 15));
JLEnd.setRequestFocusEnabled(false);
JLEnd.setText("Endereço:");
JLEnd.setBounds(new Rectangle(11, 75, 52, 15));
JLBairro.setRequestFocusEnabled(false);
JLBairro.setText("Bairro:");
JLBairro.setBounds(new Rectangle(11, 105, 34, 15));
JLCidade.setRequestFocusEnabled(false);
JLCidade.setText("Cidade:");
JLCidade.setBounds(new Rectangle(205, 105, 42, 15));
JLUF.setRequestFocusEnabled(false);
JLUF.setText("UF:");
JLUF.setBounds(new Rectangle(429, 105, 17, 15));
JLCep.setRequestFocusEnabled(false);
JLCep.setText("CEP:");
JLCep.setBounds(new Rectangle(11, 134, 34, 15));
JLTel.setRequestFocusEnabled(false);
JLTel.setText("Telefone:");
JLTel.setBounds(new Rectangle(181, 134, 47, 15));
JLCel.setRequestFocusEnabled(false);
JLCel.setText("Celular:");
JLCel.setBounds(new Rectangle(342, 134, 36, 15));
JLNasc.setRequestFocusEnabled(false);
JLNasc.setText("Data de Nascimento:");
JLNasc.setBounds(new Rectangle(307, 47, 100, 15));
JLObs.setRequestFocusEnabled(false);
JLObs.setText("Observações:");
JLObs.setBounds(new Rectangle(11, 160, 81, 15));
TAObs.setRequestFocusEnabled(true);
TAObs.setSelectedTextColor(Color.black);
TAObs.setSelectionEnd(10);
TAObs.setText("");
TAObs.setRows(0);
TAObs.setBounds(new Rectangle(11, 177, 204, 56));
tfCod.setNextFocusableComponent(tfCPF);
tfCod.setText("");
tfCod.setBounds(new Rectangle(62, 15, 70, 21));
tfCPF.setNextFocusableComponent(tfRG);
tfCPF.setText("");
tfCPF.setBounds(new Rectangle(162, 15, 157, 21));
tfRG.setNextFocusableComponent(tfNome);
tfRG.setText("");
tfRG.setBounds(new Rectangle(344, 15, 142, 21));
tfNome.setNextFocusableComponent(tfNasc);
tfNome.setText("");
tfNome.setBounds(new Rectangle(63, 44, 232, 21));
tfNasc.setNextFocusableComponent(tfEnd);
tfNasc.setText("");
tfNasc.setBounds(new Rectangle(406, 44, 80, 21));
tfEnd.setNextFocusableComponent(tfBairro);
tfEnd.setText("");
tfEnd.setBounds(new Rectangle(63, 72, 423, 21));
tfBairro.setNextFocusableComponent(tfCidade);
tfBairro.setText("");
tfBairro.setBounds(new Rectangle(63, 102, 134, 21));
tfCidade.setNextFocusableComponent(tfUF);
tfCidade.setText("");
tfCidade.setBounds(new Rectangle(244, 102, 179, 21));
tfUF.setNextFocusableComponent(tfCEP);
tfUF.setText("");
tfUF.setBounds(new Rectangle(449, 102, 37, 21));
tfCEP.setNextFocusableComponent(tfTel);
tfCEP.setText("");
tfCEP.setBounds(new Rectangle(63, 131, 111, 21));
tfCelular.setNextFocusableComponent(JBConfirmar);
tfCelular.setText("");
tfCelular.setBounds(new Rectangle(381, 130, 105, 22));
tfTel.setNextFocusableComponent(tfCelular);
tfTel.setText("");
tfTel.setBounds(new Rectangle(230, 131, 105, 21));
JBNovo.setBounds(new Rectangle(221, 178, 83, 25));
JBNovo.setNextFocusableComponent(JBEditar);
JBNovo.setText("Novo");
JBEditar.setBounds(new Rectangle(312, 178, 83, 25));
JBEditar.setNextFocusableComponent(JBExcluir);
JBEditar.setText("Editar");
JBExcluir.setBounds(new Rectangle(403, 178, 83, 25));
JBExcluir.setNextFocusableComponent(JBConfirmar);
JBExcluir.setText("Excluir");
JBConfirmar.setBounds(new Rectangle(221, 209, 83, 25));
JBConfirmar.setNextFocusableComponent(JBCancelar);
JBConfirmar.setText("Confirmar");
JBCancelar.setBounds(new Rectangle(312, 209, 83, 25));
JBCancelar.setNextFocusableComponent(JBFechar);
JBCancelar.setText("Cancelar");
JBFechar.setBounds(new Rectangle(403, 209, 83, 25));
JBFechar.setNextFocusableComponent(tfCod);
JBFechar.setText("Fechar");
this.getContentPane().add(TAObs, null);
this.getContentPane().add(tfCPF, null);
this.getContentPane().add(JLCodCli, null);
this.getContentPane().add(JLNasc, null);
this.getContentPane().add(tfNasc, null);
this.getContentPane().add(JLNome, null);
this.getContentPane().add(tfRG, null);
this.getContentPane().add(JLRG, null);
this.getContentPane().add(JLEnd, null);
this.getContentPane().add(tfBairro, null);
this.getContentPane().add(JLBairro, null);
this.getContentPane().add(JLCidade, null);
this.getContentPane().add(tfCidade, null);
this.getContentPane().add(tfUF, null);
this.getContentPane().add(JLUF, null);
this.getContentPane().add(JLCPF, null);
this.getContentPane().add(JLCep, null);
this.getContentPane().add(tfCEP, null);
this.getContentPane().add(tfCelular, null);
this.getContentPane().add(tfNome, null);
this.getContentPane().add(tfEnd, null);
this.getContentPane().add(tfTel, null);
this.getContentPane().add(JLTel, null);
this.getContentPane().add(tfCod, null);
this.getContentPane().add(JBNovo, null);
this.getContentPane().add(JBExcluir, null);
this.getContentPane().add(JLObs, null);
this.getContentPane().add(JBFechar, null);
this.getContentPane().add(JBConfirmar, null);
this.getContentPane().add(JLCel, null);
this.getContentPane().add(JBCancelar, null);
this.getContentPane().add(JBEditar, null);
}

public static void main(String args[]){
	Clientes cli = new Clientes();
}

}[/code]

Aliás, nesse caso compilando com tiger, ele exibe vários warns sobre métodos “deprecated”…

E pede pra eu compilar usando javac Clientes.java -Xlint

Alguém sabe o que é isso?

Olha, eu fiz novos testes com o setVisible(true) e deu certo…

Não sei o que havia acontecido mas agora deu certo.

Porém nessa classe aciam, eu continuo tendo que compilar com

javac Clientes.java -Xlint

para que serve esse -Xlint :?:
É só no tiger que ele é usado?