Test it:
- Code: Select all
import lejos.nxt.*;
public class NXTCommTest {
/**
* @param args
*/
public static void main(String[] args) {
try{
MemoryBar mbObj = new MemoryBar();
LCDUILite1 LCDUIObj = new LCDUILite1();
//NXTBotMenu NBM = new NXTBotMenu();
//NXTCommsListener NCL = new NXTCommsListener();
mbObj.start();
LCDUIObj.start();
//NBM.start();
//NCL.start();
}catch(Exception e){
}
}
}
- Code: Select all
import lejos.nxt.*;
public class MemoryBar extends Thread{
public MemoryBar(){
}
//Thread method
public void run()
{
while(true)
{
try{
int memory = (int)(Runtime.getRuntime().freeMemory());
LCD.drawInt(memory,0,7);
LCD.refresh();
}catch(Exception e){
}
}
}
}
- Code: Select all
import javax.microedition.lcdui.*;
import lejos.nxt.*;
public class LCDUILite1 extends Thread implements CommandListener{
private static final int CMDID_BACK_TO_MAIN = 1;
private static final int CMDID_EXIT_APP = 2;
private static final Command BACK_COMMAND = new Command(CMDID_BACK_TO_MAIN, Command.BACK, 0);
private static final Command EXIT_COMMAND = new Command(CMDID_EXIT_APP, Command.STOP, 2);
private List menu = new List("Test Components", Choice.IMPLICIT);
// Main menu items
private TextBox input = new TextBox("Enter Some Text:", "", 16, TextField.ANY);
private Alert soundAlert = new Alert("Sound Alert");
private Alert exitAlert = new Alert("Exit");
private Gauge alertGauge = new Gauge(null, false, 20, 0);
private Display display;
public LCDUILite1(){
}
private void showNXJBug(){
LCD.drawString("asdf",0,0);
int battery = (int)(Battery.getVoltageMilliVolt() );
LCD.drawInt(battery,0,1);
int memory = (int)(Runtime.getRuntime().freeMemory());
LCD.drawInt(memory,0,2);
LCD.refresh();
}
public void menu(){
// Create main menu
menu = new List("Test Components", Choice.IMPLICIT);
menu.append("Test TextBox", null);
menu.append("Test Alert", null);
menu.setSelectedIndex(0, true);
menu.addCommand(EXIT_COMMAND);
menu.setCommandListener(this);
input.addCommand(BACK_COMMAND);
input.setCommandListener(this);
// Set alert properties
soundAlert.setType(Alert.ALERT_TYPE_ERROR);
soundAlert.setTimeout(2000);
soundAlert.setString("** ERROR **");
soundAlert.setIndicator(alertGauge);
// Start displaying main menu and handling buttons
display = Display.getDisplay();
display.setCurrent(menu);
display.show(true);
}
//Event controller
public void commandAction(Command c, Displayable d) {
if (c.getCommandId() == CMDID_BACK_TO_MAIN) {
// Display main menu again
display.setCurrent(menu);
} else if (c.getCommandId() == CMDID_EXIT_APP) {
// Request to exit application
exitAlert.setType(Alert.ALERT_TYPE_CONFIRMATION);
exitAlert.setString("Exit Lejos?");
exitAlert.setCommandListener(this);
display.setCurrent(exitAlert);
} else {
// Handle system commands
if (d == exitAlert) {
if (exitAlert.getConfirmation()) {
display.quit();
} else {
display.setCurrent(menu);
}
} else if (d == menu) {
List list = (List) display.getCurrent();
if (list.getSelectedIndex() == 0) {
display.setCurrent(input);
} else if (list.getSelectedIndex() == 1) {
display.setCurrent(soundAlert);
}
}
}
}
//Thread method
public void run()
{
while(true)
{
try{
this.menu();
//this.showNXJBug();
}catch(Exception e){
}
}
}
}
