用JAVA写的简易QQ登陆界面(AWT组件的综合应用)

 


import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
public class QQ
{
public static void main(String args[])
{
 WindowBox win=new WindowBox("QQ2011");
 // Draw d=new Draw();

}
}
class WindowBox extends Frame implements ActionListener
{
  Box baseBox,boxv1,boxv2,boxv3;
  Button b1,b2;
  TextField text1,text2;
WindowBox(String s)
{
super(s);
boxv1=Box.createVerticalBox();
boxv1.add(new Label("账号"));
boxv1.add(Box.createVerticalStrut(10));
boxv1.add(new Label("密码"));
boxv1.add(Box.createVerticalStrut(10));
//boxv1.add(new Label(""));
b1=new Button("登录");
b1.addActionListener(this);
b2=new Button("退出");
b2.addActionListener(this);
boxv3=Box.createHorizontalBox();
boxv3.add(b1);
boxv3.add(Box.createHorizontalStrut(10));
boxv3.add(b2);
text1=new TextField(10);
text2=new TextField(10);
text2.setEchoChar('*');
boxv2=Box.createVerticalBox();
boxv2.add(text1);
boxv2.add(Box.createVerticalStrut(10));
boxv2.add(text2);
boxv2.add(Box.createVerticalStrut(10));
boxv2.add(boxv3);
baseBox=Box.createHorizontalBox();
baseBox.add(boxv1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxv2);
setLayout(new FlowLayout());
add(baseBox);
setBounds(600,125,400,260);
setVisible(true);
setResizable(true);
ImageIcon icon=new ImageIcon("qq.jpg");
setIconImage(icon.getImage());
setBackground(Color.pink);
}
 /*class D extends JFrame
    
  public void Draw()
               {
   MyPanel mp=null;
   
   mp=new MyPanel();
   
   this.add(mp);
   
   this.setSize(400,300);
   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   
   this.setVisible(true);
  }
 
class MyPanel extends JPanel
{
   public void paint(Graphics g)
  {
   
   super.paint(g);
//   g.setColor(Color.blue);
//   g.fillRect(10,10, 40,60);
//   g.setColor(Color.red);
//   g.fillRect(80,80, 40, 60);
//   System.out.println("paint被调用");
//        g.drawOval(10,10,30,30);
   
   
   Image im=Toolkit.getDefaultToolkit().getImage
   (Panel.class.getResource("
\\aa.jpg"));
   
   g.drawImage(im,90,90,200,150,this);
              }
  }*/
 
 

public void actionPerformed(ActionEvent e)
{
/*if(text1.getText().equals("123456")&&text2.getText().equals("123456"))
   {
 JOptionPane.showMessageDialog(null,"恭喜,登陆成功");
        
   }
else
{
JOptionPane.showMessageDialog(null,"登陆失败,密码或账号错误,请重新登录");
text1.setText(null);
text2.setText(null);
}*/
if(e.getSource()==b1)
{
 if(text1.getText().equals("123456")&&text2.getText().equals("123456"))
   {
 JOptionPane.showMessageDialog(null,"恭喜,登陆成功");
        
   }
else
{
JOptionPane.showMessageDialog(null,"登陆失败,密码或账号错误,请重新登录");
text1.setText(null);
text2.setText(null);
}
}
if(e.getSource()==b2)
{
System.exit(0);
}
}
}


 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值