?? 登錄界面.java
字號:
/*
* 登錄界面.java
*
* Created on 2007年5月1日, 下午6:48
*/
package 客戶端程序包;
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
/**
*
* @author 王綠春 8000104023 南昌大學(xué)軟件學(xué)院045班
*/
public class 登錄界面 extends javax.swing.JFrame {
/** Creates new form 登錄界面 */
public 登錄界面(Socket client_soke) {
initComponents();
this.Client_Socket=client_soke;
this.setBounds(450,220,325,242);
ImageIcon image=new ImageIcon("picture/qq.gif");
Picture.setIcon(image);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代碼 ">//GEN-BEGIN:initComponents
private void initComponents() {
登錄框面板 = new javax.swing.JPanel();
QQ號碼 = new javax.swing.JLabel();
密碼 = new javax.swing.JLabel();
QQ號碼輸入框 = new javax.swing.JTextField();
申請?zhí)柎a = new javax.swing.JButton();
取消 = new javax.swing.JButton();
自動登錄 = new javax.swing.JCheckBox();
隱身登錄 = new javax.swing.JCheckBox();
密碼輸入框 = new javax.swing.JPasswordField();
登錄 = new javax.swing.JButton();
消息框 = new javax.swing.JLabel();
Picture = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("QQ\u7528\u6237\u767b\u5f55");
setBackground(new java.awt.Color(102, 102, 255));
setForeground(new java.awt.Color(102, 102, 255));
setName("\u767b\u5f55\u6846");
setResizable(false);
登錄框面板.setBackground(new java.awt.Color(102, 102, 255));
QQ號碼.setText("QQ\u53f7\u7801\uff1a");
密碼.setText("QQ\u5bc6\u7801\uff1a");
申請?zhí)柎a.setText("\u7533\u8bf7\u53f7\u7801");
申請?zhí)柎a.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
申請?zhí)柎aMouseClicked(evt);
}
});
取消.setText("\u53d6\u6d88");
取消.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
取消MouseClicked(evt);
}
});
自動登錄.setBackground(new java.awt.Color(255, 255, 255));
自動登錄.setText("\u81ea\u52a8\u767b\u5f55");
自動登錄.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
自動登錄.setMargin(new java.awt.Insets(0, 0, 0, 0));
隱身登錄.setBackground(new java.awt.Color(255, 255, 255));
隱身登錄.setText("\u9690\u8eab\u767b\u5f55");
隱身登錄.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
隱身登錄.setMargin(new java.awt.Insets(0, 0, 0, 0));
登錄.setText("\u767b\u5f55");
登錄.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
登錄ActionPerformed(evt);
}
});
登錄.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
登錄MouseClicked(evt);
}
});
Picture.setFont(new java.awt.Font("宋體", 1, 36));
Picture.setForeground(new java.awt.Color(0, 204, 0));
Picture.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
org.jdesktop.layout.GroupLayout 登錄框面板Layout = new org.jdesktop.layout.GroupLayout(登錄框面板);
登錄框面板.setLayout(登錄框面板Layout);
登錄框面板Layout.setHorizontalGroup(
登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(登錄框面板Layout.createSequentialGroup()
.addContainerGap()
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(登錄框面板Layout.createSequentialGroup()
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(密碼)
.add(QQ號碼))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, 登錄框面板Layout.createSequentialGroup()
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, 登錄, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, 自動登錄, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(取消, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(隱身登錄, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(11, 11, 11))
.add(org.jdesktop.layout.GroupLayout.LEADING, 登錄框面板Layout.createSequentialGroup()
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, 密碼輸入框)
.add(org.jdesktop.layout.GroupLayout.LEADING, QQ號碼輸入框, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(申請?zhí)柎a, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))))
.add(org.jdesktop.layout.GroupLayout.TRAILING, 消息框, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 213, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(19, 19, 19))
.add(Picture, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
);
登錄框面板Layout.setVerticalGroup(
登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(登錄框面板Layout.createSequentialGroup()
.add(Picture, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(23, 23, 23)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(QQ號碼)
.add(QQ號碼輸入框, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(申請?zhí)柎a))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(密碼)
.add(密碼輸入框, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(15, 15, 15)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(自動登錄)
.add(隱身登錄))
.add(15, 15, 15)
.add(登錄框面板Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(登錄)
.add(取消))
.add(19, 19, 19)
.add(消息框)
.addContainerGap())
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(登錄框面板, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(登錄框面板, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void 申請?zhí)柎aMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_申請?zhí)柎aMouseClicked
申請界面 Apply=new 申請界面(Client_Socket);
Apply.setVisible(true);
new Thread(Apply).start();
}//GEN-LAST:event_申請?zhí)柎aMouseClicked
private void 登錄MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_登錄MouseClicked
// TODO 將在此處添加您的處理代碼:
QQNumber=QQ號碼輸入框.getText();
QQPassword=new String(密碼輸入框.getPassword());
if(隱身登錄.isSelected()){
IsHideRegister="1"; //1表示隱身登錄
System.out.println(IsHideRegister);
}
else{
IsHideRegister="0";
System.out.println("zhuantai"+IsHideRegister);
}
if(QQNumber.length()!=9){
JOptionPane.showMessageDialog(null,"QQ號碼必須為9位數(shù)字!","錯誤!",JOptionPane.WARNING_MESSAGE);
return;
}
RegisterMessage="0"+IsHideRegister+QQNumber+QQPassword;
消息框.setText("正在連接服務(wù)器......");
SendAndReceive Send=new SendAndReceive(Client_Socket,RegisterMessage);
Send.SendMessage();
SendAndReceive Receive=new SendAndReceive(Client_Socket);
String CheckMessage=Receive.ReceiveMessage();
if(CheckMessage.startsWith("E")){
JOptionPane.showMessageDialog(null,"該用戶已經(jīng)登錄!","錯誤!",JOptionPane.WARNING_MESSAGE);
}
else if(CheckMessage.startsWith("N")){
JOptionPane.showMessageDialog(null,"不存在該用戶!","錯誤!",JOptionPane.WARNING_MESSAGE);
}
else if(CheckMessage.startsWith("P")){
JOptionPane.showMessageDialog(null,"密碼錯誤!","錯誤!",JOptionPane.WARNING_MESSAGE);
}
else if(CheckMessage.startsWith("K")){
System.out.println(CheckMessage);
Information=CheckMessage.substring(1);
IsSuccessfull=true;
System.out.println("成功注冊");
}
if(this.GetState()){
this.setVisible(false);
//System.out.print("列表"+this.GetList());
System.out.println("登錄界面的SOCKET:"+Client_Socket);
好友界面 FriendFrame= new 好友界面(Client_Socket,this.GetQQNumber(),Information,IsHideRegister,QQPassword);
FriendFrame.setVisible(true);
new Thread(FriendFrame).start();
this.dispose();
}
}//GEN-LAST:event_登錄MouseClicked
private void 登錄ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_登錄ActionPerformed
// TODO 將在此處添加您的處理代碼:
}//GEN-LAST:event_登錄ActionPerformed
private void 取消MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_取消MouseClicked
// TODO 將在此處添加您的處理代碼:
this.dispose();
}//GEN-LAST:event_取消MouseClicked
public String GetQQNumber(){
return this.QQNumber;
}
public boolean GetState(){
return this.IsSuccessfull;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
String HostIP="127.0.0.1";
try{
Socket ClientSocket=new Socket(HostIP,6666);
登錄界面 RegisterFrame=new 登錄界面(ClientSocket);
RegisterFrame.setVisible(true);
System.out.println("通過!");
}catch( IOException e){
JOptionPane.showMessageDialog(null,"連接服務(wù)器失敗!","錯誤!",JOptionPane.WARNING_MESSAGE);
System.out.println("連接服務(wù)器失敗!");
}
}//run()
});
}
// 變量聲明 - 不進(jìn)行修改//GEN-BEGIN:variables
private javax.swing.JLabel Picture;
private javax.swing.JLabel QQ號碼;
private javax.swing.JTextField QQ號碼輸入框;
private javax.swing.JButton 取消;
private javax.swing.JLabel 密碼;
private javax.swing.JPasswordField 密碼輸入框;
private javax.swing.JLabel 消息框;
private javax.swing.JButton 申請?zhí)柎a;
private javax.swing.JButton 登錄;
private javax.swing.JPanel 登錄框面板;
private javax.swing.JCheckBox 自動登錄;
private javax.swing.JCheckBox 隱身登錄;
// 變量聲明結(jié)束//GEN-END:variables
private String QQNumber=null;
private String QQPassword=null;
//private boolean IsAutoRegister=false;
private boolean IsSuccessfull=false;
private String IsHideRegister=null;
private Socket Client_Socket=null;
//private String HostIP="192.168.250.18";
private String RegisterMessage=null;
//private PrintWriter ClientOut=null;
//private BufferedReader ClientIn=null;
private String Information=null;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -