Dúvidas na chamada de uma tela, para passar parametro

2 respostas
E

Bom dia Galera, estou com a seguinte dúvida, tenho uma tela de reservas que chama outra tela de consultar cliente. Preciso que depois de efetuar a consulta a tela consultar cliente devolva par a tela reserva o código do cliente. Segue o código:

Tela Reserva chamando a tela consultar cliente

consultar.addActionListener(new ActionListener(){
				    public void actionPerformed(ActionEvent e){
				    new CopyOfBuscaCliente();
				    }
				 });

Tela consultar

package Buscas;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Query;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;

import Beans.cliente_locadora;
import Beans.reserva_locadora;
import Conexao.JpaUtil;


	@SuppressWarnings("serial")
	public class CopyOfBuscaCliente extends JFrame{ 

		
		private JLabel rotulo4_1;
		private JLabel rotulo5_1;
		private JLabel rotulo3_1;
		JLabel rotulo1, rotulo3, rotulo4, rotulo5;
	   	JButton  consultar;		   	
	    JTextField nome_cli; 
		
		
		private static EntityManagerFactory f = null;

		public CopyOfBuscaCliente(EntityManagerFactory f1){
		
			super("LOCADORA YASMIN"); 
			getContentPane().setForeground(new Color(30, 144, 255));
			getContentPane().setLayout(null);
			Container tela = getContentPane(); 
			setLayout(null);
			
			
			f=f1;
			
			
			tela.setBackground(new Color(181,181,181));
		
			rotulo1 = new JLabel ("Nome:");
	   		rotulo1.setBounds(10, 50, 110, 30);
	   		rotulo3 = new JLabel ("");
	   		rotulo3.setBounds(141, 103, 150, 30);
	   		rotulo4 = new JLabel ("");
	   		rotulo4.setBounds(141, 175, 110, 30);
	   		rotulo5 = new JLabel ("");
	   		rotulo5.setBounds(141, 139, 110, 30);
	   		
	   		
	   		nome_cli = new JTextField (5);
	   		nome_cli.setBounds(67, 53, 142, 25);
	   		
	   		
	   		consultar = new JButton ("Consultar");
	   		consultar.setBounds(235, 54, 90, 23);
	   		
	   		
	   		
	   		
	   		
	   		
	   			   		
	   		tela.add(rotulo1);
	   		tela.add(rotulo3);
	   		tela.add(rotulo4);
	   		tela.add(rotulo5);
	   		
	   		
	   		tela.add(nome_cli);
	   		
	   		
	   		
	   		tela.add(consultar);

//	   	 DESABILITAM-SE ALGUNS BOTÕES 
		
	   	
			consultar.setEnabled(true);

			setSize(360, 309);
			setVisible(true);
			setLocationRelativeTo(null);// CENTRALIZA A JANELA 

	   	

//	 Ações Botões
	
		
			
			consultar.addActionListener(
					new ActionListener(){
						public void actionPerformed(final ActionEvent e){

							

						if(!nome_cli.getText().trim().equals("")){
								
						    

							cliente_locadora d = new cliente_locadora();
							String nome=String.valueOf(nome_cli.getText());
							
												 
							
							//List<cliente_locadora> cliente = new ArrayList<cliente_locadora>();
							List<cliente_locadora> listClientes = new ArrayList<cliente_locadora>();   
					      
						
							StringBuilder jpql = new StringBuilder("SELECT c FROM cliente_locadora c WHERE c.nome_cli = :nome");  
						 


							EntityManager em = f.createEntityManager();
							 
							Query q = em.createQuery(jpql.toString());   
							q.setParameter("nome", nome);   
							//List<cliente_locadora> resultados = q.getResultList(); 
							listClientes = q.getResultList();
							
							if(listClientes.isEmpty()){   
								JOptionPane.showMessageDialog(null, "Cliente não encontrado!");
								}  
							
							else{ 
								
								
								   //acessando os valores da lista com foreach   
								   for(cliente_locadora cliente : listClientes){     
								                          rotulo3.setText(String.valueOf(cliente.getCod_cli()));     
								                          rotulo4.setText(cliente.getFone_comercial());     
								                          rotulo5.setText(cliente.getCelular());   
								                         //para o seu caso só deve ser preenchido uma única vez certo? Se sim, deixe o break.   
								                          break;     
								  }   

								
								
								
							}

							
							
												
							
								
							
							}
							else {
								JOptionPane.showMessageDialog(null, "Cliente não encontrado!");
								
							
    						
							}
						   
					//	}
						}
						public void focusGained(final FocusEvent arg0) {
							// TODO Auto-generated method stub
							
						}

					} // fim do new ActionListener
			);

			rotulo3_1 = new JLabel();
			rotulo3_1.setText("Código do cliente:");
			rotulo3_1.setBounds(10, 103, 150, 30);
			getContentPane().add(rotulo3_1);

			rotulo5_1 = new JLabel();
			rotulo5_1.setText("Fone:");
			rotulo5_1.setBounds(10, 139, 44, 30);
			getContentPane().add(rotulo5_1);

			rotulo4_1 = new JLabel();
			rotulo4_1.setText("Celular:");
			rotulo4_1.setBounds(10, 175, 110, 30);
			getContentPane().add(rotulo4_1);

			
			
			
			
		
			
				
		
		}
			
	
		}

Agradeço a ajuda.

2 Respostas

ViniGodoy

Ou. Veja um exemplo:
http://www.guj.com.br/posts/list/55710.java#292687

E

obrigado vini

Criado 24 de novembro de 2009
Ultima resposta 24 de nov. de 2009
Respostas 2
Participantes 2