Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/07/2008, 08:03
Lindberg
 
Fecha de Ingreso: abril-2006
Ubicación: Recife - Brasil
Mensajes: 23
Antigüedad: 18 años, 10 meses
Puntos: 0
Respuesta: JFRAME o JLABEL

Opa vai um exemplo de JFrame e JLabel
para teste de senha.

------------------------------------------------- compilar e olhar ------------------

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ValidaSenha extends JFrame {

private JLabel labelValor01;
private JPasswordField senha;
private JButton botaoValida;
private Container container;

public ValidaSenha(){
//Construtor
super("Valida Senha");

//Iniciar Container
container = getContentPane();
container.setLayout(new FlowLayout());

//Setar Valores aos Componentes
labelValor01 = new JLabel("Insira a SENHA");
senha = new JPasswordField(10);
botaoValida = new JButton("Validar Senha");

//Definir evento do botao
botaoValida.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
String s = new String(senha.getPassword());
if(s.equals("")){
JOptionPane.showMessageDialog(null,"Senha CORRETA","senha correta",JOptionPane.INFORMATION_MESSAGE);
}else JOptionPane.showMessageDialog(null,"Senha INCORRETA","INCORRETA",JOptionPane.ERROR_MESSAGE);
}
});

container.add(labelValor01);
container.add(senha);
container.add(botaoValida);
setSize(400,100);
setVisible(true);
}

public static void main(String[] args) {

ValidaSenha vs = new ValidaSenha();
vs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}


-------------------------------------------------