JME:如何在不使用按钮等的情况下以白色获取完整的屏幕 [英] JME: How to get the complete screen in WHITE without buttons, etc etc

查看:73
本文介绍了JME:如何在不使用按钮等的情况下以白色获取完整的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看下面的代码

首先,请注意,我是Java Mobile的100%新手.

First, Please note I am a 100% newbie to Java Mobile.

在这里,当用户单击按钮时,我会点亮并振动.但是,我真的很想创建一个SOS应用程序,它将整个屏幕变成白色,然后在线程中变成黑色.我想我没有通过该应用程序实现这一目标,因为即使灯亮着,按钮仍然在那里.我试图将窗体"颜色更改为白色",但是JME似乎没有颜色"类.

In here, I am making the light on and vibrate on when user click the button. However, I really wanted to create a SOS application which turn the whole screen into white, and go to black, like that, in the thread. I guess I didn't achieve that by this app because even the lights are on, the buttons are still there. I tried to turn the "Form" color to "white" but it seems like JME has no "Color" class.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Midlet extends MIDlet{

    private Form f;
    private Display d;
    private Command start,stop;
    private Thread t;

    public Midlet()
    {
        t = new Thread(new TurnLightOn());

    }

    public void startApp() 
    {
        f = new Form("Back Light On");


       d = Display.getDisplay(this);
       d.setCurrent(f);        

       start = new Command("Turn On",Command.OK,0);
       stop = new Command("Turn Off",Command.OK,1);

       f.addCommand(start);
       f.setCommandListener(new Action());



    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional)
    {
        this.notifyDestroyed();
    }

    private class Action implements CommandListener
    {

        public void commandAction(Command c, Displayable dis) 
        {
            f.append("Light is Turnning On");

            t.start();

        }

    }

     private class ActionOff implements CommandListener
    {

        public void commandAction(Command c, Displayable dis) 
        {


        }

    }

    private class TurnLightOn implements Runnable
    {

        public void run() 
        {
            f.append("Working");
            for(int i=0;i<100;i++)
            {

                try 
                {

                    d.flashBacklight(200);
                    d.vibrate(200);

                    Thread.sleep(1000);

                } 
                catch (InterruptedException ex)
                {
                    ex.printStackTrace();
                }
            }
        }

    }
}

推荐答案

    public void startApp() 
        {
            f = new Form("Back Light On");


           d = Display.getDisplay(this);


           start = new Command("Turn On",Command.OK,0);
           stop = new Command("Turn Off",Command.OK,1);

           f.addCommand(start);
           f.setCommandListener(new Action());

    myCanvas = new MyCanvas();
     d.setCurrent(myCanvas);   
            myCanvas.repaint();

}

现在创建一个画布并实现这样的绘制方法:

Now create a canvas and implement paint method like this:

  class MyCanvas extends Canvas {
            public void paint(Graphics g) {
                // create a 20x20 black square in the center

                // clear the screen first
                g.setColor(0xffffff);
                g.fillRect(0, 0, getWidth(), getHeight());

                g.setColor(0xffffff); // make sure it is white color

                // draw the square, <b>changed to rely on instance variables</b>
                <b>g.fillRect(x, y, getWidth(), getHeight());</b>
            }
        }

这篇关于JME:如何在不使用按钮等的情况下以白色获取完整的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