日期:2014-05-20 浏览次数:20868 次
package myprojects.testdialog;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import study.demo.listenmouse;
/**
* 仿QQ登录界面
*
* @author jiang
*/
public class CopyOfGUIQQ extends JFrame {
// 用户名
private JTextField username;
// 密码
private JPasswordField password;
// 小容器
private JLabel jl1;
private JLabel jl2;
private JLabel jl3;
private JLabel jl4;
// 小按钮
private JButton bu1;
private JButton bu2;
private JButton bu3;
// 复选框
private JCheckBox jc1;
private JCheckBox jc2;
// 列表框
private JComboBox jcb;
listenmouse listen;
public class listenmouse extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
username.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
/*
* 构造方法
*/
public CopyOfGUIQQ() {
listen = new listenmouse();
// 设置窗口标题
//this.setTitle("QQ2012正式版");
// 窗体组件初始化
init();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置布局方式为绝对定位
this.setLayout(null);
this.setBounds(0, 0, 355, 165);
// 窗体大小不能改变
this.setResizable(false);
// 居中显示
this.setLocationRelativeTo(null);
// 窗体可见
this.setVisible(true);
this.setFocusable(true);
}
/*
* 初始化方法
*/
public void init() {
// 创建一个容器
Container con = this.getContentPane();
jl1 = new JLabel();
jl1.setBounds(0, 0, 355, 265);
// 用户号码登录输入框
username = new JTextField(5);
username.setBounds(140, 30, 150, 20);
username.addMouseListener(listen);
// 用户号码登录输入框旁边的文字
jl3 = new JLabel("注册账号");
jl3.setBounds(50, 30, 70, 20);
// 按钮设定
bu1 = new JButton("登录");
bu1.setBounds(240, 80, 65, 20);
bu3 = new JButton("设置");
bu3.setBounds(150, 80, 65, 20);
jl1.add(jl3);
jl1.add(bu1);
jl1.add(bu3);
con.add(jl1);
con.add(username);
}
public static void main(String[] args) {
// 实例化对象
CopyOfGUIQQ qq = new CopyOfGUIQQ();
}
}