package com.ibm.testQQ;
/**
* 作者雪狼
* 内容:QQ登录界面
* 时间:2009-12-20
* */
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
public class TestQQ implements WindowListener,MouseListener,ActionListener{
private Label a;
private Frame f;
private JButton load2;
private JButton load;
private JPasswordField tf2;
private TextField tf;
//设置一个容器,用于盛装用户信息
private QQinfo qqinfo_3;
public TestQQ(QQinfo info)
{
//将接住的容器中的信息转入自己所设置的容器中
qqinfo_3 = info;
//创建一个顶级容器
f = new Frame("QQ2009");
f.setLayout(null);
f.setBounds(200, 200, 340, 250);
//锁定窗口大小,不准用户改变窗体大小
f.setResizable(false);
//下拉列表的创建
Choice c = new Choice();
c.add("我在线");
c.add("隐身");
c.add("忙碌");
c.add("离线");
c.setLocation(60, 90);
c.setSize(37, 20);
// ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
// sp.setSize(20, 27);
// sp.setLocation(240, 15);
//使布局管理器可以自由调整
// f.setLayout(null);
//导入一个图片,设为背景
JLabel qq = new JLabel( new ImageIcon(this.getClass().getResource("qq6.JPG")));
qq.setSize(340, 90);
qq.setLocation(0, 20);
//改变窗体上的图标
Toolkit image = f.getToolkit();
Image img = image.createImage(this.getClass().getResource("qq.GIF"));
f.setIconImage(img);
//使容器的布局可以自由调整,并进行布局的划分
Panel p1 = new Panel(null);
p1.setBounds(0, 0, 350, 90);
p1.setBackground(new Color(49,203,254));
Panel p2 = new Panel(null);
p2.setBounds(0, 80, 350, 120);
p2.setBackground(new Color(231,247,254));
Panel p3 = new Panel(null);
p3.setBounds(0, 200, 350, 50);
p3.setBackground(new Color(189,227,255));
//设置文本,添加字条
Label lb = new Label("账 号:");
// lb.setBounds(25, 10, 40, 40);
lb.setSize(40, 40);
lb.setLocation(25, 10);
Label lb2 = new Label("密 码:");
// lb.setBounds(25, 30, 40, 40);
lb2.setSize(40, 70);
lb2.setLocation(25, 30);
a = new Label("注册新账号");
a.setSize(80, 40);
a.setLocation(260, 10);
Label a1 = new Label("取回密码");
a1.setSize(80, 40);
a1.setLocation(260, 45);
//设置文本框
// try
// {
//
// tf = new TextField();
// }catch(Exception e)
// {
// System.out.println("对不起,输入错误!");
// }
tf = new TextField();
tf.setSize(200,27);
tf.setLocation(60, 15);
tf2 = new JPasswordField();
tf2.setSize(200,27);
tf2.setLocation(60, 50);
//设置文本,并添加字条
Label a2 = new Label("状态:");
a2.setSize(30, 60);
a2.setLocation(25, 70);
Label a3 = new Label("记住密码");
a3.setSize(60, 40);
a3.setLocation(110, 80);
Label a4 = new Label("自动登录");
a4.setSize(60, 40);
a4.setLocation(180, 80);
//设置重复选项框,并使其自动勾选
Checkbox box = new Checkbox();
box.setLocation(100, 80);
box.setSize(40, 40);
box.setState(true);
//设置复选框
Checkbox box1 = new Checkbox();
box1.setLocation(170, 80);
box1.setSize(40, 40);
//设置按钮
load = new JButton("设 置");
load.setSize(80, 30);
load.setLocation(15,12);
p3.add(load);
load2 = new JButton("登 录");
load2.setSize(80, 30);
load2.setLocation(255,12);
p3.add(load2);
//设置单选框,并使其自动勾选
Checkbox box2 = new Checkbox();
CheckboxGroup b = new CheckboxGroup();
box2.setCheckboxGroup(b);
box2.setLocation(60, 90);
box2.setSize(20, 20);
box2.setState(true);
//组件的添加和显示
// sp.add(tf);
// sp.add(tf2);
// p2.add(sp);
//f.add(sp);
p2.add(c);
p2.add(a2);
p2.add(a3);
p2.add(a4);
p2.add(box);
p2.add(box1);
p2.add(box2);
p2.add(a);
p2.add(a1);
p2.add(tf);
p2.add(tf2);
p2.add(lb);
p2.add(lb2);
p1.add(qq);
f.add(p1);
f.add(p2);
f.add(p3);
//设置窗口监听器
load.addActionListener(this);
load2.addActionListener(this);
a.addMouseListener(this);
f.addWindowListener(this);
//显示窗体
f.setVisible(true);
}
public static void main(String[] agrs)
{
new TestQQ(null);
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// 监听窗口的关闭
System.exit(0);
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent arg0) {
if(arg0.getSource() == a)
{
new ListKey();
f.dispose();
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == load)
{
}else if(arg0.getSource() == load2)
{
int num = tf.getX();
String pass = tf2.getText();
//将信息装入容器中
qqinfo_3.setIntoNum(num);
qqinfo_3.setIntopass(pass);
new Load(qqinfo_3);
f.dispose();
}
}
}