English 中文(简体)
如何防止j2me 屏幕旋转?
原标题:How to prevent screen rotation in j2me?

I m programming in j2me. How can I prevent screen rotation in j2me for all phones that support screen rotation?

谢谢

最佳回答

添加到显示列表

For Nokia devices: Nokia-MIDlet-App-Orientation : Landscape

For Samsung devices: MIDlet-ScreenMode : Landscape

问题回答

If you use Canvas to draw your screen (not LCDUI, not LWUIT, not any other framework) you may implement sizeChanged method to be notified when the rotation happens.

在此情况下, 您可以将屏幕拖到图像中, 并使用 Sprite 旋转它。 例如, 只支持在构建器中使用的下面代码的景观模式 :


    int width = Math.max(super.getWidth(), super.getHeight());
    int height = Math.min(super.getWidth(), super.getHeight());
    // screen and sprite are attributes
    screen = Image.createImage(width, height);
    sprite = new Sprite(screen);
    if (super.getWidth() < super.getHeight()) { // portrait screen
        sprite.setTransform(Sprite.TRANS_ROT90);
        sprite.setPosition(0, 0);
    }

以及以下方法:


    public void sizeChanged (int w, int h) {
        // lastWidth and lastHeight are attributes
        lastWidth = w;
        lastHeight = h;
        if (sprite == null)  return;
        if (super.getWidth() < super.getHeight()) { // portrait screen
            sprite.setTransform(Sprite.TRANS_ROT90);
        } else {
            sprite.setTransform(Sprite.TRANS_NONE);
        }
        sprite.setPosition(0, 0);
    }

    protected void paint(Graphics g1) {
        if (super.getWidth() != lastWidth
            || super.getHeight() != lastHeight) {
            sizeChanged(super.getWidth(), super.getHeight());
        }
        Graphics g = screen.getGraphics();
        // ... do your drawing on g
        this.sprite.setImage(screen, screen.getWidth(), screen.getHeight());
        sprite.paint(g1);
    }





相关问题
add text in http request string url

ok i made a midlet through which i can connect to server pages and get soem information as response. For example i made a midlet through which i acced url: http://example.com/?u=nepal&t=1 Now i ...

Do I have to do a setSize() on a Vector before using it?

Given private final Vector v = new Vector(); //instance variable the following 3 lines are in an instance method in the same class. 1. int length = v.capacity(); 2. int size = v.size(); ...

Is the situation with Java ME improving?

It seems to be the consensus that developing for Java ME is not as cross platform as you might expect, particularly compared to say java SE, but it is difficult to assess how the situation is evolving....

Privileged operations in netbeans mobility

I m writing a Java ME app that will use privileged operations such as messaging. By default the user is prompted to confirm each of these operations, but I would like to run it as a background ...

ClassFormatError: 56 while using hessian in j2me

I am trying to use the hessian j2me implementation @ http://hessian.caucho.com/ using java me sdk 3.0. http://hessian.caucho.com/doc/hessian-overview.xtp#Hessian%20Client%20for%20a%20cell-phone ...