从一台计算机到另一台计算机的鼠标位置

时间:2017-02-16 16:52:44

标签: java sockets events tcp

我想在java上以VNC的形式编写一个应用程序。

起初我尝试流式传输我的鼠标位置,但我刚在学校学习了一些Java。

我的代码:

private Maus mouse;

static int cX;
static int cY;

public TestMaus() {
    mouse = new Maus();
     }

public void main() throws Exception {

    String sentence;
    String modifiedSentence;
    BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
    Socket clientSocket = new Socket("", 6789);

    while(true)
    {
        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        sentence = String.valueOf(mouse.posX + "I" + mouse.posY);
        outToServer.writeBytes(sentence + '\n');
        modifiedSentence = inFromServer.readLine();
        System.out.println("FROM SERVER: " + modifiedSentence);
        clientSocket.close();
    }        
}

public int posX, posY;

public Maus(){     

        addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(final MouseEvent e) {
            posX = e.getX();
            posY = e.getY();
        }
    });
}

0 个答案:

没有答案