1、最近在翻阅 java 基础知识的时候偶然间看到了 jpassword 的用法的介绍,然后写下了如下的这个 demo,供参考,提供意见实现功能:当你输入用户名和密码后会返回一个窗体,有刚才输入的用户名和密码。代码如下所示:package ;/实现读取登录的密码和用户名import java.awt.Container;import java.awt.GridLayout;import java.awt.Label;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JB
2、utton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;public class JpasswordField extends JFrame/* param args*/JTextField userName;JPasswordField password;JButton loginBtn;JButton cancelBtn;public JpasswordField()super(“Jpasswo
3、rd 的演示“);Container container=getContentPane();container.setLayout(new GridLayout(3,2);userName=new JTextField(16);password=new JPasswordField(16);loginBtn=new JButton(“登录“);loginBtn.addActionListener(new ActionListener()public void actionPerformed(ActionEvent evt)char pw=password.getPassword();Strin
4、g message=“您的用户名是:“+userName.getText()+“n 您的密码是:“+new String(pw);if(message=null)System.out.println(“你需要输入用户名和密码 “);elseJOptionPane.showMessageDialog(JpasswordField.this, message););cancelBtn=new JButton(“取消“);cancelBtn.addActionListener(new ActionListener()public void actionPerform(ActionEvent evt)
5、System.exit(0);Overridepublic void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stubSystem.exit(0););container.add(new Label(“userName:“);container.add(userName);container.add(new Label(“passWord:“);container.add(password);container.add(loginBtn);container.add(cancelBtn);this.setSi
6、ze(300,150);this.setLocation(400, 250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);public static void main(String args) new JpasswordField();最近在翻阅 java 基础知识的时候偶然间看到了 jpassword 的用法的介绍,然后写下了如下的这个 demo,供参考,提供意见实现功能:当你输入用户名和密码后会返回一个窗体,有刚才输入的用户名和密码。代码如下所示:package ;/实现读取登录的密码
7、和用户名import java.awt.Container;import java.awt.GridLayout;import java.awt.Label;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;pu
8、blic class JpasswordField extends JFrame/* param args*/JTextField userName;JPasswordField password;JButton loginBtn;JButton cancelBtn;public JpasswordField()super(“Jpassword 的演示“);Container container=getContentPane();container.setLayout(new GridLayout(3,2);userName=new JTextField(16);password=new JP
9、asswordField(16);loginBtn=new JButton(“登录“);loginBtn.addActionListener(new ActionListener()public void actionPerformed(ActionEvent evt)char pw=password.getPassword();String message=“您的用户名是:“+userName.getText()+“n 您的密码是:“+new String(pw);if(message=null)System.out.println(“你需要输入用户名和密码 “);elseJOptionPa
10、ne.showMessageDialog(JpasswordField.this, message););cancelBtn=new JButton(“取消“);cancelBtn.addActionListener(new ActionListener()public void actionPerform(ActionEvent evt)System.exit(0);Overridepublic void actionPerformed(ActionEvent arg0) / TODO Auto-generated method stubSystem.exit(0););container.
11、add(new Label(“userName:“);container.add(userName);container.add(new Label(“passWord:“);container.add(password);container.add(loginBtn);container.add(cancelBtn);this.setSize(300,150);this.setLocation(400, 250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);public static void main(String args) new JpasswordField();