图8-1 运行结果,输入正确信息                      图8-2 显示欢迎信息
  
图8-3 运行结果,输入错误信息                  图8-4 显示重新输入信息
//PasswordVerification.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class PasswordVerification extends JFrame 
{
   JLabel userLabel;
   JLabel passwordLabel;
   JTextField userText;
   JPasswordField passwordText;
   
   int count=1;//统计输入信息的次数
   
   public PasswordVerification()
   {
        super("请输入信息");
        
        Container c =代码1;//得到容器对象container
        c.setLayout(new FlowLayout());//设置默认布局
        
        userLabel=代码2//创建用户标签
        passwordLabel=代码3;//创建密码标签
        userText=代码4//创建用户文本输入框
        passwordText=代码5//创建密码输入文本框
        passwordText. 代码6(
new ActionListener(){  //注册事件监听者
         public void actionPerformed(代码7)//事件处理
   {
    String userName=new String("陈三");//假设为正确的用户名
    String password=new String("12345678");//假设为正确的密码
    
    if(e.getSource()==passwordText)
    {
     count++;
     char[] passwords=passwordText.getPassword();
     if(userText.getText().equals(userName)&&password.equals(new String(passwords)))
     {
     JOptionPane.showMessageDialog(null,"欢迎您:"+userName);
     System.exit(0);
     }
     else if(count>3)
     System.exit(0);
     else {
       JOptionPane.showMessageDialog(null,userText.getText()+"请输入正确信息");
         }
     }
    }
         });
        
        c.add(userLabel);
        c.add(userText);
        c.add(passwordLabel);
        c.add(passwordText);
        
        setSize(240,100);
        setVisible(true);
   }
   
     
    public static void main(String[] args)
    {
       PasswordVerification pv=new PasswordVerification();
       pv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
  }