java实现qq页面登陆界面

先看效果

1.建立包com.QQUI0819

2.在包下建立类

LoginAction

package com.QQUI0819;

import javax.swing.*;
import java.awt.event.*;
//首先,编写按钮癿监听器实现类
public class LoginAction implements
        ActionListener {
    private int count=0;
    //当前为null,创建后指向界面输入框
    private JTextField ulName;
    private JTextField ulpass;
    //创建时,输入界面类中输入框
    public LoginAction(JTextField ulName,JTextField ulpass ){
        this.ulName=ulName;
        this.ulpass=ulpass;
    }


    //实现接口中的方法
    //当劢作发生时,这个方法执行
    public void actionPerformed(ActionEvent e) {
        //点击时,就取得界面输入框癿内容
        //此时癿jtf,指向是界面上那个输入框
        String o=ulName.getText();
        String p=ulName.getText();
        System.out.println("账号输入的是 "+o);
        System.out.println("密码输入的是 "+p);
        if(o.equals("saygood") &&(p.equals("123456"))){
            //如果输入正确,弹出新界面
            JFrame jf=new JFrame();
            jf.setTitle("登陆成功");
            jf.setSize(300,400);
            jf.setLocationRelativeTo(null);
            jf.setVisible(true);
        } else {
            //如果输入正确,弹出新界面
            JFrame jf=new JFrame();
            jf.setTitle("登陆失败");
            jf.setSize(300,100);
            JButton b1 = new JButton("登陆失败,账号和密码不匹配,请重新登陆");
            jf.add(b1);
            jf.setLocationRelativeTo(null);
            jf.setVisible(true);
        }
    }
}

QQ.java

package com.QQUI0819;

import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Image;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRootPane;
import javax.swing.JTextField;

public class QQ extends JFrame{

  //用户名
  private JTextField ulName;
  //密码
  private JPasswordField ulPasswd;
  //小容器
  private JLabel j1;
  private JLabel j2;
  private JLabel j3;
  private JLabel j4;
  JLabel j5;
  JLabel j6;
  //小按钮
  private JButton b1;
  //复选框
  private JCheckBox c1;
  private JCheckBox c2;
  JPanel jp;
 
  /**
   * 初始化QQ登录页面
   * */
  public QQ(){
    //设置登录窗口标题
    this.setTitle("QQ登录");
    //去掉窗口的装饰(边框)
    //采用指定的窗口装饰风格
    this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
    //窗体组件初始化
    init();
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //设置布局为绝对定位
    this.setLayout(null);
    this.setBounds(0, 0, 355, 265);
    //设置窗体的图标
    Image img0 = new ImageIcon("C:\\Users\\lenovo\\Pictures\\Java题\\qq1.jpg").getImage();
    this.setIconImage(img0);
    //窗体大小不能改变
    this.setResizable(false);
    //居中显示
    this.setLocationRelativeTo(null);
    //窗体显示
    this.setVisible(true);


  }
  /**
   * 窗体组件初始化
   * */
  public void init(){
    //创建一个容器,其中的图片大小和setBounds
	  jp = new JPanel();
    Container container = this.getContentPane();
    j1 = new JLabel();
    //设置背景色
    Image img1 = new ImageIcon("C:\\\\Users\\\\lenovo\\\\Pictures\\\\Java题\\\\qq.jpg").getImage();
    j1.setIcon(new ImageIcon(img1));
    j1.setBounds(0, 0, 355, 90);
    //qq头像设定
    j2 = new JLabel();
    Image img2 = new ImageIcon("C:\\Users\\lenovo\\Pictures\\Java题\\qq1.jpg").getImage();
    j2.setIcon(new ImageIcon(img2));
    j2.setBounds(150, 40, 60, 60);
    //用户名输入框
    ulName = new JTextField();
    ulName.setBounds(100, 100, 150, 20);
    //注册账号
    j3 = new JLabel("账号");
    j3.setBounds(260, 100, 70, 20);
    //密码输入框
    ulPasswd = new JPasswordField();
    ulPasswd.setBounds(100, 130, 150, 20);
    j4= new JLabel("密码");
    j4.setBounds(260, 130, 70, 20);
    j5= new JLabel("注册账号");
    j5.setBounds(180, 155, 80, 15);
    j6= new JLabel("忘记密码");
    j6.setBounds(250, 155, 80, 15);
    //记住密码
    c1 = new JCheckBox("记住密码");
    c1.setBounds(20, 155, 80, 15);
    //自动登陆
    c2 = new JCheckBox("自动登陆");
    c2.setBounds(100, 155, 80, 15);
    //登陆按钮
    b1 = new JButton("登录");
    //设置字体和颜色和手形指针
    b1.setFont(new Font("宋体", Font.PLAIN, 12));
    b1.setForeground(Color.black);
    b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    b1.setBounds(20, 200, 300, 20);
    JLabel jl3=new JLabel("状态:");
    jp.add(jl3);
    jl3.setBounds(10, 100, 30, 10);
    
    JComboBox<String> jcb1=new JComboBox();
    jp.add(jcb1);
    jcb1.setBounds(10, 100,30, 10);
    jcb1.addItem("在线");
    jcb1.addItem("隐身") ;
    jcb1.addItem("追剧中") ;
    jcb1.addItem("吃瓜") ;
    jcb1.addItem("读书中") ;

    //给按钮添加
    //所有组件用容器装载
    this.add(j1);
    this.add(j2);
    this.add(j3);
    this.add(j4);
    this.add(j5);
    this.add(j6);
    
    this.add(c1);
    this.add(c2);
    this.add(b1);
    add(jcb1);
    add(jcb1);
    add(jl3);
    //创建监听器对象,幵加给按钮
    LoginAction lo=new LoginAction(ulName,ulPasswd);
    b1.addActionListener(lo);

    container.add(j1);
    container.add(ulName);
    container.add(ulPasswd);
  }
  public static void main(String[] args) {
    new QQ();
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

i want to舞动乾坤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值