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

📄 connect.java

📁 局域网聊天系统的设计与实现
💻 JAVA
字号:
package remotecontrol;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.imageio.*;


class MyMouseHandler implements MouseListener{
	private Connect ref;
	
	public MyMouseHandler(Connect ref){
		this.ref=ref;
	}
	public void mouseClicked(MouseEvent e){
		int which=e.getButton();
		int count=e.getClickCount();
		int x=e.getX();
		int y=e.getY();
		Dimension size=Toolkit.getDefaultToolkit().getScreenSize();
		double width=size.getWidth();
		double height=size.getHeight();
		
		
		if(which==MouseEvent.BUTTON1){//left
			//System.out.println("1");
			if(count==1){
				//System.out.println("1");
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON1_MASK,1).start();
			}else if(count>=2){
				//System.out.println("2");
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON1_MASK,2).start();
			}
		}else if(which==MouseEvent.BUTTON2){//middle
			//System.out.println("2");
			if(count==1){
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON2_MASK,1).start();
			}else if(count>=2){
				//System.out.println("2");
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON2_MASK,2).start();
			}
		}else if(which==MouseEvent.BUTTON3){//right
			//System.out.println("3");
			if(count==1){
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON3_MASK,1).start();
			}else if(count>=2){
				//System.out.println("2");
				new MyThread3(this.ref,x,y,(int)width,(int)height,InputEvent.BUTTON3_MASK,2).start();
			}
		}
	}       
 	public void mouseEntered(MouseEvent e) {
 		
 	}
 	public void mouseExited(MouseEvent e) {
 		
 	}
 	public void mousePressed(MouseEvent e) {
 		
 	}
 	public void mouseReleased(MouseEvent e)  {
 		
 	}
}
class MyThread3 extends Thread{
	private Connect ref;
	private int x;
	private int y;
	private int screenWidth;
	private int screenHeight;
	private int button;
	private int count;
	
	public MyThread3(Connect ref,int x,int y,int screenWidth,int screenHeight,int button,int count){
		this.ref=ref;
		this.x=x;
		this.y=y;
		this.screenWidth=screenWidth;
		this.screenHeight=screenHeight;
		this.button=button;
		this.count=count;
	}
	public void run(){
		try{
			System.out.println("Sending object...");
			MouseClickRequest request=new MouseClickRequest(x,y,this.screenWidth,this.screenHeight,this.button,this.count);
			this.ref.oos.writeObject(request);
			System.out.println("Object sended.");
			System.out.println("Sending object...");
			GetPicRequest request2=new GetPicRequest();
			this.ref.oos.writeObject(request2);
			System.out.println("Object sended.");
		}catch(Throwable t){
			t.printStackTrace();
		}
	}
}
class MyCanvas extends Canvas{
	public Graphics g;
	private byte[] value;
	
	public MyCanvas(){
		//setSize(1024,768);
	}
	public MyCanvas(byte[] value){
		this.value=value;
	}
	public void setImageArray(byte[] value){
		this.value=value;
	}
	public void paint(Graphics g){
		//System.out.println("paint");
		this.g=g;
		g.setColor(Color.WHITE);
		g.fillRect(0,0,1024,768);
		try{
			if(this.value!=null){
				 g.drawImage(ImageIO.read(new ByteArrayInputStream(this.value)),0,0,Color.BLACK,null);
			}
		}catch(Throwable t){
			t.printStackTrace();
		}
	}
}
class MyThread2 extends Thread{
	private Connect ref;
	private Object sync=new Object();
	private boolean done;
	private String ip;
	public MyThread2(Connect ref,String ip){
		this.ref=ref;
        this.ip = ip;
	}   
	public void run(){
		try{
            try{
			this.ref.socket=new Socket(ip,16888);
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null,"杩炴帴琚

⌨️ 快捷键说明

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