📄 好友界面.java
字号:
//System.out.print("wo"+this.GetList()[j].length());
String FriendInfor=St.nextToken();
String icon=FriendInfor.substring(0,1);
String Number=FriendInfor.substring(1,10);
String NicName=FriendInfor.substring(10);
ImageIcon image=new ImageIcon("picture/"+icon+".gif");
JLabel label=new JLabel(NicName+Number,image,JLabel.LEFT);
//label.setBackground(Color.gray);
label.setEnabled(false);
StringTokenizer Sk=new StringTokenizer(WhoIsOnLine.substring(2),"#");
while(Sk.hasMoreTokens()){
if(Sk.nextToken().equals(Number)){
label.setEnabled(true);
}
}
FriendList.addElement(label);
}
}catch(NullPointerException e){
System.out.println("错在这里呀! 猪头!");
}
this.好友栏.setListData(FriendList);
this.好友栏.setCellRenderer(new MyListCellRenderer());
}
public void SetGroups(){
try{
StringTokenizer St=new StringTokenizer(GroupList.substring(1),"$");
while(St.hasMoreTokens()){
String GroupInfor=St.nextToken();
String icon=GroupInfor.substring(0,1);
String Number=GroupInfor.substring(1);
ImageIcon image=new ImageIcon("picture/"+icon+".gif");
JLabel label=new JLabel(Number,image,JLabel.LEFT);
Groups.addElement(label);
}
}catch(NullPointerException e){
System.out.println("错在这里呀! 猪头!+猪头");
}
this.群.setListData(Groups);
this.群.setCellRenderer(new MyListCellRenderer());
}
public void ReadLeavingMessage(){
System.out.println("留言是:"+LeavingMessage);
if(LeavingMessage.length()!=1){
StringTokenizer Sk=new StringTokenizer(LeavingMessage.substring(1),"$");
while(Sk.hasMoreTokens()){
String Msg=Sk.nextToken();
String number=Msg.substring(0,9);
System.out.println("号码是:"+number);
String Message=Msg.substring(9);
System.out.println("消息:"+Message);
this.InforList.AddNewMember(number,Message);
boolean IsFriend=false;
int j=0;
System.out.println("列表x长度:"+FriendList.size());
for(j=0;j<FriendList.size();j++){
JLabel lab=(JLabel) 好友栏.getModel().getElementAt(j);
String s=lab.getText().substring(lab.getText().length()-9);
System.out.println("得到的号码:"+s);
System.out.println(j);
if(s.equals(number)){
IsFriend=true;
System.out.println("给我进来");
this.好友栏.setSelectedIndex(j);
break;
}
}
if(!IsFriend){
int selected=JOptionPane.showConfirmDialog(null,"陌生人"+number+"给您发消息了,查看消息?","消息",JOptionPane.YES_NO_OPTION);
if(selected==0){ //接受
私聊界面 ChatWithX=new 私聊界面(Client_Socket,number,number,QQNumber);
ChatWithX.setVisible(true);
new Thread(ChatWithX).start();
}
}
}
new SendAndReceive(Client_Socket,"DelLevMsg").SendMessage();
}
}
public void ReadRequstMessage(){
if(RequestList.length()!=1){
StringTokenizer Sk=new StringTokenizer(RequestList.substring(1),"$");
while(Sk.hasMoreTokens()){
String Msg=Sk.nextToken();
String Number=Msg.substring(0,9);
String NicNam=Msg.substring(9);
new 回应请求(Client_Socket,Number,NicNam,this.QQNumber,this.NickName,this.Friend).setVisible(true);
}
new SendAndReceive(Client_Socket,"DelAddMsg").SendMessage();
}
}
public void ReadResponseMessage(){
System.out.println(ResponseList);
if(ResponseList.length()!=1){
StringTokenizer Sk=new StringTokenizer(ResponseList.substring(1),"$");
while(Sk.hasMoreTokens()){
String Msg=Sk.nextToken();
System.out.println(Msg);
if(Msg.substring(2,4).equals("OK")){
JOptionPane.showMessageDialog(null,"恭喜!"+Msg.substring(4)+"接受你的加好友请求","恭喜",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"遗憾!"+Msg.substring(4)+"拒绝你的加好友请求","遗憾",JOptionPane.INFORMATION_MESSAGE);
}
}
new SendAndReceive(Client_Socket,"DelResMsg").SendMessage();
}
}
public void ReadGroupLeavingMessage(){
if(GroupLeavingMessage.length()!=1){
StringTokenizer Sk=new StringTokenizer(GroupLeavingMessage.substring(13),"$");
while(Sk.hasMoreTokens()){
String Msg=Sk.nextToken();
String number=Msg.substring(0,4);
System.out.println("号码是:"+number);
String Message=Msg.substring(4);
System.out.println("消息:"+Message);
this.GroupMessage.AddNewMember(number,Message);
int j=0;
System.out.println("列表长度:"+Groups.size());
for(j=0;j<Groups.size();j++){
System.out.println("列表长度:"+Groups.size());
JLabel lab=(JLabel) 群.getModel().getElementAt(j);
String s=lab.getText();
if(s.equals(number)){
this.群.setSelectedIndex(j);
break;
}
}
}
new SendAndReceive(Client_Socket,"DelLevGroupMsg").SendMessage();
}
}
public void run() {
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
PrintWriter GoOut;
try {
GoOut = new PrintWriter(Client_Socket.getOutputStream());
GoOut.println("5"+QQNumber);
GoOut.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
dispose();
}
});
System.out.println(GroupList);
SetFriendList();
ReadLeavingMessage();
ReadRequstMessage();
ReadResponseMessage();
if(!GroupList.equals("@")){
SetGroups();
}
ReadGroupLeavingMessage();
while(true){
BufferedReader In;
try {
In = new BufferedReader(new InputStreamReader(Client_Socket.getInputStream()));
String Information=In.readLine();
System.out.println("接收到的消息"+Information);
if(Information.startsWith("0E")){
String New=Information.substring(2);
WhoIsOnLine=WhoIsOnLine+New+"#";
System.out.println("新来的:"+WhoIsOnLine);
FriendList.clear();
SetFriendList();
continue;
}
if(Information.startsWith("1")) //好友发来的信息
{
String Sender=Information.substring(1,10);
String Message=Information.substring(10);
System.out.println("发来的消息:"+Message);
MsgSound.play();
System.out.println("为什么不发声音呢???");
int i=0;
flag=true;
boolean IsOnChat=false;
boolean IsFriend=false;
for(i=0;i<好友界面.InforList.GetLength();i++){
if( this.InforList.GetMember(i).GetSender().equals(Sender)){
System.out.println("错在这里");
this.InforList.GetMember(i).SetMessage(Message);
int j=0;
for(j=0;j<FriendList.size();j++){
JLabel lab=(JLabel) 好友栏.getModel().getElementAt(j);
String s=lab.getText().substring(lab.getText().length()-9);
if(s.equals(Sender)){
this.好友栏.setSelectedIndex(j);
break;
}
}
IsOnChat=true;
break;
}
}
if(!IsOnChat){
this.InforList.AddNewMember(Sender,Message);
int j=0;
for(j=0;j<FriendList.size();j++){
JLabel lab=(JLabel) 好友栏.getModel().getElementAt(j);
String s=lab.getText().substring(lab.getText().length()-9);
if(s.equals(Sender)){
this.好友栏.setSelectedIndex(j);
IsFriend=true;
break;
}
}
if(!IsFriend){
int selected=JOptionPane.showConfirmDialog(null,"陌生人"+Sender+"给您发消息了,查看消息?","消息",JOptionPane.YES_NO_OPTION);
if(selected==0){ //接受
私聊界面 ChatWithX=new 私聊界面(Client_Socket,Sender,Sender,QQNumber);
ChatWithX.setVisible(true);
new Thread(ChatWithX).start();
}
else{ //拒绝
continue;
}
}
flag=false;
}
continue;
}
if(Information.startsWith("2"))
{
String LeaveNumber=Information.substring(1);
//String [] Array=new String[4];
//Array= WhoIsOnLine.substring(2).split(LeaveNumber);
System.out.println(WhoIsOnLine.substring(2));
String NewList="0Y";
StringTokenizer St=new StringTokenizer( WhoIsOnLine.substring(2),"#");
while(St.hasMoreTokens()){
String s=St.nextToken();
if(!s.equals(LeaveNumber)){
NewList=NewList+s+"#";
}
else {
try{
NewList=NewList+St.nextToken()+"#";
}catch(NoSuchElementException e){
break;
}
}
}
WhoIsOnLine=NewList;
System.out.println("在线名单:"+WhoIsOnLine);
FriendList.clear();
SetFriendList();
continue;
}
if(Information.startsWith("3")) //tell you all the people online
{
RequireByFindFriend=Information.substring(1);
continue;
}
if(Information.startsWith("4")){
if(Information.substring(1).equals("T")){
JOptionPane.showMessageDialog(null,"恭喜!更改信息成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"遗憾!更改信息失败","遗憾",JOptionPane.INFORMATION_MESSAGE);
}
}
if(Information.startsWith("ReDelFri")){
JOptionPane.showMessageDialog(null,"恭喜!删除好友成功","恭喜",JOptionPane.INFORMATION_MESSAGE);
Friend=Information.substring(9);
FriendList.clear();
SetFriendList();
continue;
}
if(Information.startsWith("Add"))
{
String number=Information.substring(3,12);
String nickname=Information.substring(12);
/*int selected=JOptionPane.showConfirmDialog(null,nickname+"请求加您为好友,接受请求?","消息",JOptionPane.YES_NO_OPTION);
if(selected==0){ //接受请求
new SendAndReceive(Client_Socket,"RAOK"+number).SendMessage();
}
else{ //拒绝请求
new SendAndReceive(Client_Socket,"RANO"+number).SendMessage();
}*/
new 回应请求(Client_Socket,number,nickname,this.QQNumber,this.NickName,this.Friend).setVisible(true);
continue;
}
if(Information.startsWith("RA")){
if(Information.substring(2,4).equals("OK")){ //对方同意请求
JOptionPane.showMessageDialog(null,"恭喜!"+Information.substring(4)+"接受你的加好友请求","恭喜",JOptionPane.INFORMATION_MESSAGE);
}
else if(Information.substring(2,4).equals("NO")){ //对方拒绝
JOptionPane.showMessageDialog(null,"遗憾!"+Information.substring(4)+"拒绝你的加好友请求","遗憾",JOptionPane.INFORMATION_MESSAGE);
}
else{
continue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -