本文整理汇总了Java中lejos.hardware.Key类的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于lejos.hardware包,在下文中一共展示了Key类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testEqualsAndHashCode
import lejos.hardware.Key; //导入依赖的package包/类
@Test
public void testEqualsAndHashCode() {
final EV3Key enterKey = new EV3Key(EV3Key.BUTTON_LEFT);
// intentionally calling Assert.assertEquals(EV3Key.equals(...)) to demonstrate better what we're testing
Assert.assertFalse(enterKey.equals(null));
Assert.assertFalse(enterKey.equals(enterKey.getId())); // comparison with integer intentionally doesn't work as it's ambiguous (id vs. Key.* constants vs. Keys.ID_* constants)
Assert.assertTrue(enterKey.equals(enterKey));
Assert.assertTrue(enterKey.equals(new EV3Key(EV3Key.BUTTON_LEFT)));
Assert.assertTrue(enterKey.equals(new EV3Key(EV3Key.KeyType.LEFT)));
Assert.assertFalse(enterKey.equals(new EV3Key(EV3Key.KeyType.RIGHT)));
Assert.assertTrue(enterKey.equals(new TestKey(EV3Key.BUTTON_LEFT)));
Assert.assertFalse(enterKey.equals(new TestKey(EV3Key.BUTTON_RIGHT)));
final Set<Key> uniqueKeys = new HashSet<>();
uniqueKeys.add(enterKey);
uniqueKeys.add(new EV3Key(EV3Key.KeyType.LEFT));
uniqueKeys.add(new EV3Key(EV3Key.BUTTON_LEFT));
Assert.assertEquals(1, uniqueKeys.size());
}
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:21,代码来源:EV3KeyTest.java
示例2: main
import lejos.hardware.Key; //导入依赖的package包/类
public static void main(String[] args) {
brick = BrickFinder.getDefault();
GraphicsLCD g = brick.getGraphicsLCD();
Key enter = brick.getKey("Escape");
String[] sensorName = new String[4];
p[0] = brick.getPort("S1");
p[1] = brick.getPort("S2");
p[2] = brick.getPort("S3");
p[3] = brick.getPort("S4");
while ( enter.isUp() ) {
uDetected = false;
for ( int i = 0; i < sensorName.length; i++ ) {
sensorName[i] = getSensorName(i);
}
g.clear();
g.drawString("ESCAPE to quit", 0, 100, 0, true);
g.setFont(Font.getSmallFont());
g.drawString("B.", 165, 105, 0);
g.setFont(Font.getDefaultFont());
for ( int i = 0; i < sensorName.length; i++ ) {
g.drawString("Port " + (i + 1) + ": " + sensorName[i], 0, i * 20 + 20, 0);
}
if ( !uDetected ) {
Delay.msDelay(100);
}
}
}
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:30,代码来源:SensorTest.java
示例3: equals
import lejos.hardware.Key; //导入依赖的package包/类
/**
* @param obj
* @return true if the {@code obj} is an instance of {@link Key} and if the button IDs are the same.
*/
@Override
public boolean equals(final Object obj) {
if (obj == null || ! (obj instanceof Key)) {
return false;
} else if (obj == this) { // pointer comparison
return true;
} else {
return ((int)this.keyType.getId() == ((Key)obj).getId());
}
}
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:15,代码来源:EV3Key.java
示例4: broadcastToListeners
import lejos.hardware.Key; //导入依赖的package包/类
private static void broadcastToListeners(final KeyType keyType, final BiConsumer<KeyListener, Key> notificationMethod) {
keyListeners.get(keyType).forEach((listener) -> notificationMethod.accept(listener, new EV3Key(keyType))); // key-specific listeners
keyListeners.get(KeyType.ALL).forEach((listener) -> notificationMethod.accept(listener, new EV3Key(keyType))); // all-key listeners
synchronized (keyEventReader) {
keyEventReader.notifyAll();
}
}
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:8,代码来源:EV3Key.java
示例5: keyPressed
import lejos.hardware.Key; //导入依赖的package包/类
@Override
public void keyPressed(Key key) {
this.keyEvents.add(Pair.of(key, KeyEvent.PRESSED));
}
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:5,代码来源:EV3KeyTest.java
示例6: keyReleased
import lejos.hardware.Key; //导入依赖的package包/类
@Override
public void keyReleased(Key key) {
this.keyEvents.add(Pair.of(key, KeyEvent.RELEASED));
}
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:5,代码来源:EV3KeyTest.java
示例7: SimpleEV3Button
import lejos.hardware.Key; //导入依赖的package包/类
SimpleEV3Button(Key delegate, EV3ScriptContext sc) {
this.delegate = delegate;
this.sc = sc;
}
开发者ID:jbenech,项目名称:gnikrap,代码行数:5,代码来源:SimpleEV3Keyboard.java
注:本文中的lejos.hardware.Key类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论