java实现登录密码框

用JAVA实现密码登陆框的源代码:

//java语言编写登录密码框
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class myclass1 extends JFrame implements ActionListener
{
 public static void main(String[] args) {
     new myclass1(); 
 }
  public myclass1()
 {con=new JPanel();
 lb1=new JLabel("帐号:");
 lb2=new JLabel("密码:");
 text1=new JTextField();
 text2=new JTextField();
 btn1=new JButton("登陆");
    btn1.addActionListener(this);
 btn2=new JButton("取消");
 btn2.addActionListener(this);
 
 con.setLayout(new GridLayout(3,2));
 con.add(lb1);
 con.add(text1);
 con.add(lb2);
 con.add(text2);
 con.add(btn1);
 con.add(btn2);
 
 Container c=getContentPane();
 c.setLayout(new BorderLayout());
 c.add(con,BorderLayout.CENTER);
 
 
 setSize(300,200);
 setVisible(true);
 }
 
 public void actionPerformed(ActionEvent e)
 {
 
    
  if(e.getSource()==btn1)
  {    user=text1.getText();
 
     pass=text2.getText();
   
  
   if(user.equals("wjm")&&pass.equals("123"))
   {
     System.out.println(user+user.length());
  //System.out.println("sucessfullyy");
     myclass2 ms2=new myclass2();
 
  // ms2.setTitle("登陆窗口哦");
  // ms2.setVisible(true);
  // ms2.setSize(800,800);
   }
  else  
    //System.out.println("failedd");
   JOptionPane.showMessageDialog(null,"密码错误,请再次输入!","FirstJava",1);
 

  
  }
  else if(e.getSource()==btn2)
  {
  
   text1.setText("");
   text2.setText("");
  }
  
 }
 JPanel con=null;
 JLabel lb1=null;
 JLabel lb2=null;
 JTextField text1=null;
 JTextField text2=null;
 JButton btn1=null;
 JButton btn2=null;
 
 String user="";
 String pass="";

}

 class myclass2 extends JFrame
{
  Container c=null;
  JLabel lb1=null;
  myclass2()
  {
   c=getContentPane();
   lb1=new JLabel("登陆成功!!");
   c.setLayout(new FlowLayout());
   c.add(lb1);
     setSize(800,800);
      setVisible(true);
 
     setBak();         //调用背景方法
  Container c = getContentPane(); //获取JFrame面板
  JPanel jp = new JPanel();      //创建个JPanel
  jp.setOpaque(false);           //把JPanel设置为透明 这样就不会遮住后面的背景  这样你就能在JPanel随意加组件了
  c.add(jp);                  
  setSize(540, 450);
  setVisible(true);
 }
 public void setBak(){
  ((JPanel)this.getContentPane()).setOpaque(false);
   ImageIcon img = new ImageIcon("d://51.jpg");
   JLabel background = new JLabel(img);this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
   background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
    }
 }

作者:kgcywjm,转载本文时,必须以超链接的形式标明文章的原始出处!
网址:
 | 0 Comments | EDIT
相关日志

Advertisements

  • 史蒂夫•乔布斯传(精装珍藏版,附印作者签章)
  • 黑客:计算机革命的英雄
  • HTML5揭秘
  • 卓越购书,满一百返20。
  • 留言