Como eu crio um leitor de Usuario/Senha?

2 respostas
Cesar1987

eu tava tentando fazer sózinho, mas tem algo q ta dando errado ainda!!
Se alguem souber oq é, porfavor me mande respostas!!

Obrigado!

import javax.swing.JFrame;

import javax.swing.<em>;

import java.awt.event.</em>;

import java.awt.<em>;

import java.applet.</em>;

import <a href="http://java.io">java.io</a>.<em>;

import java.lang.</em>;
public class Senha extends JFrame  {

private GridBagLayout layout;

private GridBagConstraints constraints;
public Senha() {

super( Registro );

layout = new GridBagLayout();

constraints = new GridBagConstraints();
setLayout( layout );
  
  JLabel texto1        = new JLabel("Digite o Nome");
  JLabel texto2        = new JLabel("Digite a Senha");
  JPasswordField nome  = new JPasswordField( "Digite aqui" );
  JPasswordField senha = new JPasswordField( "[telefone removido]" );
  JButton botao1       = new JButton( "   Ok   " );
  JButton botao2      = new JButton( "Cancelar" );
     
  constraints.weightx = 0;            
  constraints.weighty = 0;
  addComponent( texto1,   1, 1, 1, 1 );
  addComponent( texto2,   2, 1, 1, 1 );
  addComponent( nome,     1, 2, 1, 1 );
  addComponent( senha,    2, 2, 1, 1 );
  addComponent( botao1,   4, 1, 1, 1 );
  addComponent( botao2,   4, 2, 1, 1 );
  
  senha.setEchoChar('*');
  senha.addActionListener(this);
  botao1.addActionListener(this);
}

private void addComponent( Component component,

int row, int column, int width, int height ) {

constraints.gridy = row;

constraints.gridx = column;

constraints.gridwidth = width;

constraints.gridheight = height;

layout.setConstraints( component, constraints );

add( component );

}
public void actionPerformed(ActionEvent e)

{

if (e.getSource().equals(botao2));	

System.exit(0);

// else

}
public static void main( String args[] )

{

Senha gridBagFrame = new Senha();

gridBagFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

gridBagFrame.setBackground(new Color(236,233,216));

gridBagFrame.setSize( 200, 100 );

gridBagFrame.setVisible( true );

}

}

2 Respostas

_Renatu

Fica mais fácil se você disser qual mensagem de erro você recebe, ou o que você vê de errado no seu programa…

erickcellani

fica mais fácil ainda se vc usar a tag code

Criado 24 de maio de 2007
Ultima resposta 24 de mai. de 2007
Respostas 2
Participantes 3