📄 logintest.java
字号:
package com.hs ;
import java.awt.* ;
import javax.swing.* ;
import java.awt.event.* ;
import java.net.* ;
public class LogInTest extends JFrame implements ActionListener {
JComboBox t_username = new JComboBox() ;
JPasswordField t_password = new JPasswordField() ;
JComboBox t_phone = new JComboBox() ;
JPasswordField t_phoneword = new JPasswordField() ;
LogIn2Test lg2 = new LogIn2Test() ;
boolean bl = true ;//决定设置选项是否是否被显示
LogIn3Test lg3 = new LogIn3Test() ;
boolean bl2 = true ;
//构造函数
LogInTest(String title) {
this.setTitle(title) ;
this.setSize(420 , 280) ;
this.setResizable(false) ;
int width = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() ;
int height = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight() ;
this.setLocation((width - 420) / 2 , (height - 380) / 2) ;
//new 一大堆组件
ImageIcon im = new ImageIcon("qq.jpg") ;
JLabel jim = new JLabel(im) ;
JButton b_ok = new JButton("登陆") ;
JButton b_unok = new JButton("取消") ;
JButton b_shezhi = new JButton("设置↓") ;
JLabel l_username = new JLabel(" QQ号码") ;
JLabel l_password = new JLabel(" 请输入密码") ;
JButton b_missword = new JButton("忘记密码") ;
JButton b_baohuword = new JButton("申请密码保护") ;
JLabel l_phone = new JLabel(" 手机号码") ;
JLabel l_phoneword = new JLabel(" 手机密码") ;
JButton b_missphone = new JButton("忘记手机密码") ;
JButton b_getphoneword = new JButton("短信找回") ;
JButton b_zhuce = new JButton("注册新用户") ;
t_username.setEditable(true) ;
t_phone.setEditable(true) ;
//注册按钮事件监听
b_ok.addActionListener(this) ;
b_unok.addActionListener(this) ;
b_shezhi.addActionListener(this) ;
b_zhuce.addActionListener(this) ;
//QQ登陆面板
JPanel p_qq = new JPanel() ;
p_qq.setLayout(new GridLayout(2 , 3 , 5 , 10)) ;
p_qq.add(l_username) ;
p_qq.add(t_username) ;
p_qq.add(b_missword) ;
p_qq.add(l_password) ;
p_qq.add(t_password) ;
p_qq.add(b_baohuword) ;
//手机登陆面板
JPanel p_phone = new JPanel() ;
p_phone.setLayout(new GridLayout(2 , 3 , 5 , 10)) ;
p_phone.add(l_phone) ;
p_phone.add(t_phone) ;
p_phone.add(b_missphone) ;
p_phone.add(l_phoneword) ;
p_phone.add(t_phoneword) ;
p_phone.add(b_getphoneword) ;
//设置多选框
JCheckBox c_jizhumima = new JCheckBox("记住密码") ;
JCheckBox c_yinshendenglu = new JCheckBox("隐身登录") ;
JPanel p_denglufangshi = new JPanel() ;
p_denglufangshi.setLayout(new FlowLayout()) ;
p_denglufangshi.add(c_jizhumima) ;
p_denglufangshi.add(c_yinshendenglu) ;
//设置双选者登陆面板
JTabbedPane t = new JTabbedPane(JTabbedPane.NORTH) ;
t.add("QQ号登陆" ,p_qq) ;
t.add("手机登陆",p_phone) ;
//设置登陆取消面板
JPanel p_dengluandquxiao = new JPanel() ;
p_dengluandquxiao.setLayout(new FlowLayout()) ;
p_dengluandquxiao.add(b_shezhi) ;
p_dengluandquxiao.add(b_ok) ;
p_dengluandquxiao.add(b_unok) ;
p_dengluandquxiao.add(b_zhuce) ;
//合并登陆取消面板和多选框面板
JPanel p_denglus = new JPanel() ;
p_denglus.setLayout(new GridLayout(2 , 1)) ;
p_denglus.add(p_denglufangshi) ;
p_denglus.add(p_dengluandquxiao) ;
//设置窗体
this.setLayout(new BorderLayout()) ;
this.add(jim , BorderLayout.NORTH) ;
this.add(t , BorderLayout.CENTER) ;
this.add(p_denglus , BorderLayout.SOUTH) ;
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true) ;
LogInTest l = new LogInTest("QQ登录") ;
l.setVisible(true) ;
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("设置↓")) {
if(bl) {
lg2.setVisible(true) ;
bl = false ;
}else{
lg2.setVisible(false) ;
bl = true ;
}
}
if(e.getActionCommand().equals("注册新用户")) {
if(bl2) {
lg3.setVisible(true) ;
bl2 = false ;
}else{
lg3.setVisible(false) ;
bl2 = true ;
}
}
if(e.getActionCommand().equals("登陆")) {
try {
MyNet mn = new MyNet() ;
Socket s = new Socket("127.0.0.1" , 8001) ;
//把用户名和密码发送到服务端
mn.send(s , t_username.getSelectedItem() + "==hs==" + t_password.getText()) ;
//接收服务端返回的确认信息
if(mn.receive(s).equals("ok")) {
QQmain qq = new QQmain(t_username.getSelectedItem().toString() , s) ;
qq.setVisible(true) ;
this.setVisible(false) ;
System.out.println ("登陆成功 欢迎!") ;
}else {
JOptionPane.showMessageDialog(this , "滚蛋") ;
}
}
catch (Exception ex) {
ex.printStackTrace() ;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -