-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.java
More file actions
65 lines (58 loc) · 2 KB
/
Copy pathScreen.java
File metadata and controls
65 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipInputStream;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
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);
}
}