?? splashcanvas.java
字號:
/*
*
* Copyright ? 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
package com.sun.perseus.demo;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* The <code>SplashCanvas</code> class is used to display an image as soon as
* a MIDlet is started and, possibly, show information about the coming demo
* while that demo is loading.
*/
public class SplashCanvas extends Canvas {
/**
* The minimal amount of time to wait when a splash screen is displayed.
*/
public static final long SPLASH_MIN_LENGTH = 2500; // 2.5s
/**
* The image this splash screen should show.
*/
Image image;
/**
* The time the last display started.
*/
private long start;
/**
* @param image the image this splash screen should show.
*/
public SplashCanvas(final Image image) {
this.image = image;
}
/**
* @param imageURL the url for the splash screen image.
*/
public SplashCanvas(final String imageURL) {
boolean error = false;
if (imageURL == null) {
error = true;
} else {
InputStream splashStream = getClass().getResourceAsStream(imageURL);
try {
image = Image.createImage(splashStream);
} catch (Exception e) {
e.printStackTrace();
error = true;
}
}
if (error) {
// Create simple stub splash screen.
System.err.println("Creating image : " + getWidth() + " / " + getHeight());
image = Image.createImage(getWidth(), getHeight());
System.err.println("Image created");
Graphics g = image.getGraphics();
System.err.println("Graphics created");
g.setColor(255, 255, 255);
System.err.println("Color set");
g.fillRect(0, 0, getWidth(), getHeight());
System.err.println("Background filled");
g.setColor(0, 0, 0);
System.err.println("Color set 2");
Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
System.err.println("Font created : " + font);
g.setFont(font);
System.err.println("Font set");
g.drawString("Splash Screen", getWidth() / 2, getHeight() / 2,
Graphics.TOP | Graphics.LEFT);
System.err.println("String drawn");
}
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
int x = (getWidth() - image.getWidth()) / 2;
int y = (getHeight() - image.getHeight()) / 2;
g.drawImage(image, x, y, Graphics.TOP | Graphics.LEFT);
}
/**
* @param display the Display on which this splash screen should paint.
*/
public void display(final Display display) {
display.setCurrent(this);
start = System.currentTimeMillis();
}
/**
* Switches to the input Display after the minimal time has ellapsed.
*
* @param display the display to switch to.
* @param canvas the canvas to set after the minimal amount of time has ellapsed.
*/
public void switchTo(final Display display, final Canvas newCanvas) {
long end = System.currentTimeMillis();
long waitMore = SPLASH_MIN_LENGTH - (end - start);
if (waitMore > 0) {
try {
Thread.currentThread().sleep(waitMore);
} catch (InterruptedException ie) {
// Do nothing.
}
}
display.setCurrent(newCanvas);
}
/**
* Shows the splash screen and waits for SPLASH_MIN_LENGTH before restoring
* the input Displayable.
*
* @param display the display on which to show the splash screen.
* @param displayable the displayable to restore after the help screen has been shown.
*/
public void showAndWait(final Display display, final Displayable displayable) {
// Show the splashCanvas for a little while.
display.setCurrent(this);
Thread th =
new Thread() {
public void run() {
try {
Thread.currentThread().sleep(SPLASH_MIN_LENGTH);
} catch (InterruptedException ie) {
}
display.setCurrent(displayable);
}
};
th.start();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -