#1Qua 14 Ago - 20:44
[Java]Informar login e senha (TextField) ~~ Code
Boa Noite,
Não é útil, eu só estou testando meu conhecimento Java:
Não é útil, eu só estou testando meu conhecimento Java:
- Código:
/*
* Amostrar Senha e Usuários
* JTextField & JPasswordField
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author TrY
*/
public class ControleText extends JFrame implements ActionListener{
JButton ok, cancel;
JPasswordField senha;
JTextField login;
public ControleText(){
super("Textos e Senhas!!!");
ok = new JButton("Confirmar...");
ok.addActionListener(this);
cancel = new JButton("Cancelar...");
cancel.addActionListener(this);
senha = new JPasswordField();
senha.addActionListener(this);
login = new JTextField();
login.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new GridLayout(3,2));
c.add(new JLabel("Login:"));
c.add(login);
c.add(new JLabel("Senha:"));
c.add(senha);
c.add(ok);
c.add(cancel);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args){
new ControleText();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == ok){
String msg = "Login: "+login.getText()+"\nSenha: "+new String(senha.getPassword());
JOptionPane.showMessageDialog(null, msg);
}else if(e.getSource() == cancel){
login.setText("");
senha.setText("");
}
}
}