Java me 在java应用程序中显示消息框或通知栏?
在我的J2ME应用程序中,我有一些窗体和一些后台运行的线程。如果在这些线程中的任何一个线程中,我决定在应用程序顶部显示一个消息框或通知栏,我有一个问题,即不知道我是哪个表单,因此我不知道隐藏消息框或通知栏后显示哪个表单Java me 在java应用程序中显示消息框或通知栏?,java-me,Java Me,在我的J2ME应用程序中,我有一些窗体和一些后台运行的线程。如果在这些线程中的任何一个线程中,我决定在应用程序顶部显示一个消息框或通知栏,我有一个问题,即不知道我是哪个表单,因此我不知道隐藏消息框或通知栏后显示哪个表单 有人有什么建议吗?ticker是一种在屏幕顶部提供滚动文本的对象。股票代码与显示屏关联,而不是与屏幕关联。您可以使用screen.setTicker(Ticker t)方法在屏幕上放置一个Ticker,如下面的代码所示 但是,您可以将同一个Ticker对象与多个屏幕关联。该实现在
有人有什么建议吗?ticker是一种在屏幕顶部提供滚动文本的对象。股票代码与显示屏关联,而不是与屏幕关联。您可以使用screen.setTicker(Ticker t)方法在屏幕上放置一个Ticker,如下面的代码所示 但是,您可以将同一个Ticker对象与多个屏幕关联。该实现在显示器的某个固定部分(在本例中为显示器的顶部)上呈现股票代码。股票代码不是一个项目。它直接从java.lang.Object派生而来,为您提供了一条线索,说明为什么股票代码可以绑定到显示器而不是屏幕。它不需要从Item派生,因为它实际上不是放置在表单中的东西
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Ticker;
import javax.microedition.lcdui.Form;
/**
This class demonstrates use of the Ticker MIDP UI
component class.
@see javax.microedition.lcdui.Gauge
*/
public class TickerDemo extends Form
implements CommandListener
{
private String str =
"This text keeps scrolling until the demo stops...";
private Ticker ticker = new Ticker(str);
private Command back = new Command("Back", Command.BACK, 1);
private static Displayable instance;
/**
Constructor.
*/
public TickerDemo()
{
super("Ticker demo");
instance = this;
addCommand(back);
setTicker(ticker);
setCommandListener(this);
}
...
}
希望这对你有帮助。谢谢您可以使用“Display.getCurrent()”获取已显示的当前表单。例如,此画布是一个SplashScreen,在屏幕中显示之前获取当前表单:
import javax.microedition.lcdui.Canvas;
/* */ import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
/* */ import javax.microedition.lcdui.Graphics;
/* */ import javax.microedition.lcdui.Image;
public class StaticSplashScreen extends Canvas
implements Runnable {
private HelloMIDlet mainMidlet;
private boolean isSplashOver;
private long currentTime;
private long previousTime;
private Form currentForm;
public StaticSplashScreen(HelloMIDlet mid) {
this.mainMidlet = mid;
currentForm = (Form) this.mainMidlet.getDisplay().getCurrent();
this.previousTime = System.currentTimeMillis();
new Thread(this).start();
}
protected void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.drawString("In the name of God", 40, 70, 0);
}
public void run() {
while (!this.isSplashOver) {
this.currentTime = System.currentTimeMillis();
if (this.currentTime - this.previousTime >= 10000L) {
this.isSplashOver = true;
}
}
this.mainMidlet.getDisplay().setCurrent(currentForm);
}
}
在此midlet中,您可以看到带有一些命令的两个表单。当您在每个表单中按“帮助”时,method()调用并播放SplashScreen,10秒钟后,您可以看到再次启动它的表单:
public class HelloMIDlet extends MIDlet implements CommandListener {
...
public void commandAction (Command command, Displayable displayable) {
...
if (command == helpCommand) {
method ();
}
...
}
public Form getForm () {
if (form == null) {
form = new Form ("Welcome");
form.addCommand (getHelpCommand());
form.setCommandListener (this);
}
return form;
}
public void method () {
if (true) {
StaticSplashScreen sss = new StaticSplashScreen(this);
this.getDisplay().setCurrent(sss);
} else {
}
}
public Form getForm1 () {
if (form1 == null) {
form1 = new Form ("form1");
form1.addCommand (getHelpCommand ());
form1.setCommandListener (this);
}
return form1;
}
}
你能展示演示你的问题的代码片段吗?最好使用需要使用画布。。。。不是J2me表单。。。