java实现实验室教师远程学生桌面把jframe改成jpanel

网上找的代码如下 现在是一个一个窗口显示一个桌面 我想把他变成panel然后放在主界面那里(主界面需要监控多个学生的桌面)。。。可是渣渣不会改

package ServerWhat;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipInputStream;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

public class RemoteMonitored extends JFrame {

private static final long serialVersionUID = 1L;

Dimension screenSize;

public  RemoteMonitored () {  
    super();  
    screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
    this.setSize(800, 640);  
    Screen p = new Screen();  
    Container c = this.getContentPane();  
    c.setLayout(new BorderLayout());  
    c.add(p, SwingConstants.CENTER);  
    new Thread(p).start();  
    SwingUtilities.invokeLater(new Runnable(){  
        public void run() {  
            setVisible(true);  
        }});  
}  

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

class Screen extends JPanel implements Runnable {  

    private static final long serialVersionUID = 1L;  
    private Image cimage;  

    public void run() {  
        ServerSocket ss = null;  
        try {  
            ss = new ServerSocket(5001);// 探听5001端口的连接  
            while (true) {  
                Socket s = null;  
                try {  
                    s = ss.accept();  
                    ZipInputStream zis = new ZipInputStream(s  
                            .getInputStream());  
                    zis.getNextEntry();  
                    cimage = ImageIO.read(zis);// 把ZIP流转换为图片  
                    repaint();  
                } catch (Exception e) {  
                    e.printStackTrace();  
                } finally {  
                    if (s != null) {  
                        try {  
                            s.close();  
                        } catch (IOException e) {  
                            e.printStackTrace();  
                        }  
                    }  
                }  
            }  
        } catch (Exception e) {  
        } finally {  
            if (ss != null) {  
                try {  
                    ss.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
    }  

    public Screen() {  
        super();  
        this.setLayout(null);  
    }  

    public void paint(Graphics g) {  
        super.paint(g);  
        Graphics2D g2 = (Graphics2D) g;  
        g2.drawImage(cimage, 0, 0, null);  
    }  
}  

}

1个回答

因为这个窗口跟套接字建立放在一起了 可以把他们分开 然后在主界面出现之前套接字建立 让远程桌面的图案在主界面某一panel显示吗

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!