package Ksr10Move;
import java.applet.Applet;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import DriverKsr10.Ksr10;
public class Move extends Applet implements KeyListener
{
/*
*
/
String FunctionKey = null;
private int lumiere = 0;
public static void main( String[] commande){
return;
}
public void init()
{
Routines.debug("Début MOVE");
addKeyListener(this);
requestFocus();
}
public void keyReleased(KeyEvent event)
{
// Ignore keyReleased events
}
public void keyPressed(KeyEvent event)
{
int letter = event.getKeyCode();
System.out.println("KeyCode = " + letter);
FunctionKey = "" + (char) letter;
Routines.debug("KeyPressed = " + FunctionKey);
String retour = "OK";
if (FunctionKey.equals("L")){
Routines.debug("KeyPressed = L");
if (lumiere == 0){
lumiere = 1;
} else {
lumiere = 0;
}
}
MyClass mc = new MyClass();
retour = mc.myStarterMethod(FunctionKey, lumiere);
Routines.debug("retour = " + retour);
System.out.println(retour);
repaint();
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public static class MyClass {
public String myStarterMethod(String commande, int lumiere) { Routines.debug("debut mystarter commande = " + commande); String retour = "OK"; retour = traitCommande(commande, lumiere); return retour; } private String traitCommande(String entree, int lumiere) { // TODO Auto-generated method stub String retour = "OK"; String[] commande = new String[2]; double commande2 = 0.0; Routines.debug("Key = " + entree); if (entree.equals("L") || entree.equals("NL")){ commande[0] = entree; commande[1] = ""; commande2 = 0.0; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("Q")){ commande[0] = "M1"; commande[1] = "OPEN"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("W")){ commande[0] = "M1"; commande[1] = "CLOSE"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("S")){ commande[0] = "M2"; commande[1] = "UP"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("X")){ commande[0] = "M2"; commande[1] = "DOWN"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("D")){ commande[0] = "M3"; commande[1] = "UP"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("C")){ commande[0] = "M3"; commande[1] = "DOWN"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("F")){ commande[0] = "M4"; commande[1] = "UP"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("V")){ commande[0] = "M4"; commande[1] = "DOWN"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("G")){ commande[0] = "M5"; commande[1] = "LEFT"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else if (entree.equals("B")){ commande[0] = "M5"; commande[1] = "RIGHT"; commande2 = 0.5; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } else { commande[0] = "stop"; commande[1] = ""; commande2 = 0.0; retour = envoiCommande(commande[0], commande[1], commande2, lumiere); } if (retour.equals("OK")){ Routines.debug("OK"); } else { Routines.debug("retour KO " + retour); } return retour; } private String envoiCommande(String commande0, String commande1, double commande2, int lumiere){ String retour = ""; if (commande1.equals("")){ retour = Ksr10.Ksr10Driver(commande0, lumiere, Routines.debug); } else { retour = Ksr10.Ksr10Driver(commande0, commande1, commande2, lumiere, Routines.debug); retour = Ksr10.Ksr10Driver("stop", lumiere, Routines.debug); } return retour; }
}
public static class Routines{
public static boolean debug = true; public static void debug(String entree){ // message si debug if (debug == true){ System.out.println(entree); } }
}
}