JME:如何让整个屏幕在白色无按键,等等等等(JME: How to get the complet

2019-07-29 16:37发布

请看看下面的代码

首先,请注意,我是100%的新手到Java手机。

在这里,我正在点亮和振动就当用户点击该按钮。 可是,我真的想创造出把整个屏幕变成白色SOS应用程序,并去黑头,这样,在该线程。 我想我并没有达到,通过这个程序,因为即使在灯上,按钮仍然存在。 我试图把“形式”颜色为“白色”,但好像JME没有“颜色”类。

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();
                }
            }
        }

    }
}

Answer 1:

    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();

}

现在创建一个帆布和实施这样的paint方法:

  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>
            }
        }


Answer 2:

使用javax.microedition.lcdui.Canvas ,而不是形式。 这个例子可以让你开始



文章来源: JME: How to get the complete screen in WHITE without buttons, etc etc