Java Tutorial/J2ME/ImageItem — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:00, 1 июня 2010
Содержание
- 1 Combine ImageItem.LAYOUT_NEWLINE_BEFORE, ImageItem.LAYOUT_CENTER,ImageItem.LAYOUT_NEWLINE_AFTER for ImageItem
- 2 ImageItem with default image layout
- 3 ImageItem with Image layout center
- 4 ImageItem with image layout left
- 5 ImageItem with image layout right
- 6 Load png image to ImageItem
- 7 Use ImageItem in a form
Combine ImageItem.LAYOUT_NEWLINE_BEFORE, ImageItem.LAYOUT_CENTER,ImageItem.LAYOUT_NEWLINE_AFTER for ImageItem
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemLAYOUT_NEWLINE_BEFORELAYOUT_CENTER extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem(null, red, ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
ImageItem with default image layout
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemLAYOUT_DEFAULT extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem("Default", red, ImageItem.LAYOUT_DEFAULT, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
ImageItem with Image layout center
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemLAYOUT_CENTER extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem("Center", red, ImageItem.LAYOUT_CENTER, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
ImageItem with image layout left
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemLAYOUT_LEFT extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem("Left", red, ImageItem.LAYOUT_LEFT, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
ImageItem with image layout right
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemLAYOUT_RIGHT extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem("Right", red, ImageItem.LAYOUT_RIGHT, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
Load png image to ImageItem
<source lang="java">
import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemExampleMIDlet extends MIDlet {
protected Display display; protected void startApp() { display = Display.getDisplay(this); Form form = new Form("Demo"); form.append("line"); try { Image red = Image.createImage("/red.png"); form.append(new ImageItem(null, red, ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_DEFAULT | ImageItem.LAYOUT_NEWLINE_AFTER, null)); } catch (IOException ex) { form.append("Failed to load images"); } display.setCurrent(form); } protected void pauseApp() { } protected void destroyApp(boolean unconditional) { }
}</source>
Use ImageItem in a form
<source lang="java">
import javax.microedition.lcdui.rumand; import javax.microedition.lcdui.rumandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.midlet.MIDlet; public class ImageItemMIDlet extends MIDlet implements CommandListener {
private Command exitCommand = new Command("exit", Command.EXIT, 1); private ImageItem imageItem; private Image aImage; private Display display = Display.getDisplay(this); public ImageItemMIDlet() { try { aImage = Image.createImage("/10.png"); } catch (Exception e) { } imageItem = new ImageItem("Java 2", aImage, ImageItem.LAYOUT_CENTER, "image"); } public void startApp() { Form aForm = new Form("ImageItem"); aForm.append(imageItem); aForm.addCommand(exitCommand); aForm.setCommandListener(this); display.setCurrent(aForm); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } }
}</source>