📄 imageitemdemo.java
字号:
//imageItemDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import itemex.*;
public class imageItemDemo extends MIDlet implements CommandListener, ItemCommandListener
{
private Command exitCommand, aCommand1, aCommand2, aCommand3;
private Form form;
ImageItem imageLogo,imageAlt;
ButtonImage buttonPlay;
HyperLinkImage linkCode;
public imageItemDemo()
{
exitCommand =new Command("Exit",Command.EXIT,1);
aCommand1 =new Command("ImageLogo",Command.SCREEN,2);
aCommand2 =new Command("Button",Command.SCREEN,2);
aCommand3 =new Command("HyperLink",Command.SCREEN,2);
form = new Form("ImageItem form");
form.addCommand(exitCommand);
form.addCommand(aCommand1);
form.addCommand(aCommand2);
form.addCommand(aCommand3);
form.setCommandListener(this);
try
{//程序创建时添加PLAIN 模式的图像
imageLogo = new ImageItem("logo.png", Image.createImage("/logo.png"),
Item.LAYOUT_DEFAULT ,
"large.png");
form.append(imageLogo);
}
catch(Exception e) { System.out.println("load image error");}
}
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();
}
else if (c ==aCommand1)
{//切换到imageLogo
if(form.get(0) != imageLogo)
{//检查当前显示,如果imageLogo没有被显示才执行操作
form.delete(0);
form.append(imageLogo);
}
}
else if (c ==aCommand2)
{//切换到buttonPlay
if(buttonPlay == null)
{//第一次使用时才创建对象
try
{
buttonPlay = new ButtonImage("Play Sound", Image.createImage("/announce.png"),
Item.LAYOUT_EXPAND|Item.LAYOUT_NEWLINE_AFTER|Item.LAYOUT_2 ,
"announce.png", this);
}
catch(Exception e) { System.out.println("load image error");}
}
if(form.get(0) != buttonPlay)
{//检查当前显示,如果buttonPlay没有被显示才执行操作
form.delete(0);
form.append(buttonPlay);
}
}
else if (c ==aCommand3)
{//切换到linkCode
if(linkCode == null)
{//第一次使用时才创建对象
try
{
linkCode = new HyperLinkImage("http://wyy.vchelp.net/book/jmcode.zip",
Image.createImage("/download.png"),
Item.LAYOUT_EXPAND|Item.LAYOUT_NEWLINE_AFTER|Item.LAYOUT_2,
"download.png", this);
}
catch(Exception e) { System.out.println("load image error");}
}
if(form.get(0) != linkCode)
{//检查当前显示,如果linkCode没有被显示才执行操作
form.delete(0);
form.append(linkCode);
}
}
}
public void commandAction(Command c,Item i)
{
if(i == linkCode)
{//处理来自HyperLink的命令
System.out.println("goto "+ i.getLabel());
}
else if(i == buttonPlay)
{//处理来自Button的命令
System.out.println("Command "+ i.getLabel());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -