本文整理汇总了Java中lejos.hardware.Button.getButtons方法的典型用法代码示例。如果您正苦于以下问题:Java Button.getButtons方法的具体用法?Java Button.getButtons怎么用?Java Button.getButtons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lejos.hardware.Button
的用法示例。
在下文中一共展示了Button.getButtons方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import lejos.hardware.Button; //导入方法依赖的package包/类
public void run() {
while (true) {
if (Button.getButtons() == Keys.ID_ESCAPE) {
try {
robot.stop();
} catch (IOException e) {
// this won't happen
}
}
}
}
示例2: getSelection
import lejos.hardware.Button; //导入方法依赖的package包/类
/**
* Obtain a menu item selection
* Allow the user to make a selection from the specified menu item. If a
* power off timeout has been specified and no choice is made within this
* time power off the NXT.
*
* @param menu Menu to display.
* @param cur Initial item to select.
* @return Selected item or < 0 for escape etc.
*/
@SuppressWarnings("deprecation")
private int getSelection(GraphicMenu menu, int cur) {
int selection;
curMenu = menu;
// If the menu is interrupted by another thread, redisplay
do {
selection = menu.select(cur, this.timeout * 60000);
while ( suspend ) {
if ( program != null && !echoIn.isAlive() && !echoErr.isAlive() ) {
stopProgram();
this.ind.resume();
break;
}
int b = Button.getButtons();
if ( b == 6 ) {
if ( program != null ) {
stopProgram();
}
this.ind.resume();
break;
}
Delay.msDelay(200);
}
} while ( selection == -2 );
if ( selection == -3 ) {
shutdown();
}
return selection;
}
示例3: exec
import lejos.hardware.Button; //导入方法依赖的package包/类
/**
* Execute a program and display its output to System.out and error stream to System.err
*/
private static void exec(File jar, String command, String directory) {
try {
if ( jar != null ) {
String jarName = jar.getName();
programName = jarName.substring(0, jarName.length() - 4); // Remove .jar
}
lcd.clear();
lcd.refresh();
lcd.setAutoRefresh(false);
drawLaunchScreen();
program = new ProcessBuilder(command.split(" ")).directory(new File(directory)).start();
BufferedReader input = new BufferedReader(new InputStreamReader(program.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader(program.getErrorStream()));
echoIn = new EchoThread(jar.getPath().replace(".jar", ".out"), input, System.out);
echoErr = new EchoThread(jar.getPath().replace(".jar", ".err"), err, System.err);
echoIn.start();
echoErr.start();
System.out.println("Executing " + command + " in " + directory);
while ( true ) {
int b = Button.getButtons();
if ( b == 6 ) {
System.out.println("Killing the process");
program.destroy();
// reset motors after program is aborted
resetMotors();
break;
}
if ( !echoIn.isAlive() && !echoErr.isAlive() ) {
break;
}
Delay.msDelay(200);
}
System.out.println("Waiting for process to die");
;
program.waitFor();
System.out.println("Program finished");
} catch ( Exception e ) {
System.err.println("Failed to execute program: " + e);
} finally {
// Turn the LED off, in case left on
Button.LEDPattern(0);
lcd.setAutoRefresh(true);
lcd.clear();
lcd.refresh();
program = null;
}
}