|
@@ -1,5 +1,7 @@
|
|
package com.sziit.G06.controller;
|
|
package com.sziit.G06.controller;
|
|
|
|
|
|
|
|
+import com.sziit.G06.controller.MyException;
|
|
|
|
+
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
@@ -18,14 +20,15 @@ import java.io.ObjectOutputStream;
|
|
|
|
|
|
public class Controller extends Thread {
|
|
public class Controller extends Thread {
|
|
|
|
|
|
- private java.io.DataInputStream dis;
|
|
+ private DataInputStream dis;
|
|
- private java.io.ObjectOutputStream ous;
|
|
+ private ObjectOutputStream ous;
|
|
- private javax.swing.JLabel la_image = new javax.swing.JLabel();
|
|
+ private JLabel la_image = new JLabel();
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
* 显示页面
|
|
* 显示页面
|
|
*/
|
|
*/
|
|
- public void showUI() {
|
|
+ public void showUI(String ip,int port,String idname) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -51,12 +54,16 @@ public class Controller extends Thread {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- javax.swing.JFrame frame=new javax.swing.JFrame("远程控制");
|
|
+ JFrame frame=new JFrame("远程控制");
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
frame.setSize(w,h);
|
|
frame.setSize(w,h);
|
|
|
|
|
|
frame.setResizable(false);
|
|
frame.setResizable(false);
|
|
|
|
+
|
|
|
|
+ frame.setTitle(ip +" 端口:" + port+" 被控制端名字:"+idname);
|
|
|
|
|
|
la_image.setSize(w1, h1);
|
|
la_image.setSize(w1, h1);
|
|
JLayeredPane jlp = new JLayeredPane();
|
|
JLayeredPane jlp = new JLayeredPane();
|
|
@@ -73,13 +80,13 @@ public class Controller extends Thread {
|
|
|
|
|
|
|
|
|
|
frame.addKeyListener(new KeyAdapter(){
|
|
frame.addKeyListener(new KeyAdapter(){
|
|
- public void keyPressed(KeyEvent e) {
|
|
+ public void keyPressed(KeyEvent e) {
|
|
- sendEventObject(e);
|
|
+ sendEventObject(e);
|
|
- }
|
|
+ }
|
|
- @Override
|
|
+ @Override
|
|
- public void keyReleased(KeyEvent e) {
|
|
+ public void keyReleased(KeyEvent e) {
|
|
- sendEventObject(e);
|
|
+ sendEventObject(e);
|
|
- }
|
|
+ }
|
|
@Override
|
|
@Override
|
|
public void keyTyped(KeyEvent e) {
|
|
public void keyTyped(KeyEvent e) {
|
|
}
|
|
}
|
|
@@ -122,7 +129,7 @@ public class Controller extends Thread {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
+
|
|
private void connectToServer(String ip,int port)
|
|
private void connectToServer(String ip,int port)
|
|
throws Exception{
|
|
throws Exception{
|
|
|
|
|
|
@@ -135,10 +142,10 @@ public class Controller extends Thread {
|
|
if(dis==null||ous==null)throw new MyException("远程控制不接受或未接受被控制。。。");
|
|
if(dis==null||ous==null)throw new MyException("远程控制不接受或未接受被控制。。。");
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
- private void sendEventObject(java.awt.event.InputEvent event){
|
|
+ private void sendEventObject(InputEvent event){
|
|
try{
|
|
try{
|
|
ous.writeObject(event);
|
|
ous.writeObject(event);
|
|
|
|
|
|
@@ -154,7 +161,7 @@ public class Controller extends Thread {
|
|
try{
|
|
try{
|
|
|
|
|
|
while(true){
|
|
while(true){
|
|
-
|
|
+
|
|
int len=dis.readInt();
|
|
int len=dis.readInt();
|
|
|
|
|
|
byte[] data=new byte[len];
|
|
byte[] data=new byte[len];
|
|
@@ -165,8 +172,8 @@ public class Controller extends Thread {
|
|
ByteArrayInputStream bins=new ByteArrayInputStream(data);
|
|
ByteArrayInputStream bins=new ByteArrayInputStream(data);
|
|
BufferedImage image= ImageIO.read(bins);
|
|
BufferedImage image= ImageIO.read(bins);
|
|
|
|
|
|
-
|
|
+
|
|
- javax.swing.ImageIcon ic=new ImageIcon(image);
|
|
+ ImageIcon ic=new ImageIcon(image);
|
|
Image img = ic.getImage();
|
|
Image img = ic.getImage();
|
|
|
|
|
|
|
|
|
|
@@ -191,7 +198,7 @@ public class Controller extends Thread {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
private static BufferedImage resize(Image img, int newW, int newH) {
|
|
private static BufferedImage resize(Image img, int newW, int newH) {
|
|
|
|
|
|
int w = img.getWidth(null);
|
|
int w = img.getWidth(null);
|
|
@@ -201,7 +208,7 @@ public class Controller extends Thread {
|
|
|
|
|
|
Graphics2D g = dimg.createGraphics();
|
|
Graphics2D g = dimg.createGraphics();
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -224,11 +231,11 @@ public class Controller extends Thread {
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
|
|
|
|
- public static void connect(String ip,int port) throws Exception{
|
|
+ public static void connect(String ip,int port,String idname) throws Exception{
|
|
|
|
|
|
Controller ct=new Controller();
|
|
Controller ct=new Controller();
|
|
|
|
|
|
- ct.showUI();
|
|
+ ct.showUI(ip,port,idname);
|
|
|
|
|
|
ct.connectToServer(ip,port);
|
|
ct.connectToServer(ip,port);
|
|
|
|
|
|
@@ -236,5 +243,3 @@ public class Controller extends Thread {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|