1 2 package Jt; 3 import java.util.*; 4 import java.lang.reflect.*; 5 import java.beans.*; 6 import java.io.*; 7 8 12 13 14 public class JtKeyboard extends JtObject { 15 16 String command = null; 17 Process process = null; 18 int status = 0; 19 String stdout; 20 String line = null; 21 22 private byte readln ()[] throws IOException { 23 byte buffer[] ; 24 int i; 25 byte ch; 26 27 buffer = new byte[1024]; 28 buffer[0] = '\0'; 29 30 i = 0; 31 while ((ch = (byte) System.in.read ()) >= 0) { 32 if (i >= 1024) 33 break; 34 buffer[i++] = ch; 35 if (ch == '\n') 36 break; 37 } 38 if (i == 0) 39 line = null; 40 else 41 line = new String (buffer, 0, i); 42 return buffer; 44 45 } 46 47 48 49 51 void activate () { 52 byte buffer[]; 53 54 try { 55 buffer = readln (); 56 } catch (IOException ex) { 57 handleException (ex); 58 return; 60 } 61 } 64 65 66 72 73 public Object processMessage (Object message) { 74 75 String msgid = null; 76 byte buffer[]; 77 File file; 78 JtMessage e = (JtMessage) message; 79 80 if (e == null) 81 return null; 82 83 msgid = (String ) e.getMsgId (); 84 85 if (msgid == null) 86 return null; 87 88 if (msgid.equals ("JtREMOVE")) { 90 return (null); 91 } 92 93 if (msgid.equals ("JtACTIVATE")) { 94 activate (); 95 return (line); 96 } 97 handleError ("JtKeyboard.processMessage: invalid message id:" + msgid); 98 99 return null; 100 } 101 102 103 106 107 public static void main(String [] args) { 108 109 JtObject main = new JtObject (); 110 JtMessage msg; 111 String oline; 112 113 114 115 117 main.createObject ("Jt.JtKeyboard", "keyboard"); 118 msg = new JtMessage ("JtACTIVATE"); 119 System.out.println ("Press any key to continue ..."); 120 oline = (String ) main.sendMessage ("keyboard", msg); 121 System.out.println ("Keyboard input:" + oline); 122 main.removeObject ("keyboard"); 123 124 125 126 } 127 } 128 129 130
| Popular Tags
|