cara… fiz uma tela de login bem simples aqui… com os campos de login e senha assim como os botões para entrar e sair… roda aí e adapta com seu código para validar o login…
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* @author lb
*/
public class Login extends JFrame
{
/**
* main
*
* @param args[] String
*/
public static void main( String args[] )
{
new Login().setVisible( true );
}
/**
* Login
*
*/
public Login()
{
initComponents();
}
/**
* performLogin
*
*/
private void performLogin()
{
String user = tfLogin.getText();
String password = new String( pfPassword.getPassword() );
System.out.println( "COLOQUE AQUI SEU CÓDIGO DE LOGIN" );
System.out.println( "LOGIN: " + user + " - SENHA: " + password );
}
/**
* performCancel
*
*/
private void performCancel()
{
System.exit( 0 );
}
/**
* initComponents
*
*/
private void initComponents()
{
setLayout( new BorderLayout() );
// define o tamanho da janel x - y
setSize( 300, 150 );
// coloca a janela no centro da tela
setLocationRelativeTo( null );
captionPane.setLayout( new FlowLayout( FlowLayout.CENTER ) );
captionPane.setBackground( Color.LIGHT_GRAY );
captionPane.add( jlTitle );
jlTitle.setFont( new Font( "SansSerif", Font.BOLD, 16 ) );
buttonsPane.setLayout( new FlowLayout( FlowLayout.CENTER ) );
buttonsPane.setBackground( Color.WHITE );
buttonsPane.add( btOk );
buttonsPane.add( btCancel );
bodyPane.setLayout( new GridBagLayout() );
bodyPane.setBackground( Color.WHITE );
bodyPane.add( jlLogin, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets( 5, 5, 0, 0 ), 0, 0 ) );
bodyPane.add( tfLogin, new GridBagConstraints( 1, 0, 1, 1, 1.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets( 5, 5, 0, 10 ), 0, 0 ) );
bodyPane.add( jlPassword, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets( 5, 5, 0, 0 ), 0, 0 ) );
bodyPane.add( pfPassword, new GridBagConstraints( 1, 1, 1, 1, 1.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets( 5, 5, 0, 10 ), 0, 0 ) );
add( captionPane, BorderLayout.NORTH );
add( bodyPane, BorderLayout.CENTER );
add( buttonsPane, BorderLayout.SOUTH );
btOk.addActionListener( new AbstractAction()
{
public void actionPerformed( ActionEvent e )
{
performLogin();
}
});
btCancel.addActionListener( new AbstractAction()
{
public void actionPerformed( ActionEvent e )
{
performCancel();
}
});
}
private JLabel jlTitle = new JLabel( "Titulo do programa" );
private JLabel jlLogin = new JLabel( "Login" );
private JLabel jlPassword = new JLabel( "Password" );
private JTextField tfLogin = new JTextField();
private JPasswordField pfPassword = new JPasswordField();
private JPanel bodyPane = new JPanel();
private JPanel captionPane = new JPanel();
private JPanel buttonsPane = new JPanel();
private JButton btOk = new JButton( "Entrar" );
private JButton btCancel = new JButton( "Sair" );
}