Porque quando boto o nome e senha ele nao passsa pra proxima tela?
Código abaixo:
Classe login:
package view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import DAO.Acesso;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField txtLogin;
private JPasswordField txtSenha;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Login:");
lblNewLabel.setBounds(40, 64, 86, 14);
contentPane.add(lblNewLabel);
JLabel lblSenha = new JLabel("Senha:");
lblSenha.setBounds(40, 101, 86, 14);
contentPane.add(lblSenha);
txtLogin = new JTextField();
txtLogin.setBounds(76, 61, 167, 20);
contentPane.add(txtLogin);
txtLogin.setColumns(10);
txtSenha = new JPasswordField();
txtSenha.setBounds(76, 98, 167, 20);
contentPane.add(txtSenha);
JButton btnNewButton = new JButton("Acessar");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Acesso cl = new Acesso();
cl.Acesso(txtLogin.getText(),txtSenha.getText());
if (cl.acesso == true) {
TelaInicial tl = new TelaInicial();
tl.show();
tl.setExtendedState(new TelaInicial().MAXIMIZED_BOTH);
dispose();
}
if (cl.acesso == false) {
txtLogin.setText("");
txtSenha.setText("");
txtLogin.requestFocus();
}
cl.acesso = false;
}
});
btnNewButton.setBounds(53, 163, 107, 35);
contentPane.add(btnNewButton);
JButton btnCancelar = new JButton("Cancelar");
btnCancelar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnCancelar.setBounds(170, 163, 131, 35);
contentPane.add(btnCancelar);
}
}
classe tela inicial
package view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class TelaInicial extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TelaInicial frame = new TelaInicial();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public TelaInicial() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
classe acesso
package DAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Statement;
import javax.swing.JOptionPane;
public class Acesso {
public boolean acesso;
public void Acesso(String login, String senha) {
Connection con = null;
Statement consulta = null;
ResultSet tabela = null;
try {
Class.forName("con.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/login","root","");
consulta = (Statement) con.createStatement();
tabela = consulta.executeQuery("select login, senha from tbl_usuario where login='"+login+"'and senha='"+senha+"");
if (tabela.next()) {
JOptionPane.showMessageDialog(null, "Usuario e Senha Corretos");
acesso = true;
}else{
JOptionPane.showMessageDialog(null, "Usuario e Senha Incorretos");
acesso = false;
}
}catch (ClassNotFoundException | SQLException e) {
}
}}
me ajudem pfvr