java速度入门九_j2me基本控件

来源:互联网 发布:收银软件有哪些 编辑:程序博客网 时间:2024/05/16 14:05

一个textarea。

package hi;

import javax.microedition.lcdui.Display;

import javax.microedition.lcdui.Form;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

public class Hi extends MIDlet {

 Display display;
 public static Hi instance;
 public Hi() {

  super();

  display = Display.getDisplay(this);

 }

 protected void destroyApp(boolean arg0){

 }

 protected void pauseApp() {

 }

 protected void startApp() throws MIDletStateChangeException {

  Form form = new Form("Hello S60 JAVA");

  form.append("Hello World!");

  display.setCurrent(form);
  Display.getDisplay(this).setCurrent(new TBoxDisp("TextBox", "test for textbox", 100, 0));
  

 }
 public void exitAapp()
 {
  this.notifyDestroyed();
  this.destroyApp(true);
 }

}

package hi;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;

public class TBoxDisp extends TextBox implements CommandListener {
 private Command cmdOkCommand=new Command("Ok", Command.OK, 1);
 private Command cmdExitCommand=new Command("Exit", Command.EXIT, 1);
 
 private int constraints;
 final static int ANY=0;
 
 public TBoxDisp(String title,String text,int maxsize,int constraints)
 {
  super(title, text, maxsize, constraints);
  this.constraints=constraints;
  addCommand(cmdOkCommand);
  addCommand(cmdExitCommand);
  setCommandListener(this);
 }

 public void commandAction(Command arg0, Displayable arg1) {
  // TODO Auto-generated method stub
  if(arg0.equals(cmdOkCommand))
  {
   switch(constraints)
   {
   case ANY:
    System.out.println("Type:Any Max_Size:"+this.getMaxSize()+"CurrentSize:"+this.size());
   }
  }else if(arg0.equals(cmdExitCommand)){
   Hi.instance.exitAapp();
  }

 }

}

原创粉丝点击