显示已记录的用户数据Java

时间:2018-10-01 01:05:51

标签: java database

我已经创建了一个用户登录的界面,现在我想创建另一个界面,该界面显示已登录用户的地籍数据。我想知道我该怎么做?

是这样吗? (我创建了一个单独的接口类来查询数据库)我实例化了该接口,并让textField发送ResultSet结果

  public boolean checkLogin(String nick, String senha) {

    Connection con = JBancoDeDados.getConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;

    boolean check = false;

    try {

        stmt = con.prepareStatement("SELECT * FROM usuario WHERE Nick = ? and Senha = ?");
        stmt.setString(1, nick);
        stmt.setString(2, senha);
        rs = stmt.executeQuery();

        if (rs.next()) {
            check = true;
            Interface_Perfil ip = new Interface_Perfil();
            ip.txtExibirNomePerfil.setText(rs.getString("Nome"));
            ip.txtExibirNickPerfil.setText(rs.getString("Nick"));
            ip.txtExibirSenha.setText("Senha");
            ip.txtExibirEmailPerfil.setText(rs.getString("Email"));

        }

    } catch (SQLException ex) {
        Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        JBancoDeDados.closeConnection(con, stmt, rs);
    }   
    return check;   
    }

Interface_Perfil

package Interface;
import java.awt.Color;

public class Interface_Perfil extends javax.swing.JFrame {


public Interface_Perfil() {
    super("JOGO DA FORCA");
    Color corFundo = new Color(32,33,35);
    getContentPane().setBackground(corFundo);
    initComponents();
    setLocationRelativeTo(null);
    setResizable(false);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    plPerfil = new javax.swing.JPanel();
    lblNick = new javax.swing.JLabel();
    lblNome = new javax.swing.JLabel();
    lblNome1 = new javax.swing.JLabel();
    lblSenha = new javax.swing.JLabel();
    jPanel2 = new javax.swing.JPanel();
    lblConquista_Facil = new javax.swing.JLabel();
    lblConquista_Medio = new javax.swing.JLabel();
    lblConquista_Dificil = new javax.swing.JLabel();
    lblConquista_Impossivel = new javax.swing.JLabel();
    lblTitulo_Facil = new javax.swing.JLabel();
    lblTitulo_Facil1 = new javax.swing.JLabel();
    lblTitulo_Facil2 = new javax.swing.JLabel();
    lblTitulo_Facil3 = new javax.swing.JLabel();
    lblDemo_Contagem_Conquista = new javax.swing.JLabel();
    lblDemo_Contagem_Conquista1 = new javax.swing.JLabel();
    lblDemo_Contagem_Conquista2 = new javax.swing.JLabel();
    lblDemo_Contagem_Conquista3 = new javax.swing.JLabel();
    btAlterarSenha = new java.awt.Button();
    txtExibirNickPerfil = new javax.swing.JTextField();
    txtExibirNomePerfil = new javax.swing.JTextField();
    txtExibirEmailPerfil = new javax.swing.JTextField();
    txtExibirSenha = new javax.swing.JTextField();
    btSair = new java.awt.Button();
    btJogar = new java.awt.Button();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    plPerfil.setBackground(new java.awt.Color(32, 33, 35));
    plPerfil.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PERFIL", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bahnschrift", 0, 24), new java.awt.Color(255, 255, 255))); // NOI18N

    lblNick.setFont(new java.awt.Font("Bahnschrift", 0, 24)); // NOI18N
    lblNick.setForeground(new java.awt.Color(255, 255, 255));
    lblNick.setText("NICK:");

    lblNome.setFont(new java.awt.Font("Bahnschrift", 0, 24)); // NOI18N
    lblNome.setForeground(new java.awt.Color(255, 255, 255));
    lblNome.setText("NOME:");

    lblNome1.setFont(new java.awt.Font("Bahnschrift", 0, 24)); // NOI18N
    lblNome1.setForeground(new java.awt.Color(255, 255, 255));
    lblNome1.setText("EMAIL:");

    lblSenha.setFont(new java.awt.Font("Bahnschrift", 0, 24)); // NOI18N
    lblSenha.setForeground(new java.awt.Color(255, 255, 255));
    lblSenha.setText("SENHA:");

    jPanel2.setBackground(new java.awt.Color(32, 33, 35));
    jPanel2.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(126, 87, 194)));
    jPanel2.setForeground(new java.awt.Color(255, 255, 255));

    lblConquista_Facil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Conquista_facil.png"))); // NOI18N

    lblConquista_Medio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Conquista_medio.png"))); // NOI18N

    lblConquista_Dificil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Conquista_dificil.png"))); // NOI18N

    lblConquista_Impossivel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Conquista_imposivel.png"))); // NOI18N

    lblTitulo_Facil.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblTitulo_Facil.setForeground(new java.awt.Color(255, 255, 255));
    lblTitulo_Facil.setText("MODO FÁCIL");

    lblTitulo_Facil1.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblTitulo_Facil1.setForeground(new java.awt.Color(255, 255, 255));
    lblTitulo_Facil1.setText("MODO MÉDIO");

    lblTitulo_Facil2.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblTitulo_Facil2.setForeground(new java.awt.Color(255, 255, 255));
    lblTitulo_Facil2.setText("MODO DIFICÍL");

    lblTitulo_Facil3.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblTitulo_Facil3.setForeground(new java.awt.Color(255, 255, 255));
    lblTitulo_Facil3.setText("MODO IMPOSSÍVEL");

    lblDemo_Contagem_Conquista.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblDemo_Contagem_Conquista.setForeground(new java.awt.Color(255, 255, 255));
    lblDemo_Contagem_Conquista.setText("0");

    lblDemo_Contagem_Conquista1.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblDemo_Contagem_Conquista1.setForeground(new java.awt.Color(255, 255, 255));
    lblDemo_Contagem_Conquista1.setText("0");

    lblDemo_Contagem_Conquista2.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblDemo_Contagem_Conquista2.setForeground(new java.awt.Color(255, 255, 255));
    lblDemo_Contagem_Conquista2.setText("0");

    lblDemo_Contagem_Conquista3.setFont(new java.awt.Font("Bahnschrift", 0, 12)); // NOI18N
    lblDemo_Contagem_Conquista3.setForeground(new java.awt.Color(255, 255, 255));
    lblDemo_Contagem_Conquista3.setText("0");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addGap(49, 49, 49)
            .addComponent(lblDemo_Contagem_Conquista)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(lblDemo_Contagem_Conquista1)
            .addGap(162, 162, 162)
            .addComponent(lblDemo_Contagem_Conquista2)
            .addGap(158, 158, 158)
            .addComponent(lblDemo_Contagem_Conquista3)
            .addGap(47, 47, 47))
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addComponent(lblTitulo_Facil))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lblConquista_Facil, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblConquista_Medio, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(13, 13, 13)
                    .addComponent(lblTitulo_Facil1)))
            .addGap(80, 80, 80)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addComponent(lblConquista_Dificil, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(60, 60, 60))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addComponent(lblTitulo_Facil2)
                    .addGap(72, 72, 72)))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(lblTitulo_Facil3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblConquista_Impossivel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTitulo_Facil)
                        .addComponent(lblTitulo_Facil1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lblConquista_Facil, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblConquista_Medio, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(13, 13, 13)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTitulo_Facil2)
                        .addComponent(lblTitulo_Facil3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblConquista_Impossivel, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblConquista_Dificil, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDemo_Contagem_Conquista3)
                    .addComponent(lblDemo_Contagem_Conquista2)
                    .addComponent(lblDemo_Contagem_Conquista1))
                .addComponent(lblDemo_Contagem_Conquista))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    btAlterarSenha.setBackground(new java.awt.Color(126, 87, 194));
    btAlterarSenha.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
    btAlterarSenha.setForeground(new java.awt.Color(255, 255, 255));
    btAlterarSenha.setLabel("Alterar senha");

    javax.swing.GroupLayout plPerfilLayout = new javax.swing.GroupLayout(plPerfil);
    plPerfil.setLayout(plPerfilLayout);
    plPerfilLayout.setHorizontalGroup(
        plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(plPerfilLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(plPerfilLayout.createSequentialGroup()
                    .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(plPerfilLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(lblNick)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtExibirNickPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(plPerfilLayout.createSequentialGroup()
                                    .addComponent(lblNome)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtExibirNomePerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(plPerfilLayout.createSequentialGroup()
                                    .addComponent(lblNome1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txtExibirEmailPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btAlterarSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(plPerfilLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(lblSenha)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtExibirSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGap(0, 0, Short.MAX_VALUE)))
            .addContainerGap())
    );
    plPerfilLayout.setVerticalGroup(
        plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(plPerfilLayout.createSequentialGroup()
            .addGap(19, 19, 19)
            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblNick)
                .addComponent(txtExibirNickPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(txtExibirNomePerfil, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblNome, javax.swing.GroupLayout.Alignment.TRAILING))
            .addGap(18, 18, 18)
            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(txtExibirEmailPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(lblNome1))
            .addGap(18, 18, 18)
            .addGroup(plPerfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(lblSenha)
                .addComponent(txtExibirSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(btAlterarSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(72, 72, 72)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(53, 53, 53))
    );

    btSair.setBackground(new java.awt.Color(126, 87, 194));
    btSair.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
    btSair.setForeground(new java.awt.Color(255, 255, 255));
    btSair.setLabel("Sair");
    btSair.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btSairActionPerformed(evt);
        }
    });

    btJogar.setBackground(new java.awt.Color(126, 87, 194));
    btJogar.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
    btJogar.setForeground(new java.awt.Color(255, 255, 255));
    btJogar.setLabel("Jogar");
    btJogar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btJogarActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(plPerfil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(btSair, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(btJogar, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(13, 13, 13)))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(plPerfil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(47, 47, 47)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(btJogar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btSair, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    pack();
}// </editor-fold>                        

private void btSairActionPerformed(java.awt.event.ActionEvent evt) {                                       
   Tela_Inicial TL = new  Tela_Inicial();
   TL.pack();
   TL.setVisible(true);
   dispose();
}                                      

private void btJogarActionPerformed(java.awt.event.ActionEvent evt) {                                        
    Interface_Nivel IN = new Interface_Nivel();
    IN.pack();
    IN.setVisible(true);
    dispose(); 
}                                       

public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(Interface_Perfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Interface_Perfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Interface_Perfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Interface_Perfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new Interface_Perfil().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private java.awt.Button btAlterarSenha;
private java.awt.Button btJogar;
private java.awt.Button btSair;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel lblConquista_Dificil;
private javax.swing.JLabel lblConquista_Facil;
private javax.swing.JLabel lblConquista_Impossivel;
private javax.swing.JLabel lblConquista_Medio;
private javax.swing.JLabel lblDemo_Contagem_Conquista;
private javax.swing.JLabel lblDemo_Contagem_Conquista1;
private javax.swing.JLabel lblDemo_Contagem_Conquista2;
private javax.swing.JLabel lblDemo_Contagem_Conquista3;
private javax.swing.JLabel lblNick;
private javax.swing.JLabel lblNome;
private javax.swing.JLabel lblNome1;
private javax.swing.JLabel lblSenha;
private javax.swing.JLabel lblTitulo_Facil;
private javax.swing.JLabel lblTitulo_Facil1;
private javax.swing.JLabel lblTitulo_Facil2;
private javax.swing.JLabel lblTitulo_Facil3;
private javax.swing.JPanel plPerfil;
public javax.swing.JTextField txtExibirEmailPerfil;
public javax.swing.JTextField txtExibirNickPerfil;
public javax.swing.JTextField txtExibirNomePerfil;
public javax.swing.JTextField txtExibirSenha;
// End of variables declaration                   

}

1 个答案:

答案 0 :(得分:1)

您的代码中没有错误,只是您错过了在行ip.setVisible(true);下添加ip.txtExibirEmailPerfil.setText(rs.getString("Email"));来显示Interface_Perfil的错误。

下面是我的工作代码

首页

 login.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String Name = name.getText();
                String Pass = new String(pass.getPassword());

                UserAPI user = new UserAPI();
                user.checklogin(Name, Pass);       
            }

            private void setVisible(boolean b) {
                // TODO Auto-generated method stub

            }
        });

UserAPI

public boolean checklogin(String name, String Pass) throws Exception {
        boolean check = false;

        String sql = "SELECT * FROM admin WHERE name =? and password= ?";
        DatabaseConnection db = new DatabaseConnection();
        Connection conn = db.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, name);
        ps.setString(2, Pass);

        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            check = true;
            Interface_Perfil ip = new Interface_Perfil();
            System.out.println("dddd");
            ip.txtExibirNomePerfil.setText(rs.getString("name"));
            ip.txtExibirNickPerfil.setText(rs.getString("password"));
            ip.txtExibirSenha.setText("Senha");
            ip.txtExibirEmailPerfil.setText("email@hotmail.com");
            ip.setVisible(true);
        }
        ps.close();
        rs.close();
        conn.close();
        return check;
    }

我的项目在 Home 类中运行。

enter image description here