📄 qqclient.java
字号:
{
nn=nn+filename+',';
bin=new BufferedReader(file_reader);
while((q=bin.readLine())!=null)
{nn=nn+q+'\n';
}
bin.close();
file_reader.close();
}
else
{JOptionPane.showMessageDialog(this,"只支持文本格式的传输!","提示",JOptionPane.WARNING_MESSAGE);
return;
}
}
catch(IOException e2) {}
}
try
{
byte buffer[]=nn.getBytes();
if(buffer.length>65000)
{JOptionPane.showMessageDialog(this,"对不起,你传送的文件太大!","提示",JOptionPane.WARNING_MESSAGE);
return;
}
else
{
data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
send=new DatagramSocket();
send.send(data_send);
JOptionPane.showMessageDialog(this,"发送离线文件成功!","提示",JOptionPane.WARNING_MESSAGE);
}
}
catch(Exception e3) {}
}
}
else if(e.getSource()==item9)
{yuanfenceshi kk=new yuanfenceshi();
}
else if(e.getSource()==item10)
{wannianli kk=new wannianli();
}
}
public void run()
{ while(true)
{if(Thread.currentThread()==shuaxin)//向服务器提出刷新在线用户和离线用户
{try
{
String nn="scanonline";
byte buffer[]=nn.getBytes();
data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
send=new DatagramSocket();
send.send(data_send);
}
catch(Exception e3) {}
try
{shuaxin.sleep(10000);
}
catch(InterruptedException e4) {}
}
else if(Thread.currentThread()==accept)//接收数据
{ String gg="",xx="";
byte data[]=new byte[8888888];
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);
gg=message;
}
catch(Exception e4) {}
StringTokenizer fenxi=new StringTokenizer(gg,",");
while(fenxi.hasMoreTokens())
{String str=fenxi.nextToken();
xx=str;
break;
}
if(xx.indexOf("onlineqq")!=-1) //接收到的数据为所有在线用户的数据
{String nn=gg.substring(8);
choice.removeAll();
StringTokenizer fenxi2=new StringTokenizer(nn,",");
while(fenxi2.hasMoreTokens())
{String dd=fenxi2.nextToken();
choice.add(dd);
}
}
else if(xx.indexOf("suoyouyonghu")!=-1) //接收到的数据为所有用户的数据
{String nn=gg.substring(12);
choice2.removeAll();
StringTokenizer fenxi2=new StringTokenizer(nn,",");
while(fenxi2.hasMoreTokens())
{String dd=fenxi2.nextToken();
choice2.add(dd);
}
for(int i=0;i<choice.getItemCount();i++)
for(int j=0;j<choice2.getItemCount();j++)
{choice.select(i);
String a1=choice.getSelectedItem();
choice2.select(j);
String a2=choice2.getSelectedItem();
if(a1.equals(a2))
{choice2.remove(j);}
}
}
else if(xx.indexOf("liaotianshuju")!=-1)//接收到的数据为聊天数据
{
try
{ file=new File("C:/WINDOWS/Media","msg.wav");
mediaurl=file.toURL();
player=Manager.createPlayer(mediaurl);
player.prefetch();
player.start();
}
catch(Exception e3){}
String nn=gg.substring(13);
String q1="",q2="";
StringTokenizer fenxi2=new StringTokenizer(nn,",");
int k=0;
while(fenxi2.hasMoreTokens())
{ String str=fenxi2.nextToken();
k++;
if(k==1) {q1=str;}
else if(k==2){q2=str;}
}
Date date1=new Date();
text.append(q1+"在"+qq.format(date1)+"对你说:"+'\n'+q2+'\n'+'\n'+'\n');
}
else if(xx.indexOf("gerenxinxi")!=-1)//接收到的数据为查询的用户信息
{ String nn=gg.substring(11);
String q1="",q2="",q3="",q4="",q5="",q6="";
StringTokenizer fenxi2=new StringTokenizer(nn,",");
int k=0;
while(fenxi2.hasMoreTokens())
{ String str=fenxi2.nextToken();
k++;
if(k==1) {q1=str;}
else if(k==2){q2=str;}
else if(k==3){q3=str;}
else if(k==4){q4=str;}
else if(k==5){q5=str;}
else if(k==6){q6=str;}
}
text1.setText("用户名:"+q1);
text2.setText("学院:"+q2);
text3.setText("班级:"+q3);
text4.setText("QQ号:"+q4);
text5.setText("手机号:"+q5);
text6.setText("出生日期:"+q6);
}
else if(xx.indexOf("broadcast")!=-1)//接收到的数据为服务器的广播
{ String nn=gg.substring(10);
Date date2=new Date();
text.append("服务器在"+qq.format(date2)+"广播:"+'\n'+nn+'\n');
}
else if(xx.indexOf("xiugaigerenmimachenggong")!=-1)//接收到的数据为服务器发来的修改密码成功提示
{JOptionPane.showMessageDialog(this,"修改个人密码成功!","提示",JOptionPane.WARNING_MESSAGE);
}
else if(xx.indexOf("xinxixiugaichenggong")!=-1)//接收到的数据为服务器发来的修改个人信息成功提示
{JOptionPane.showMessageDialog(this,"修改个人信息成功!","提示",JOptionPane.WARNING_MESSAGE);
}
else if(xx.indexOf("filetransfer")!=-1)//接收到的数据为文件数据
{ String nn=gg.substring(13);
StringTokenizer fenxi2=new StringTokenizer(nn,",");
int k=0;
while(fenxi2.hasMoreTokens())
{ String str=fenxi2.nextToken();
k++;
if(k==1) {filename=str;}
}
filedata=gg.substring(14+filename.length());
wenjian hh=new wenjian();
}
else if(xx.indexOf("liuyan")!=-1)//接收到的数据为留言
{String nn=gg.substring(7);
String zhujiao="";
String message="";
String time="";
StringTokenizer fenxi2=new StringTokenizer(nn,",");
int k=0;
while(fenxi2.hasMoreTokens())
{ String str=fenxi2.nextToken();
k++;
if(k==1) {zhujiao=str;}
else if(k==2) {message=str;}
else if(k==3) {time=str;}
}
text.append(zhujiao+"在"+time+"给你留言:"+'\n'+message+'\n'+'\n');
}
try
{accept.sleep(100);
}
catch(InterruptedException e4) {}
}
}
}
class mima extends Frame implements ActionListener//修改密码界面
{Label label1,label2;
TextField text1,text2;
Button button;
Box basebox,boxh1,boxh2;
mima()
{super("个人登录密码修改页面");
setSize(200,200);
setBounds(300,300,280,120);
setVisible(true);
setBackground(color);
label1=new Label("密码");
label2=new Label("确认密码");
text1=new TextField(20);
text2=new TextField(20);
text1.setEchoChar('*');
text2.setEchoChar('*');
button=new Button("修改");
button.setBackground(color);
button.addActionListener(this);
basebox=Box.createVerticalBox();
boxh1=Box.createHorizontalBox();;
boxh2=Box.createHorizontalBox();;
boxh1.add(label1);
boxh1.add(Box.createHorizontalStrut(22));
boxh1.add(text1);
boxh2.add(label2);
boxh2.add(Box.createHorizontalStrut(1));
boxh2.add(text2);
basebox.add(boxh1);
basebox.add(boxh2);
basebox.add(button);
add(basebox);
validate();
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{dispose();}
}
);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button)
{String s1=text1.getText();
String s2=text2.getText();
if(s1.equals("")||s2.equals(""))
{JOptionPane.showMessageDialog(this,"密码不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else if(!s1.equals(s2))
{JOptionPane.showMessageDialog(this,"两次输入的密码不一致,请重新输入!","提示",JOptionPane.WARNING_MESSAGE);
}
else
{try
{
String nn="xiugaigerenmima"+','+zhujiao+','+s1;
byte buffer[]=nn.getBytes();
data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
send=new DatagramSocket();
send.send(data_send);
dispose();
}
catch(Exception e3) {}
}
}
}
}
class genggaixinxi extends Frame implements ActionListener//修改个人信息界面
{Label label1,label2,label3,label4,label5;
TextField text1,text2,text3,text4,text5;
Button button;
Box basebox,boxh1,boxh2;
genggaixinxi()
{super("个人信息修改页面");
setLayout(new BorderLayout());
setSize(300,300);
setBounds(300,300,300,200);
setVisible(true);
setBackground(color);
label1=new Label("学院");
label2=new Label("班级");
label3=new Label("QQ号");
label4=new Label("手机号");
label5=new Label("出生日期");
text1=new TextField(20);
text2=new TextField(20);
text3=new TextField(20);
text4=new TextField(20);
text5=new TextField(20);
button=new Button("修改");
button.setBackground(color);
button.addActionListener(this);
basebox=Box.createHorizontalBox();
boxh1=Box.createVerticalBox();
boxh2=Box.createVerticalBox();
boxh1.add(label1);
boxh1.add(Box.createVerticalStrut(2));
boxh1.add(label2);
boxh1.add(Box.createVerticalStrut(2));
boxh1.add(label3);
boxh1.add(Box.createVerticalStrut(2));
boxh1.add(label4);
boxh1.add(Box.createVerticalStrut(2));
boxh1.add(label5);
boxh2.add(text1);
boxh2.add(Box.createVerticalStrut(2));
boxh2.add(text2);
boxh2.add(Box.createVerticalStrut(2));
boxh2.add(text3);
boxh2.add(Box.createVerticalStrut(2));
boxh2.add(text4);
boxh2.add(Box.createVerticalStrut(2));
boxh2.add(text5);
basebox.add(boxh1);
basebox.add(boxh2);
basebox.add(button);
add(basebox,BorderLayout.NORTH);
add(button,BorderLayout.CENTER);
validate();
addWindowListener (new WindowAdapter()
{public void windowClosing(WindowEvent e)
{dispose();}
}
);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button)
{String s1=text1.getText();
String s2=text2.getText();
String s3=text3.getText();
String s4=text4.getText();
String s5=text5.getText();
if(s1.equals("")||s2.equals("")||s3.equals("")||s4.equals("")||s5.equals(""))
{ JOptionPane.showMessageDialog(this,"各选项不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else
try
{
String nn="xiugaigerenxinxi"+','+zhujiao+','+s1+','+s2+','+s3+','+s4+','+s5;
byte buffer[]=nn.getBytes();
data_send=new DatagramPacket(buffer,buffer.length,serveraddress,9999);
send=new DatagramSocket();
send.send(data_send);
dispose();
}
catch(Exception e3) {}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -