Salvar dados no banco de dados

2 respostas
E
Eu fiz uma aplicaçao que calcula dois numeros e mostra um resultado , tal tudo certinho , e eu fiz um botao que quando clicado nele era pra abrir uma outra janela porem nao ta indo. Alguem pode da uma olhada ?
Button btnResultados = new JButton("Resultados");
        btnResultados.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		new PesquisaBanco();
        	}
        });

a outra janela se chama PesquisaBanco, era pra funcionar nao ?

codigo inteiro:

package View;  
  
import java.awt.BorderLayout;  
import java.awt.EventQueue;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import javax.swing.JLabel;  
import javax.swing.JPanel;  
import javax.swing.JTextField;  
import javax.swing.SwingConstants;  
  
public class somar {  
  
    private JFrame frame;  
    private JTextField txf1;  
    private JTextField txf2;  
    
    JLabel lblresult;  
  
    /** 
     * Launch the application. 
     */  
    public static void main(String[] args) {  
        EventQueue.invokeLater(new Runnable() {  
            public void run() {  
                try {  
                    somar window = new somar();  
                    window.frame.setVisible(true);  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
        });  
    }  
  
    /** 
     * Create the application. 
     */  
    public somar() {  
        initialize();  
    }  
  
    /** 
     * Initialize the contents of the frame. 
     */  
    private void initialize() {  
        frame = new JFrame();  
        frame.setBounds(100, 100, 450, 300);  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        frame.getContentPane().setLayout(null);
          
        JPanel panel = new JPanel();  
        panel.setBounds(0, 0, 432, 255);
        frame.getContentPane().add(panel);  
        panel.setLayout(null);  
          
        JLabel lblnum1 = new JLabel("Valor 1:");  
        lblnum1.setBounds(22, 40, 116, 16);  
        panel.add(lblnum1);  
        
        txf1 = new JTextField();  
        txf1.setBounds(22, 69, 116, 22);  
        panel.add(txf1);  
        txf1.setColumns(10);  
          
        JLabel lblnum2 = new JLabel("Valor 2:");  
        lblnum2.setBounds(299, 40, 131, 16);  
        panel.add(lblnum2);  
          
        txf2 = new JTextField();  
        txf2.setBounds(299, 69, 116, 22);  
        panel.add(txf2);  
        txf2.setColumns(10);  
          
        JButton btncalcular = new JButton("Calcular");  
        btncalcular.setBounds(22, 113, 106, 33);  
        panel.add(btncalcular);
  
        lblresult = new JLabel("");  
        lblresult.setBounds(22, 209, 195, 33);  
        panel.add(lblresult);  
        
        JButton btnlimpar = new JButton("Limpar");
        btnlimpar.setBounds(170, 113, 97, 33);
        btnlimpar.addActionListener(
        new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                txf1.setText(null);
                txf2.setText(null);
                lblresult.setText(null);
                txf1.requestFocus();
            }
        });
        panel.add(btnlimpar);
        
        JLabel label = new JLabel("+");
        label.setBounds(211, 72, 27, 16);
        panel.add(label);
        
        
        // AQUI ESTA O PROBLEMA   
        JButton btnResultados = new JButton("Resultados");
        btnResultados.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		new PesquisaBanco();
        	}
        });
         panel.add(btnResultados);
         btnResultados.setBounds(309, 113, 106, 33); 
        
        
        
        
         	// Lógica do botao calcular
         
            btncalcular.addActionListener(  
                new ActionListener() {  
  
                    public void actionPerformed(ActionEvent e) {  
  
                        int numero1, numero2, soma = 0;  
                        numero1 = Integer.parseInt(txf1.getText());  
                        numero2 = Integer.parseInt(txf2.getText());  
  
                        soma = numero1 + numero2;  
  
                        lblresult.setText("A Soma é:  "  + soma);  
                    }  
                });  
    }  
}

2 Respostas

M

Então não conheço muito bem a parte gráfica do java, mas onde esta o codigo do PesquisaBanco()?

Luan_Kevin

cara eu dei uma olhada rápida no seu código e acho que só está faltando você deixar a sua outra tela visível!

tenta ai

new PesquisaBanco().setVisible(true);

espero ter ajudado! :thumbup:

Criado 28 de junho de 2012
Ultima resposta 29 de jun. de 2012
Respostas 2
Participantes 3