Package DriverTeclado

Source Code of DriverTeclado.Teclado

/*
* File:        Teclado.java
*
*
*     This file is a part of MICE, a program designed for
*              people with severe motor disabilities to whom it is impossible
*              to use a traditional mouse. This application gives these people
*              the control of the physical mouse via another type of device.
*
* Authors:     Isabel Gonzalez
* Date:        2008/ 2009
*
* Company:     Colegio Publico de Educacion Especial Alborada, Zaragoza
*              DIIS, Universidad de Zaragoza
*
* License:     Copyright (C) 2008
*
*              This program is free software: you can redistribute it and/or modify
*              it under the terms of the GNU General Public License as published by
*              the Free Software Foundation, either version 3 of the License, or
*              (at your option) any later version.
*
*              This program is distributed in the hope that it will be useful,
*              but WITHOUT ANY WARRANTY; without even the implied warranty of
*              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*              GNU General Public License for more details.
*
*              You should have received a copy of the GNU General Public License
*              along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*
*
*
*/



package DriverTeclado;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

public class Teclado {
   
    public static Conexion c;
    public static FrameHook fh;
    public static Eventos e;
    public static configuracionTecladoVentana ctv;
    public static esperarEventos espEv;
 
    public Teclado() {
      
       
    }
   
  
    public static void main(String args[]) {
         //Establezco la conexion con la Pasarela
         c= new Conexion(e);
         c.establecerConexion();
        
         e= new Eventos();
         e.almacenarLibres();
        
        
          if(System.getProperties().getProperty("os.name").toLowerCase().equals("linux")) {
           
             fh= new FrameHook(c,e);
          }
          else {
            
          }
        
        
         ctv= new configuracionTecladoVentana(e,c,fh);
        

    }

      


}
class esperarEventos extends Thread {
    SocketChannel sc;
   public esperarEventos (SocketChannel socket) {
      sc=socket;
   }
    public void esperar(){
        String result;
        try {
            while(true){
                ByteBuffer buf = ByteBuffer.allocate(1024);
                // Clear the buffer and read bytes from socket
               
                buf.clear();
                int numBytesRead = sc.read(buf);
                if (numBytesRead == -1) {
                    // No more bytes can be read from the channel
                    sc.close();
                } else {
                    // To read the bytes, flip the buffer
                    buf.flip();
                    result=decode(buf);
                   
                    if (result.equals("fin")){
                        sc.close();
                        System.exit(0);
                    }
                }
            }
        } catch (IOException e) {
            // Connection may have been closed
        }
    }
    public static String decode( ByteBuffer byteBuffer ) throws CharacterCodingException {
        Charset charset = Charset.forName( "us-ascii" );
        CharsetDecoder decoder = charset.newDecoder();
        CharBuffer charBuffer = decoder.decode( byteBuffer );
        String result = charBuffer.toString();
        return result;
    }
   public void run() { // Sobrecargando al metodo run
    
     esperar();
   }
}
TOP

Related Classes of DriverTeclado.Teclado

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.