⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatgui.java

📁 JAVA聊天室 即使通讯
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	  
	  

	  
	  

	  
	  
	gbc.gridx = 0;
	gbc.gridy = 5;
	gbc.gridwidth = 1;
	gbc.gridheight =1;   
	gb.setConstraints(font,gbc);//选择字体
	p.add(font);
	 
	  
	
	gbc.gridx = 1;
	gbc.gridy = 5;
	gbc.gridwidth = 1;
	gbc.gridheight =1;   
	gb.setConstraints(p3,gbc);//选择字体
	p.add(p3);
	
	
	
	gbc.gridx = 0;
	gbc.gridy = 6;
	gbc.gridwidth = 4;
	gbc.gridheight =2;
	gbc.fill = GridBagConstraints.BOTH;
	gb.setConstraints(scrollwrite,gbc);//写入区
	p.add(scrollwrite); 
	
	
	   
	gbc.gridx = 1;
	gbc.gridy = 2;
	gbc.gridwidth = 3;
	gbc.gridheight =1;
	gbc.fill = GridBagConstraints.NONE;
	gbc.anchor = GridBagConstraints.WEST;  
	gb.setConstraints(scrollDrivateChat,gbc);//群聊区
	p.add(scrollDrivateChat);
	
	
	
	gbc.gridx = 1;
	gbc.gridy = 3;
	gbc.gridwidth = 3;
	gbc.gridheight =1;
	gb.setConstraints(scrollPrivateChat,gbc);//私聊区
	p.add(scrollPrivateChat);
	
	
	

	
	gbc.gridx = 2;
	gbc.gridy = 5;
	gbc.gridwidth = 1;
	gbc.gridheight =1;
	gb.setConstraints(expression,gbc);//选择表情区
	p.add(expression);
	
	
	
	
	
	
	
	gbc.gridx = 3;
	gbc.gridy = 5;
	gbc.gridwidth = 1;
	gbc.gridheight =1;
	gb.setConstraints(cbb,gbc);//选择表情区
	p.add(cbb);
	
	
	
	gbc.gridx = 4;
	gbc.gridy = 2;
	gbc.gridwidth = 1;
	gbc.gridheight =2;
	gb.setConstraints(p5,gbc);//聊天公告
	p.add(p5);
	

	
	
		
		
	gbc.gridx = 4;
	gbc.gridy = 5;
	gbc.gridwidth = 0;
	gbc.gridheight =1;
	gb.setConstraints(amend,gbc);//修改资料
	p.add(amend);
	
	
	
	
	gbc.gridx = 4;
	gbc.gridy = 6;
	gbc.gridwidth = 0;
	gbc.gridheight =0;
	gb.setConstraints(dispatch,gbc);//发      送
	p.add(dispatch); 
	
	
	
	gbc.gridx = 4;
	gbc.gridy = 7;
	gbc.gridwidth = 0;
	gbc.gridheight =0;
	gbc.anchor = GridBagConstraints.SOUTHWEST;
	gb.setConstraints(cancel,gbc);//取       消 
	p.add(cancel);
	
	
	
	
	
	
	
	this.pack();
	//this.setResizable(false);
	this.setVisible(true);
	
	Thread t= new Thread(this);
	t.start();
	
	}

		
	
	   public void actionPerformed(ActionEvent e)
          {
     	   
     	   
     	    JButton obj= (JButton)e.getSource();
	       
	       
	       if(obj.equals(amend))
     	     {
     	     	
     	     	new RetakeGUI(client);
             }
             
             
            if(e.getSource() == help)
     	    {     	       
     	       new HelpGUI();     	      
     	    }
     	    if(e.getSource()==dispatch)
     	    {
     	    	Message m = new Message();
     	    	m.setsender(myName);
     	    	
     	    if(!textare3.getStyledDocument().equals(null))	
   	   	     { 
   	   	         String line = (String)listUsrifo.getSelectedValue();
   	   	         if(line==null){
   	   	         	 if(RadioButton2.isSelected()){
   	   	         	 	JOptionPane.showMessageDialog(null, "私聊时请先选择对象");
   	   	         	 	return;
   	   	         	 }else{
   	   	         	 	m.setaccept("大家");
   	   	         	 }
   	   	         }
   	   	         else{
   	   	         	if(line.equals(myName))
   	   	           	{
   	   	     	    	JOptionPane.showMessageDialog(null, "对不起! 您不能自己对自己说话!");
   	   	     	    	return;
   	   	           	}
   	   	           	m.setaccept(line);
   	   	         }
   	   	        
   	   	        if(RadioButton1.isSelected())
   	   	           {  
   	   	             m.setflag(0);  //公聊标志 
   	   	           }
   	   	        else
   	   	           { m.setflag(1);}   //私聊标志
   	   	           
   	   	            //System.out.println("自己: "+myName);
   	   	            
   	   	            m.setMessage(textare3.getStyledDocument());   	   	      
   	   	        try
   	   	        {	
   	   	           client.messageSend(m);
   	   	        }catch(Exception e1){e1.printStackTrace();   }
   	   	        textare3.setText("");	   	  
   	   	    }
   	   	   else
   	         JOptionPane.showMessageDialog(null,"发送的消息不能为空");   	
     	 }
  			 if(e.getSource()==cancel){
  			 
  			}
        }	
	 public void tuichu() //退出事件方法
   	  {
         Message m=new Message(); 
       
  	    m.setsender(myName);
         
        m.setflag(2);
         
        try
   	    {
   	      client.messageSend(m);
        }catch(Exception e1){  e1.printStackTrace();   }
        System.exit(0); 
  	 }   
	       
