Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wy.FrameClass;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- /**
- * 测试输入密码和用户名后打印输入的密码和用户名。
- * Created by Administrator on 2016/4/18.
- */
- public class PasswordField extends JFrame {
- private JTextField userName;
- private JPasswordField userPassword;
- private JButton logonButton;
- private JButton exitButton;
- public PasswordField(){
- super("密码验证");
- Container container=getContentPane();
- container.setLayout(new GridLayout(3,2,2,2));
- userName=new JTextField(16);
- userPassword=new JPasswordField(16);
- logonButton=new JButton("登录");
- exitButton=new JButton("退出");
- logonButton.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- char[] pw=userPassword.getPassword();
- String message="你的用户名是:"+userName.getText()+"你的密码是:"+new String(pw);
- JOptionPane.showMessageDialog(PasswordField.this,message);
- }
- });
- exitButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(-1);
- }
- });
- container.add(new JLabel(" 用户名:"));
- container.add(userName);
- container.add(new JLabel(" 密码:"));
- container.add(userPassword);
- container.add(logonButton);
- container.add(exitButton);
- setResizable(false);
- setSize(300,200);
- setVisible(true);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- }
- public static void main(String []args){
- new PasswordField();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement