[java]代码库
package com.qq.login;
/**
* QQ登录界面的设计
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import com.qq.MyClient.MyClient;
import com.qq.user.user;
public class qq_login extends JFrame implements ActionListener{
JPanel jp1,jp2,jp3,jp4;
JLabel jlb1,jlb2,jlb3,jlb4,jlb5;
JTextField jtf;
JPasswordField jpf;
JButton jb1,jb2,jb3;
JTabbedPane jtp;
public qq_login() {
jp1=new JPanel(new GridLayout(2,3));
jp2=new JPanel();
jb1=new JButton(new ImageIcon("dl.jpg"));
jb1.addActionListener(this);jb1.setActionCommand("a");
jb2=new JButton("取消");
jb2.addActionListener(this);jb2.setActionCommand("b");
jb3=new JButton("注册");
jb3.addActionListener(this);jb3.setActionCommand("c");
jp3=new JPanel();
jp4=new JPanel();
//处理中部
jlb5=new JLabel(new ImageIcon("bq.jpg"));
jlb1=new JLabel("QQ号码",JLabel.CENTER);
jlb2=new JLabel("QQ密码",JLabel.CENTER);
jlb3=new JLabel("申请号码");
jlb4=new JLabel("找回密码");
jlb4.setForeground(Color.BLUE);
jpf=new JPasswordField();
jtf=new JTextField();
jp1.add(jlb1);
jp1.add(jtf);
jp1.add(jlb3);
jp1.add(jlb2);
jp1.add(jpf);
jp1.add(jlb4);
jtp=new JTabbedPane();
jtp.add("QQ号码",jp1);
jtp.add("手机号码",jp3);
jtp.add("电子邮件",jp4);
//处理南部
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
this.setTitle("QQ2009");
this.setIconImage((new ImageIcon("qq.jpg")).getImage());
this.add(jlb5,new BorderLayout().NORTH);
this.add(jtp);
this.add(jp2,new BorderLayout().SOUTH);
this.setSize(345,220);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new qq_login();
}
@Override
public void actionPerformed(ActionEvent e) {
if("a".equals(e.getActionCommand())){
user u=new user();
u.setUserId(jtf.getText());
u.setUserPd(new String(jpf.getPassword()));
if(new MyClient().fistLogin(u)){
new qq_FriendList(u.getUserId());
this.dispose();
}else{
JOptionPane.showConfirmDialog(this,"帐号或密码错误","提示",JOptionPane.CANCEL_OPTION);
}
}else if("b".equals(e.getActionCommand())){
System.exit(0);
}else if("c".equals(e.getActionCommand())){
Desktop ds=Desktop.getDesktop();
try {
ds.browse(new URI("http://tts6.tarena.com.cn"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}