您的位置:首页 > 其它

用户名称   登录密码

2014-05-21 23:43 106 查看
import javax.swing.*;import java.awt.*;import java.awt.event.*; //导入事件包中的所有类public class TextApp extends JFrame implements ActionListener{ private JLabel label1,label2,label3; private JTextField inputText; private JPasswordField inputPwd; public TextApp(){ super("单行文本框的应用"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); label1=new JLabel("用户名称:"); label2=new JLabel("登陆密码:"); inputText = new JTextField(" ",27); inputPwd = new JPasswordField(27); label3= new JLabel();
inputText.addActionListener(this);//添加监听器 inputPwd.addActionListener(this); Container cp= getContentPane(); cp.setLayout(new FlowLayout()); cp.add(label1); cp.add(inputText); cp.add(label2); cp.add(inputPwd);cp.add(label3); setSize(400,200); } public void actionPerformed(ActionEvent e){ //对回车事件的处理 if(e.getSource()==inputText)
{if (inputText.getText().indexOf('@') != -1) label3.setText("含有非法字符");}

else if(e.getSource()==inputPwd){
if (inputPwd.getPassword().length > 10 ) label3.setText("密码太长,请重新输入");
else if(inputPwd.getPassword().length < 6) label3.setText("密码太短,请重新输入");elselabel3.setText("成功");}
}

public static void main(String args[]){ TextApp frame=new TextApp(); frame.setVisible(true); } }

附件:http://down.51cto.com/data/2364450
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息