| 12
 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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 
 | package com.example.clavierb;
 
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
 
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends Activity {
    public Button button5;
    public Button button6;
    public Button button7;
    public Button button8;
    public Button button9;
    public Button button10;
    public Button button11;
    public Button button12;
    public Button button13;
    public Button button14;
    public Button button15;
    public Button button16;
    public Button button17;
    public Button button18;
    public Button button19;
    public Button button20;
    public EditText port;
    public EditText ip;
    public Socket socket;
    //private int Port = 8002;
    //private String host = "127.0.0.1";
    //private int Port = Integer.parseInt(port.getText().toString());
	//private String host = ip.getText().toString(); 
 
    @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
 
		button5 = (Button) findViewById(R.id.button5);
        button6 = (Button) findViewById(R.id.button6);
        button7 = (Button) findViewById(R.id.button7);
        button8 = (Button) findViewById(R.id.button8);
        button9 = (Button) findViewById(R.id.button9);
        button10 = (Button) findViewById(R.id.button10);
        button11 = (Button) findViewById(R.id.button11);
        button12 = (Button) findViewById(R.id.button12);
        button13 = (Button) findViewById(R.id.button13);
        button14 = (Button) findViewById(R.id.button14);
        button15 = (Button) findViewById(R.id.button15);
        button16 = (Button) findViewById(R.id.button16);
        button17 = (Button) findViewById(R.id.button17);
        button18 = (Button) findViewById(R.id.button18);
        button19 = (Button) findViewById(R.id.button19);
        button20 = (Button) findViewById(R.id.button20);
        port = (EditText) findViewById(R.id.editText);
        ip = (EditText) findViewById(R.id.editText2);
 
 
        button19.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
               new Thread(new ClientThread()).start();
               /*try{
            	   int Port = 8002;
            	   String host = "127.0.0.1";
			 InetAddress serverAddr = InetAddress.getByName(host);
             socket = new Socket(serverAddr, Port);
               }
             catch (UnknownHostException e1)
             {
                 e1.printStackTrace();
             }
             catch (IOException e1)
             {
                 e1.printStackTrace();
             }*/
            }
        });
 
        button20.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
            	try{
                socket.close();
            	}
            	catch(IOException e){
            		e.printStackTrace();
            		//button20.setBackgroundColor(Color.RED);
            	}
            	}
            });
 
  button5.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View v) {
            	try{
            		String touche1="ON_LA_5"; 
	    			   PrintWriter out = new PrintWriter(new BufferedWriter(
	                            new OutputStreamWriter(socket.getOutputStream())), true);
	                   //affichage.append(Msg+"\n");
	                    out.println(touche1);
	                } catch (UnknownHostException e) {
	                        e.printStackTrace();
	                } catch (IOException e) {
	                        e.printStackTrace();
	                } catch (Exception e) {
	                        e.printStackTrace();
	                }
 
            	}
            });
 
class ClientThread implements Runnable{
		@Override
		public void run(){
		 try{
			 //int Port = 8002;
      	   //String host = "127.0.0.1";
			 //int Port = Integer.parseInt(port.getText().toString());
			 //String host = ip.getText().toString(); 
			 InetAddress serverAddr = InetAddress.getByName("127.0.0.1");
             socket = new Socket(serverAddr, 8002);
		 }
             catch (UnknownHostException e1)
             {
                 e1.printStackTrace();
             }
             catch (IOException e1)
             {
                 e1.printStackTrace();
             }
		 }
	}
} | 
Partager