Prezado colegas, estou com problemas para enviar dados de uma Tela JDialog (Modal) para outra Tela JDialog (Modal). Percebi q muitos tem a mesma dificuldade por esse motivo peço a contribuição de todos para tornar esse post a referencia em JDialog. Conto com a ajuda de todos! O problema está descrito abaixo:
Tenho dois JDialog, os dois são setModal(true) estou tentando passar os dados da Tela Funcionario para a Tela Setor através de um botão, mas... a Tela Setor não recebe o respectivo dado enviado. Segue o fonte agradeço sua ajuda. Preciso que a Tela Setor recebe os dados enviados para ela!
[size=18]
TelaFuncionario[/size]
package br.com.sisportaria.visao;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TelaFuncionario extends javax.swing.JDialog {
private JTextField txtNomeFuncionario;
private JButton bntEnviaDados;
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TelaFuncionario inst = new TelaFuncionario();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public TelaFuncionario() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
this.setTitle("Tela Funcionario");
this.setModal(true);
{
txtNomeFuncionario = new JTextField();
getContentPane().add(txtNomeFuncionario);
txtNomeFuncionario.setBounds(13, 6, 178, 40);
txtNomeFuncionario.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//chama método para enviar mensagem
enviar();
}
});
}
{
bntEnviaDados = new JButton();
getContentPane().add(bntEnviaDados);
bntEnviaDados.setText("Envia Dados");
bntEnviaDados.setBounds(13, 52, 178, 43);
bntEnviaDados.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
enviar();
}
});
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
//Metodo para enviar os dados para a TELA SETOR
public void enviar(){
String nome = txtNomeFuncionario.getText();
TelaSetor.main(null);
TelaSetor.receber(nome);
}
}
[size=18]Tela Setor[/size]
package br.com.sisportaria.visao;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TelaSetor extends javax.swing.JDialog {
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}
private static JTextField txtNomeSetor;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
TelaSetor inst = new TelaSetor();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
return;
}
public TelaSetor() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
this.setTitle("Tela Setor");
this.setModal(true);
{
txtNomeSetor = new JTextField();
getContentPane().add(txtNomeSetor);
txtNomeSetor.setBounds(5, 12, 244, 34);
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void receber(String nome) {
txtNomeSetor.setText(nome);
}
}
Aguardo sua ajuda parceiro, falta somente isso para que eu possa terminar uma aplicação
grato!