public void run()//启用 run()
{   
   while(true)
   { 
    ServerResults ser;
    try
      {      
        //调用客服端的方法getserverResults()
   	    ser = client.getServerResults(); 
   	    System.out.println("主界面收到的状态信息: "+ser.getstatue());
   	    
   	    
 	    if(ser.getstatue()==0)    
   	    {
   	      Vector v=ser.getVoctor();
   	      v.add(0,"所有人");
   	      System.out.println(v);
   	      
   	      //调用的原java中的方法setListData();
   	      listUsrifo.setListData(v); 
   	    }
   	    if(ser.getstatue()==1)
   	    {
   	       Message m =ser.getMessage1();
   	       StyledDocument stydocmt=m.getMessage();
   	       String jsoName=m.getaccept();
   		   String senter=m.getsender();
   		   System.out.println("发送人: "+senter);
   		   System.out.println("接收人: "+jsoName);
   		   if(m.getflag()==0)   //为公聊
   	       {
   	      	 String s = senter+" 面对 "+jsoName+" 讲: ";
   	      	 textare1.getStyledDocument().insertString(textare1.getStyledDocument().getLength(),s,null);
   	      	 this.quansongMessage(textare1,m);
   	       }
   	       if(m.getflag()==1)   //为私聊
   	       { 
   	       String s ="密密的"+ senter+"对"+jsoName+"说:";
   	       textare2.getStyledDocument().insertString(textare2.getStyledDocument().getLength(),s,null);
   	       this.quansongMessage(textare2,m);
   	       	
   	       } 
   	    }
   	    try
   	    {
   	      Thread.sleep(1000);	
   	    }catch(Exception e2){e2.printStackTrace();}
   	     
   	  }catch(Exception e){   e.printStackTrace();  }	
   }
 }
 //**********************************************附加方法,说明你在文本框中的 限定条件
 public void quansongMessage(JTextPane txtPane,Message mess)
 {
 	StyledDocument slyd= mess.getMessage();
 	try{
     	for(int i=0;i<slyd.getLength();i++)
 	    {
 		  String car = slyd.getText(i,1);
 		  char c = car.charAt(0);
 		  int changdu = (int)c;
 		  if(changdu==32)
 		  {
 		  	txtPane.getStyledDocument().insertString(txtPane.getStyledDocument().getLength(),car,slyd.getCharacterElement(i).getAttributes());
 		  }
 		  else
 		  {
 		  	txtPane.getStyledDocument().insertString(txtPane.getStyledDocument().getLength(),car,slyd.getLogicalStyle(i));
 		  }
 	    }
 	    txtPane.getStyledDocument().insertString(txtPane.getStyledDocument().getLength(),"\n",null);
 	   }catch(Exception e){e.printStackTrace();}
 }
 public void itemStateChanged(ItemEvent e) 
 {
 	textare3.insertIcon((Icon)cbb.getSelectedItem());
 }
  
 
}


//     public static void main(String[] args)
//	{
//		new chatGUI();    
//    }
//}      
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -