logo资料库

gui登陆界面.doc

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class text extends JFrame { /** * @param args */ public String str="左强"; public String strc="1234567"; protected JButton a=new JButton("注册"); protected JButton b=new JButton("登录"); protected JPanel bb=new JPanel(); protected JLabel aa=new JLabel(" 如果你是新用户请先注册帐号"); text() { setLayout(new GridLayout(3,1)); bb.setLayout(new FlowLayout()); bb.add(a); bb.add(b); add(aa); add(bb); b.addActionListener(new ActionListener()//创建事件监听 { @Override public void actionPerformed(ActionEvent arg0) { System.out.print("zuoziqiang"); loade jf=new loade(); jf.pack(); //jf.setDefaultCloseOperation(3); jf.setTitle("用户登录"); jf.setLocation(400, 400); jf.setVisible(true); jf.setBackground(Color.RED); a.addActionListener(new ActionListener()//创建事件监听器 { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub mark jf=new mark(); }); }
jf.setTitle("用户注册"); jf.setLocation(400, 400); jf.setSize(200,200); jf.setVisible(true); } } class mark extends JFrame//创建一个登录,注册窗口 { protected JButton a=new JButton("完成"); }); protected JButton b=new JButton("登录"); protected JLabel xx=new JLabel("版权所有,不得抄袭 !"); protected JPanel aa=new JPanel(); protected JPanel bb=new JPanel(); protected JPanel kk=new JPanel(); //final JLabel cc=new JLabel("请输入账号和密码"); JLabel c1=new JLabel("请输入账号"); JLabel c2=new JLabel("请输入密码"); final JTextField a2=new JTextField(); final JPasswordField a1=new JPasswordField(); ////////////// mark() { kk.setLayout(new GridLayout(2,2)); kk.add(c1); kk.add(a2); kk.add(c2); kk.add(a1); a1.setEchoChar('*'); setLayout(new GridLayout(3,1)); aa.setLayout(new FlowLayout()); aa.add(a); aa.add(b); bb.add(xx); add(bb); add(kk); add(aa); a.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub if((a2.getText()).equals("") ) { } xx.setText("账号不能为空"); repaint(); else if( a1.getPassword().length <6 || a1.getPassword().length>10) { xx.setText("请重新输入 6~10 之间长度的密码"); repaint(); else JOptionPane.showMessageDialog(null,"密码长度不够或太长"); }
{ str=a2.getText().toString(); strc=a1.getText().toString(); //JOptionPane.showMessageDialog(null," 你 的 用 户 名 为 :"+str+a1.getText().toString()); xx.setText("注册成功 欢迎使用!"); repaint(); } } }); b.addActionListener(new ActionListener(){ ublic void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub if(!(a2.getText()).equals(str) ) { xx.setText("账号错误 请重新输入"); repaint(); } else if( !(a1.getText().toString()).equals(strc)) { xx.setText("密码错误请重新输入"); repaint(); } else { xx.setText("welcome"+" "+a2.getText()); //JOptionPane.showMessageDialog(null,"密码长度不够或太长"); repaint(); } }); setLayout(new GridLayout(3,1)); } } } //class class loade extends JFrame{ loade() { final JLabel cc=new JLabel("请输入账号和密码"); JLabel c1=new JLabel("请输入账号"); JLabel c2=new JLabel("请输入密码"); final JTextField aa=new JTextField(); final JPasswordField bb=new JPasswordField(); bb.setEchoChar('*'); //bb.getText().toCharArray()=0; JButton x=new JButton("确定"); JButton y=new JButton("取消"); JPanel jj=new JPanel(); jj.setSize(100,100); JPanel pp=new JPanel();
JPanel qq=new JPanel(); qq.setLayout(new FlowLayout()); pp.setLayout(new FlowLayout()); jj.setLayout(new GridLayout(2,2)); jj.add(c1); jj.add(aa); jj.add(c2); jj.add(bb); pp.add(x); pp.add(y); qq.add(cc); add(qq,BorderLayout.NORTH); add(jj,BorderLayout.CENTER); add(pp); x.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub //JOptionPane.showMessageDialog(null,"密码长度不够或太长"); } { } if(!(aa.getText()).equals(str) ) { cc.setText("账号错误 请重新输入"); repaint(); else if( !(bb.getText().toString()).equals(strc)) { cc.setText("密码错误请重新输入"); repaint(); else cc.setText("welcome"+" "+aa.getText()); repaint(); } } } ); y.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { aa.setText(""); cc.setText("请输入账号和密码"); bb.setText(""); repaint(); } } } } public static void main(String[] args) { text jj=new text(); jj.setSize(200,200); jj.setLocation(400, 400);
jj.setDefaultCloseOperation(3); jj.setTitle("用户登录"); jj.setVisible(true); jj.setBackground(Color.RED); } }
分享到:
收藏