//LoginInterface.java
package com.im.client.view;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import com.im.client.common.*;
import com.im.client.model.*;
public class LoginInterface extends JFrame implements ActionListener{
//定义组件
JPanel jp1;
JPanel jp2;
JPanel jp3;
JLabel jb1 = null;
JTextField userName = null;
JLabel jb2 = null;
JPasswordField password = null;
JButton login = null;
JButton register = null;
//构造函数
public LoginInterface(){
//创建组件
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jb1 = new JLabel("IM号码",JLabel.CENTER);
userName = new JTextField(20);
jb2 = new JLabel("密 码",JLabel.CENTER);
password = new JPasswordField(20);
login = new JButton("登录");
register = new JButton("注册");
//设置组件属性
jb1.setFont(new Font("宋体",Font.PLAIN,14));
jb2.setFont(new Font("宋体",Font.PLAIN,14));
userName.setFont(new Font("宋体",Font.PLAIN,18));
password.setFont(new Font("宋体",Font.PLAIN,18));
login.setFont(new Font(null,Font.PLAIN,14));
register.setFont(new Font(null,Font.PLAIN,14));
login.setBackground(Color.white);
register.setBackground(Color.white);
//组件事件
login.addActionListener(this);
//添加组件
jp1.add(jb1);
jp1.add(userName);
jp2.add(jb2);
jp2.add(password);
jp3.add(login);
jp3.add(register);
this.add(jp1);
this.add(jp2);
this.add(jp3);
//设置窗口属性
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screensize.getWidth();
int height = (int)screensize.getHeight();
this.setIconImage((new ImageIcon("images/icon.gif")).getImage());
this.setTitle("IM登陆");
this.setSize(260,200);
this.setLocation(width/2-130,height/2-200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setLayout(new GridLayout(3,1));
//显示窗口
this.setVisible(true);
}
public static void main(String[] args){
LoginInterface l = new LoginInterface();
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == login){