lei说的对。我来详细说明一下:JButton button = new JButton("OK");button.addActionListener(this);//这个界面实现一个ActionListenerpublic void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();if("OK".equals(cmd)){ validate();}}private JTextField tfName;//这些控件都假设你自己add到界面里了private JPasswordField tpPsw;public void validate(){String name = tfName.getText();char[] psw = tpPsw.getPassword();if("".equals(name)){System.out.println("填写名字");return;}if(psw.length<=0){return;}//下面自己查询结果,然后比较密码。可能需要用到一些加密算法}