📄 stringitemdemo.java
字号:
//stringItemDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import itemex.*; //引入新创建的类 Button ,HyperLink
public class stringItemDemo extends MIDlet implements CommandListener, ItemCommandListener
{
private Command exitCommand;
StringItem strTitle;
Button btn
;
HyperLink hlink1, hlink2, hlink3;
Form form;
Font font;
public stringItemDemo()
{
//创建Form对象并设置命令
form = new Form("Demo Form");
exitCommand =new Command("Exit",Command.EXIT,1);
form.addCommand(exitCommand);
form.setCommandListener(this);
//创建StringItem对象并重新设置对象的字体
font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_LARGE);
strTitle = new StringItem("","StringItemDemo");
strTitle.setFont(font);
//创建三个HyperLink 对象
hlink1 = new HyperLink("SUN","http://www.sun.com",this);
hlink2 = new HyperLink("IBM","http://www.ibm.com",this);
hlink3 = new HyperLink("VCHelp","http://www.vchelp.net",this);
//创建按钮对象
btn = new Button("Button",this);
//把所有Item对象添加到Form 中
form.append(strTitle);
form.append(hlink1);
form.append(hlink2);
form.append(hlink3);
form.append(btn);
}
protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean p1 )
{
}
public void commandAction(Command c,Displayable d)
{
if (c ==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
public void commandAction(Command c, Item item)
{ if (c == Button.CLICK_COMMAND)
{
if(item instanceof Button)
{
System.out.println("Button "+ ((StringItem)item).getText() +" clicked");
}
} else if (c == HyperLink.CLICK_COMMAND)
{
if(item instanceof HyperLink)
{
System.out.println("Goto "+ ((StringItem)item).getText() );
}
} }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -