当前位置: 首页>>代码示例>>Java>>正文


Java Button.ID_LEFT属性代码示例

本文整理汇总了Java中lejos.hardware.Button.ID_LEFT属性的典型用法代码示例。如果您正苦于以下问题:Java Button.ID_LEFT属性的具体用法?Java Button.ID_LEFT怎么用?Java Button.ID_LEFT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在lejos.hardware.Button的用法示例。


在下文中一共展示了Button.ID_LEFT属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uncaughtException

@Override
public void uncaughtException(Thread th, Throwable t)  {
	Sound.buzz();
    TextLCD lcd = LocalEV3.get().getTextLCD(Font.getSmallFont());
    int offset = 0;
    while (true)
    {
   		lcd.clear();
   		lcd.drawString("Uncaught exception:", offset, 0);
   		lcd.drawString(t.getClass().getName(), offset, 2);
   		if (t.getMessage() != null) lcd.drawString(t.getMessage(), offset, 3);		
   		
   		if (t.getCause() != null) {
   			lcd.drawString("Caused by:", offset, 5);
   			lcd.drawString(t.getCause().toString(), offset, 6);
   		}
   		
   		StackTraceElement[] trace = t.getStackTrace();
   		for(int i=0;i<7 && i < trace.length ;i++) lcd.drawString(trace[i].toString(), offset, 8+i);
   		
   		lcd.refresh();
   		int id = Button.waitForAnyEvent();
   		if (id == Button.ID_ESCAPE) break;
   		if (id == Button.ID_LEFT) offset += 5;
   		if (id == Button.ID_RIGHT)offset -= 5;
   		if (offset > 0) offset = 0;
    }
    
    // Shutdown the EV3
   	try {
		Runtime.getRuntime().exec("init 0");
	} catch (IOException e) {
		// Ignore
	}
    System.exit(1);
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:36,代码来源:ExceptionHandler.java

示例2: select

@Override
public int select(int selectedIndex, int timeout) 
{ 
	if (selectedIndex >= _length)
		//might result in -1
		selectedIndex = _length -1;
	if (selectedIndex < 0)
		selectedIndex = 0;
	
	_quit = false;
	resetTimeout();

	if (_topIndex > selectedIndex)
		_topIndex = selectedIndex;
	if (_topIndex > _length - _height)
		_topIndex = _length - _height;			
	display(selectedIndex, 0,0);
	while(true)
	{
		int button;
		do
		{				
			if (_quit)
				return -2; // quit by another thread
			
			if (timeout > 0 && System.currentTimeMillis() - _startTime >= timeout) 
				return -3; // timeout
			
               button = Button.waitForAnyPress(BUTTON_POLL_INTERVAL);
		} while (button == 0);
		
		if(button == Button.ID_ENTER && selectedIndex >= 0 && selectedIndex < _length){
			clearArea();
			return selectedIndex;
		}
		if(button == Button.ID_ESCAPE)
			return -1; //Escape
		int temp = selectedIndex;
		int dir = 0;
		if(button == Button.ID_RIGHT && (!(_length <= 2 && selectedIndex > 0) || get2IconMode()))//scroll forward
		{
			selectedIndex++;
			// check for index out of bounds
			if(selectedIndex >= _length)
			{
				selectedIndex = 0;
				_topIndex = 0;
			}
			else if(selectedIndex >= _topIndex + _height){
				_topIndex = selectedIndex - _height + 1;
			}
			dir = -1;

		}
		if(button == Button.ID_LEFT && (!(_length <= 2 && selectedIndex < _length-1) || get2IconMode()))//scroll backward
		{
			selectedIndex --;
			// check for index out of bounds
			if(selectedIndex < 0)
			{			
				selectedIndex  = _length - 1;
				_topIndex = _length - _height;
			}
			else if(selectedIndex < _topIndex){
				_topIndex = selectedIndex;
			}
			dir = 1;

		}
		if (_length > 1)
		animate(temp,selectedIndex,dir);
	}
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:73,代码来源:GraphicMenu.java

示例3: enterNumber

/**
 * Clears the screen, displays a number and allows user to change
 * the digits of the number individually using the NXT buttons.
 * Note the array of bytes represent ASCII characters, not actual numbers.
 *
 * @param digits Number of digits in the PIN.
 * @param title The text to display above the numbers.
 * @param number Start with a default PIN. Array of bytes up to 8 length.
 * @return
 */
private boolean enterNumber(String title, byte[] number, int digits) {
    // !! Should probably check to make sure defaultNumber is digits in size
    int curDigit = 0;

    while ( true ) {
        newScreen();
        lcd.drawString(title, 0, 2);
        for ( int i = 0; i < digits; i++ ) {
            lcd.drawChar((char) number[i], i * 2 + 1, 4);
        }

        if ( curDigit >= digits ) {
            return true;
        }

        Utils.drawRect(curDigit * 20 + 3, 60, 20, 20);

        int ret = getButtonPress();
        switch ( ret ) {
            case Button.ID_ENTER: { // ENTER
                curDigit++;
                break;
            }
            case Button.ID_LEFT: { // LEFT
                number[curDigit]--;
                if ( number[curDigit] < '0' ) {
                    number[curDigit] = '9';
                }
                break;
            }
            case Button.ID_RIGHT: { // RIGHT
                number[curDigit]++;
                if ( number[curDigit] > '9' ) {
                    number[curDigit] = '0';
                }
                break;
            }
            case Button.ID_ESCAPE: { // ESCAPE
                curDigit--;
                // Return false if user backs out
                if ( curDigit < 0 ) {
                    return false;
                }
                break;
            }
        }
    }
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:58,代码来源:GraphicStartup.java

示例4: getIPAddress

/**
 * Requests an IP Address from the user where the server is running.<br>
 * For developer version only.
 */
private String getIPAddress() {
    String customaddress = "";
    if ( openrobertaProperties != null ) {
        customaddress = openrobertaProperties.getProperty("customaddress");
    }
    if ( customaddress == null || customaddress.equals("") ) {
        customaddress = "";
    }

    int i = 1;
    newScreen("Server?");
    lcd.drawString("lab.open-roberta.org", 0, 1, true);
    lcd.drawString("10.0.1.10:1999", 0, 2, false);
    lcd.drawString(customaddress, 0, 3, false);
    lcd.drawString("Another (type in)", 0, 4, false);
    lcd.drawString("(ESCAPE to exit)", 0, 7);

    while ( true ) {
        int id = Button.waitForAnyEvent(500);
        if ( id == Button.ID_ENTER ) {
            customaddress = select(i, customaddress);
            if ( customaddress == null ) {
                return enterIP();
            } else {
                return customaddress;
            }
        }
        if ( id == Button.ID_ESCAPE ) {
            return "";
        }
        if ( id == Button.ID_DOWN || id == Button.ID_RIGHT ) {
            if ( i != 4 ) {
                rewrite(i, false, customaddress);
                i++;
                rewrite(i, true, customaddress);
            } else {
                rewrite(i, false, customaddress);
                i = 1;
                rewrite(i, true, customaddress);
            }
        }
        if ( id == Button.ID_UP || id == Button.ID_LEFT ) {
            if ( i != 1 ) {
                rewrite(i, false, customaddress);
                i--;
                rewrite(i, true, customaddress);
            } else {
                rewrite(i, false, customaddress);
                i = 4;
                rewrite(i, true, customaddress);
            }
        }
    }
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:58,代码来源:GraphicStartup.java

示例5: toolException

private void toolException(Throwable t) {
    Sound.buzz();
    TextLCD lcd = BrickFinder.getDefault().getTextLCD(Font.getSmallFont());
    int offset = 0;
    // Get rid of invocation exception
    if ( t.getCause() != null ) {
        t = t.getCause();
    }
    while ( true ) {
        lcd.clear();
        lcd.drawString("Tool exception:", offset, 1);
        lcd.drawString(t.getClass().getName(), offset, 3);
        if ( t.getMessage() != null ) {
            lcd.drawString(t.getMessage(), offset, 4);
        }

        if ( t.getCause() != null ) {
            lcd.drawString("Caused by:", offset, 5);
            lcd.drawString(t.getCause().toString(), offset, 6);
        }

        StackTraceElement[] trace = t.getStackTrace();
        for ( int i = 0; i < 7 && i < trace.length; i++ ) {
            lcd.drawString(trace[i].toString(), offset, 8 + i);
        }

        lcd.refresh();
        int id = Button.waitForAnyEvent();
        if ( id == Button.ID_ESCAPE ) {
            break;
        }
        if ( id == Button.ID_LEFT ) {
            offset += 5;
        }
        if ( id == Button.ID_RIGHT ) {
            offset -= 5;
        }
        if ( offset > 0 ) {
            offset = 0;
        }
    }
    lcd.clear();
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:43,代码来源:GraphicStartup.java

示例6: select

@Override
public int select(int selectedIndex, int timeout) 
{ 
	_offset = 0;
	int maxLen = 0;
	for(String s: _items) {
		if (s.length() > maxLen) maxLen = s.length();
	}
	
	if (selectedIndex >= _length)
		//might result in -1
		selectedIndex = _length -1;
	if (selectedIndex < 0)
		selectedIndex = 0;
	
	_quit = false;
	resetTimeout();

	if (_topIndex > selectedIndex)
		_topIndex = selectedIndex;
	if (_topIndex > _length - _height)
		_topIndex = _length - _height;			
	display(selectedIndex, 0,0);
	while(true)
	{
		int button;
		do
		{				
			if (_quit)
				return -2; // quit by another thread
			
			if (timeout > 0 && System.currentTimeMillis() - _startTime >= timeout) 
				return -3; // timeout
			
               button = Button.waitForAnyPress(BUTTON_POLL_INTERVAL);
		} while (button == 0);
		
		if(button == Button.ID_ENTER && selectedIndex >= 0 && selectedIndex < _length){
			clearArea();
			return selectedIndex;
		}
		if(button == Button.ID_ESCAPE)
			return -1; //Escape
		int temp = selectedIndex;
		int dir = 0;
		if(button == Button.ID_DOWN && (!(_length <= 2 && selectedIndex > 0) || get2IconMode()))//scroll forward
		{
			selectedIndex++;
			// check for index out of bounds
			if(selectedIndex >= _length)
			{
				selectedIndex = 0;
				_topIndex = 0;
			}
			else if(selectedIndex >= _topIndex + _height){
				_topIndex = selectedIndex - _height + 1;
			}
			dir = -1;

		} else if(button == Button.ID_UP && (!(_length <= 2 && selectedIndex < _length-1) || get2IconMode()))//scroll backward
		{
			selectedIndex --;
			// check for index out of bounds
			if(selectedIndex < 0)
			{			
				selectedIndex  = _length - 1;
				_topIndex = _length - _height;
			}
			else if(selectedIndex < _topIndex){
				_topIndex = selectedIndex;
			}
			dir = 1;

		} else if(button == Button.ID_LEFT) {
			if (_offset > 0) _offset--;
		} else if(button == Button.ID_RIGHT) {
			if (_offset < maxLen - 15) _offset++;
		}
		if (_length > 1) animate(temp,selectedIndex,dir);
	}
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:81,代码来源:GraphicListMenu.java

示例7: getString

String getString() {
	StringBuilder sb = new StringBuilder();
	x = 0;
	y = 5;
	display();
	
	while (true) {
		int b = Button.waitForAnyPress();
		
		displayCursor(false);
		
		if (b == Button.ID_DOWN) {
			if (++y > 6) y = 1;
		} else if (b == Button.ID_UP) {
			if (--y < 1) y = 6;
		} else if (b == Button.ID_LEFT) {
			if (--x < 0) x = 17;
		} else if (b == Button.ID_RIGHT) {
			if (++x > 17) x = 0;
		} else if (b == Button.ID_ENTER) {
			if (y < 6) sb.append(lines[y-1].charAt(x));
			else {
				switch (lines[5].charAt(x)) {
				case 'U': 
					lines = upper;
					display();
				    break;
				case 'l':
					lines = lower;
					display();
					break;
				case 'x':
					if (sb.length() > 0) {
						sb.deleteCharAt(sb.length()-1);
						lcd.drawString(" ", sb.length(), 7);
					} else Sound.buzz();
					break;
				case 'D':
					return sb.toString();
				}
			}
		} else if (b == Button.ID_ESCAPE) {
			return null;
		}
		
		displayCursor(true);
		String s = sb.toString();
		if (s.length() > 18) s = s.substring(s.length() - 18, s.length());
		lcd.drawString(s, 0, 7);
	}
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:51,代码来源:Keyboard.java

示例8: calibrateHand

public void calibrateHand()
{
	System.out.println("Move hand up...");
	
    motor3.setStallThreshold(5, 15);
    motor3.setAcceleration(500);
    motor3.setSpeed(600);
	motor3.rotate(-720, false);
	motor3.resetTachoCount();
	
	positionHand(handDownPosition, true);
	
	boolean finished = false;
	while (!finished) {
		LCD.clear();
		LCD.drawString("hand down position: ", 0, 0);
		LCD.drawString("" + handDownPosition+ "%" , 5, 1);
		LCD.drawString("up, down: +-10%", 0, 2);
		LCD.drawString("left, right: +-2%", 0, 3);
		LCD.refresh();

		int buttonId = Button.waitForAnyPress();
		switch (buttonId) {
		case Button.ID_ESCAPE:
			finished = true;
			break;
		case Button.ID_UP:
			handDownPosition += 10;
			if (handDownPosition > 100) handDownPosition = 100;
			break;
		case Button.ID_DOWN:
			handDownPosition -= 10;
			if (handDownPosition < 0) handDownPosition = 0;
			break;
		case Button.ID_ENTER:
			finished = true;
			break;
		case Button.ID_LEFT:
			handDownPosition -= 2;
			if (handDownPosition < 0) handDownPosition = 0;
			break;
		case Button.ID_RIGHT:
			handDownPosition += 2;
			if (handDownPosition > 100) handDownPosition = 100;
			break;
		}
		positionHand(handDownPosition, true);
	}
	LCD.clear();
	LCD.drawString("set hand down ", 0, 3);
	LCD.drawString("position to " + handDownPosition+ "%" , 0, 4);
	LCD.refresh();
	positionHand(100, false);
	
}
 
开发者ID:stahlfabrik,项目名称:TRAC3R,代码行数:55,代码来源:TRAC3RsArm.java

示例9: select

/**
	 * Allows the user to scroll through the items, using the right and left buttons (forward and back)  The Enter key closes the menu <br>
	 * and returns the index of the selected item. <br>
	 * The menu display wraps items that scroll off the top will reappear on the bottom and vice versa.
	 * 
	 * This version of select allows the selected index to be set when the menu is first displayed.
	 * 
	 * @param selectedIndex the index to start the menu on
	 * @return the index of the selected item
	 **/
	public int select(int selectedIndex, int timeout) 
	{ 
		if (selectedIndex >= _length)
			//might result in -1
			selectedIndex = _length -1;
		if (selectedIndex < 0)
			selectedIndex = 0;
		
//		if (_length<_size) _size = _length;
		_quit = false;
		resetTimeout();
//		LCD.clear();
		if (_topIndex > selectedIndex)
			_topIndex = selectedIndex;
		if (_topIndex > _length - _height)
			_topIndex = _length - _height;			
		display(selectedIndex, _topIndex);
		while(true)
		{
			int button;
			do
			{				
				if (_quit)
					return -2; // quit by another thread
				
				if (timeout > 0 && System.currentTimeMillis() - _startTime >= timeout) 
					return -3; // timeout
				
				button = Button.waitForAnyPress(BUTTON_POLL_INTERVAL);
			} while (button == 0);
			
			if(button == Button.ID_ENTER && selectedIndex >= 0 && selectedIndex < _length)
				return selectedIndex;
			if(button == Button.ID_ESCAPE)
				return -1; //Escape
			if(button == Button.ID_RIGHT)//scroll forward
			{
				selectedIndex++;
				// check for index out of bounds
				if(selectedIndex >= _length)
				{
					selectedIndex = 0;
					_topIndex = 0;
				}
				else if(selectedIndex >= _topIndex + _height)
				{
					_topIndex = selectedIndex - _height + 1;
				}
			}
			if(button == Button.ID_LEFT)//scroll backward
			{
				selectedIndex --;
				// check for index out of bounds
				if(selectedIndex < 0)
				{
					selectedIndex  = _length - 1;
					_topIndex = _length - _height;
				}
				else if(selectedIndex < _topIndex)
				{
					_topIndex = selectedIndex;
				}
			}
			display(selectedIndex, _topIndex);
		}
	}
 
开发者ID:SnakeSVx,项目名称:ev3,代码行数:76,代码来源:TextMenu.java


注:本文中的lejos.hardware.Button.ID_LEFT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。