首页 > 程序开发 > 软件开发 > Java >

用JAVA实现一个简单的QQ界面

2018-07-19

用JAVA实现一个简单的QQ界面。

用JAVA实现一个简单的QQ界面

package com.wbq.event;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
public class MyQQLogin extends JFrame{
//定义所需要的组件
JLabel jlbTop,jlbImg,jlbReg,jlbPsw;
JPanel jp; //用于界面底部区域
JTextField jtf;
JPasswordField jpf;
JCheckBox box1,box2;
JButton jbLogin;//登陆按钮

 

public static void main(String[] args) {
// TODO Auto-generated method stub
MyQQLogin qqLogin=new MyQQLogin();
}

public MyQQLogin() {
// TODO Auto-generated constructor stub
//北部
jlbTop=new JLabel(new ImageIcon("img/qq.gif"));

//中部
jp=new JPanel();
jp.setLayout(null);  //绝对layout布局
jlbImg=new JLabel(new ImageIcon("img/bghd.jpg"));
jlbImg.setBounds(25,0,70,70);
jtf=new JTextField(15);
jtf.setBounds(110,10,180,30);
jpf=new JPasswordField(15);
jpf.setBounds(110,35,180,30);
box1=new JCheckBox("记住密码");
box1.setBounds(110,75,90,15);
box2=new JCheckBox("自动登陆");
box2.setBounds(210,75,90,15);

jlbReg=new JLabel("注册账号");
jlbReg.setBounds(300,15,60,15);
//jlbReg.setFont(MyFont.myFont);
jlbReg.setForeground(Color.blue);
jlbPsw=new JLabel("找回密码");
jlbPsw.setBounds(300,50,60,15);
//jlbPsw.setFont(MyFont.myFont);
jlbPsw.setForeground(Color.blue);

//南部
jbLogin=new JButton(new ImageIcon("img/login.png"));
jbLogin.setBounds(110,100,180,32);

//添加组件
jp.add(jlbImg);
jp.add(jtf);
jp.add(jpf);
jp.add(box1);
jp.add(box2);
jp.add(jlbReg);
jp.add(jlbPsw);
jp.add(jbLogin);

//添加组件到JFrame
this.add(jlbTop,"North");
this.add(jp,"Center");
//设置窗体属性
this.setTitle("QQ2018");
this.setIconImage(new ImageIcon("Image/qq.gif").getImage());
this.setSize(400,350);
// 居中显示
        this.setLocationRelativeTo(null);
        // 窗体大小不能改变
        this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
ActionListener al = new ActionListener() {
    
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("被点了");
        
    }
};
MouseListener ml = new MouseListener() {
    
    //在组件上释放鼠标按钮时调用
    @Override
    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标释放了..");
    }
    
    //在组件上按下鼠标按钮时调用。
    @Override
    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标点下了..");
    }
    
    //当鼠标退出组件时调用。
    @Override
    public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标退出 了..");
    }
    
    //当鼠标进入组件时调用
    @Override
    public void mouseEntered(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标移入 了..");
    }
    
    //在组件上单击(按下并释放)鼠标按钮时调用。 
    @Override
    public void mouseClicked(MouseEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("鼠标点击 了..");
    }
};
KeyListener kl = new KeyListener() {
    //完成一次完整的敲击键盘上某个键的过程(按下和松开)
    @Override
    public void keyTyped(KeyEvent arg0) {
        
        
        // TODO Auto-generated method stub
        System.out.println("键盘敲击了..arg0 = "+arg0.getKeyChar());
        jtf.setText("读书真好");
        System.out.println(jtf.getText());
    }
    //松开键
    @Override
    public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("键盘释放了..");
    }
    //按下键时调用。
    @Override
    public void keyPressed(KeyEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("键盘按下了..");
    }
};
    jbLogin.addActionListener(al);
    jbLogin.addMouseListener(ml);
    jtf.addKeyListener(kl);

}

\

相关文章
最新文章
热点推荐