?? qqclient.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.Date;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer;
import java.applet.*;
import java.io.*;
import java.util.*;
import javax.media.*;
class kehuduan extends Frame implements ActionListener
{ Label label1,label2;
TextField text1,text2;
Button button1,button2,button3;
InetAddress serveraddress;
String address,host;
String s=null;
String zaixian;
String zhujiao;
String filename,filedata;
DatagramPacket data_send=null,data_receive=null;
DatagramSocket send=null,receive=null;
SimpleDateFormat qq=new SimpleDateFormat("HH時mm分ss秒");
SimpleDateFormat QQ=new SimpleDateFormat("yyyy年MM月dd日HH時mm分ss秒");
Box basebox,boxh1,boxh2,boxh3;
Color color=Color.cyan;
kehuduan()
{super("飛鴻2.0-登錄界面");
setSize(100,300);
setBounds(300,300,300,140);
setVisible(true);
setResizable(false);
label1=new Label("用戶名");
label2=new Label("密碼");
text1=new TextField(20);
text2=new TextField(20);
text2.setEchoChar('*');
button1=new Button("登錄 ");
button2=new Button("注冊");
button3=new Button("修改飛鴻界面顏色");
label1.setBackground(color);
label2.setBackground(color);
button1.setBackground(color);
button2.setBackground(color);
button3.setBackground(color);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
basebox=Box.createHorizontalBox();
boxh1=Box.createVerticalBox();
boxh2=Box.createVerticalBox();
boxh3=Box.createHorizontalBox();
boxh3.add(button2);
boxh3.add(button3);
boxh1.add(label1);
boxh1.add(label2);
boxh1.add(button1);
boxh2.add(text1);
boxh2.add(text2);
boxh2.add(boxh3);
basebox.add(boxh1);
basebox.add(boxh2);
add(basebox);
validate();
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
try
{ InetAddress oo=InetAddress.getLocalHost();
address=oo.getHostAddress();
host=oo.getHostName();
serveraddress=InetAddress.getByName("10.10.145.88"); //服務器端IP地址為10.10.145.88
}
catch(UnknownHostException e6)
{
}
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button1)//輸入用戶名和密碼,發送給服務器端,進行登錄驗證
{
String s1=text1.getText();
zhujiao=s1;
String s2=text2.getText();
if(s1.equals("")||s2.equals(""))
{JOptionPane.showMessageDialog(this,"用戶名和密碼不能為空!","提示",JOptionPane.WARNING_MESSAGE);
return;
}
String nn="denglu"+','+s1+','+s2+','+address;
byte buffer[]=nn.getBytes();
try
{data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);//客戶端發送端口為9999,接收端口為8888
send=new DatagramSocket();
send.send(data_send);
}
catch(Exception e1)
{
}
byte data[]=new byte[88];
try
{data_receive=new DatagramPacket(data,data.length);
receive=new DatagramSocket(8888);
}
catch(Exception e1)
{
}
try
{receive.receive(data_receive);
int length=data_receive.getLength();
String message=new String(data_receive.getData(),0,length);
s=message;
zaixian=s;
}
catch(Exception e4)
{JOptionPane.showMessageDialog(this,"不能在同一個電腦上打開兩個客戶端!","提示",JOptionPane.WARNING_MESSAGE);
return;
}
if(s.indexOf("yonghumingbucunzai")!=-1)//驗證完畢,提交的用戶不存在
{JOptionPane.showMessageDialog(this,"該用戶不存在","提示",JOptionPane.WARNING_MESSAGE);
return;
}
else if(s.indexOf("mimachucuo")!=-1)//驗證完畢,提交的密碼錯誤
{JOptionPane.showMessageDialog(this,"密碼錯誤","提示",JOptionPane.WARNING_MESSAGE);
return;
}
else if(s.indexOf("dengluchenggong")!=-1)//登錄成功,進入主界面
{dispose();
qq jnj=new qq();
return;
}
}
else if(e.getSource()==button2)//客戶端請求注冊,進入注冊界面
{zhuce gg=new zhuce();
}
else if(e.getSource()==button3)//修改客戶端界面的顏色
{color=JColorChooser.showDialog(this,"飛鴻界面顏色選擇對話框",getBackground());
button1.setBackground(color);
button2.setBackground(color);
button3.setBackground(color);
label1.setBackground(color);
label2.setBackground(color);
}
}
class zhuce extends Frame implements ActionListener //注冊界面
{ Label label1,label2,label3,label4,label5,label6,label7,label8;
TextField text1,text2,text3,text4,text5,text6,text7,text8;
Button button1;
Box basebox,boxh1,boxh2;
zhuce()
{super("用戶注冊頁面");
setLayout(new BorderLayout());
setSize(300,300);
setBounds(300,300,300,300);
setVisible(true);
setBackground(color);
label1=new Label("用戶名");
label2=new Label("密碼");
label3=new Label("確認密碼");
label4=new Label("學院");
label5=new Label("班級");
label6=new Label("QQ號");
label7=new Label("手機號");
label8=new Label("出生日期");
text1=new TextField(20);
text2=new TextField(20);
text2.setEchoChar('*');
text3=new TextField(20);
text3.setEchoChar('*');
text4=new TextField(20);
text5=new TextField(20);
text6=new TextField(20);
text7=new TextField(20);
text8=new TextField(20);
text8.setText("19**-**-**");
button1=new Button("注冊");
button1.setBackground(color);
button1.addActionListener(this);
basebox=Box.createHorizontalBox();
boxh1=Box.createVerticalBox();
boxh2=Box.createVerticalBox();
boxh1.add(label1);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label2);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label3);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label4);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label5);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label6);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label7);
boxh1.add(Box.createVerticalStrut(4));
boxh1.add(label8);
boxh2.add(text1);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text2);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text3);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text4);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text5);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text6);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text7);
boxh2.add(Box.createVerticalStrut(4));
boxh2.add(text8);
boxh2.add(Box.createVerticalStrut(4));
basebox.add(boxh1);
basebox.add(boxh2);
add(basebox,BorderLayout.NORTH);
add(button1,BorderLayout.CENTER);
validate();
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{dispose();}
}
);
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button1)
{String s1=text1.getText();
String s2=text2.getText();
String s3=text3.getText();
String s4=text4.getText();
String s5=text5.getText();
String s6=text6.getText();
String s7=text7.getText();
String s8=text8.getText();
if(s1.equals("")||s2.equals("")||s3.equals("")||s4.equals("")||s5.equals("")||s6.equals("")||s7.equals("")||s8.equals(""))
{JOptionPane.showMessageDialog(this,"各選項不能為空!","提示",JOptionPane.WARNING_MESSAGE);}
else if(!s2.equals(s3))
{JOptionPane.showMessageDialog(this,"兩次輸入的密碼不一致,請重新輸入","提示",JOptionPane.WARNING_MESSAGE);}
else if((!s1.equals(""))&&(s2.equals(s3)))
{
try
{
String nn="zhuce"+','+s1+','+s2+','+s4+','+s5+','+s6+','+s7+','+s8;
byte buffer[]=nn.getBytes();
data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
send=new DatagramSocket();
send.send(data_send);
}
catch(Exception e3) {}
zhucejieshou();
}
}
}
public void zhucejieshou()//提交注冊信息完畢后,等待服務器端發來的響應
{
byte data[]=new byte[88];
try
{data_receive=new DatagramPacket(data,data.length);
receive=new DatagramSocket(8888);
}
catch(Exception e1) {}
try
{receive.receive(data_receive);
int length=data_receive.getLength();
String message=new String(data_receive.getData(),0,length);
s=message;
}
catch(Exception e4) {}
if(s.equals("zhucechenggong"))
{JOptionPane.showMessageDialog(this,"注冊成功","提示",JOptionPane.WARNING_MESSAGE);
return;
}
else if(s.equals("yiyougaiyonghu"))
{JOptionPane.showMessageDialog(this,"數據庫中已有該用戶,請更換用戶名","提示",JOptionPane.WARNING_MESSAGE);
return;
}
}
}
class qq extends Frame implements ActionListener,Runnable,ItemListener//主界面
{JButton button,button2,button3,button4,button5;
Label label1,label2,label3,label4,label5;
Choice choice,choice2;
TextArea text;
TextField text1,text2,text3,text4,text5,text6,text8,text9;
Box basebox,boxh1,boxh2,boxh3,boxh4,boxh5,boxh6;
Thread shuaxin,accept;
MenuBar menubar;
Menu menu1,menu2,menu3,menu4;
MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10;
Player player;
File file;
URL mediaurl;
BufferedReader bin;
FileReader file_reader;
BufferedWriter bout;
FileWriter tofile;
FileDialog filedialog_save=new FileDialog(this,"保存文件對話框",FileDialog.SAVE);
FileDialog filedialog_open=new FileDialog(this,"打開文件對話框",FileDialog.LOAD);
qq()
{super("飛鴻2.0(Special for Postgraduate Of Nanjing University Of Posts & Telecommunications)");
setSize(200,300);
setBounds(200,200,650,420);
setVisible(true);
setBackground(color);
setResizable(false);
menubar=new MenuBar();
menu1=new Menu("信息管理");
menu2=new Menu("關機選項");
menu3=new Menu("幫助");
menu4=new Menu("附加功能");
item1=new MenuItem("修改密碼");
item2=new MenuItem("修改個人信息");
item3=new MenuItem("退出飛鴻客戶端");
item4=new MenuItem("注銷");
item5=new MenuItem("關機");
item6=new MenuItem("重啟");
item7=new MenuItem("關于作者");
item8=new MenuItem("發送文件");
item9=new MenuItem("緣分測試");
item10=new MenuItem("萬年歷");
menu1.add(item1);
menu1.addSeparator();
menu1.add(item2);
menu1.addSeparator();
menu1.add(item3);
menu2.add(item4);
menu2.addSeparator();
menu2.add(item5);
menu2.addSeparator();
menu2.add(item6);
menu3.add(item7);
menu4.add(item8);
menu4.addSeparator();
menu4.add(item9);
menu4.addSeparator();
menu4.add(item10);
menubar.add(menu1);
menubar.add(menu4);
menubar.add(menu2);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -