GUIs in Applets

What's the suggested method for building a GUI in applets?



I've gotten FengGui running in a regular application, but not in an applet.

Does anyone have experience (positive or negative) with this?



Thanks.

Should be identical as doing it in a standard jME game (non-applet).

That's what I thought.



However, when I try creating the fengui display, I get a Mouse not created error when checking for maxsize and no display gets created.



I followed that up by trying to explicitly create the mouse before the display.  That throws a display no created error.    :stuck_out_tongue:



So, if anyone has explicit suggestions, thoughts or some piece of knowledge I need before I try to walk through a concrete wall (eg it won't work in an applet because of X; or dont create an input handler in the applet base) it would be greatly appreciated.



btw darkfrog I love your GameState stuff.  Do you see a reason that wouldn't work in applets?



Thanks in advance.


You may have to check in the FengGUI forums if you're having issues with it.  GameStates should work just fine in an Applet.

I'll look on the fenggui forums.

Took a little wiggling, but I got gamestates running in an applet(mostly).



For those initerested here is the exception thrown when creating feng gui:

java.lang.IllegalStateException: Mouse must be created.

at org.lwjgl.input.Cursor.getMaxCursorSize(Cursor.java:137)

at org.fenggui.render.lwjgl.LWJGLCursorFactory.<init>(Unknown Source)

at org.fenggui.render.lwjgl.LWJGLBinding.<init>(Unknown Source)

at org.fenggui.render.lwjgl.LWJGLBinding.<init>(Unknown Source)

at myjme.Demo.FengGUIGameState.buildUI(FengGUIGameState.java:56)

at myjme.Demo.FengGUIGameState.<init>(FengGUIGameState.java:48)

at myjme.Demo.StationAlphaMain.simpleAppletSetup(StationAlphaMain.java:180)

at myjme.Demo.DEBaseApplet$SimpleAppletCanvasImplementor.simpleSetup(DEBaseApplet.java:383)

at com.jmex.awt.SimpleCanvasImpl.doSetup(Unknown Source)

at com.jmex.awt.lwjgl.LWJGLCanvas.paintGL(Unknown Source)

at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:308)

at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:339)

at sun.awt.RepaintArea.updateComponent(Unknown Source)

at sun.awt.RepaintArea.paint(Unknown Source)

at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

I'm not there yet, but after much head spinning from similarly named classes I can contribute something that hopefully someone with more engine familiarity can suggest a workaround for.



I'm running inside an APPLET.

As a result of this, an AWTGLCanvas is created rather than a window.

It appears that LWJGL only registers the display system as being built if a window is created.  (lwjgl.Display.isCreated()  tests against the var window_created).



Thus, when trying to create the LWJGLBinding, everything fubars (since Display.create has not happened).



Cross posting to fenggui and lwjgl.

Thanks for ideas.




Thank you to Fool Running on the lwjgl forum to providing me the answer.

Using an AWTGLCanvasBinding rather than a LWJGLBinding solved my particular instance of this problem.

Hey,



sorry to reactivate such an old Thread but I ran into the same problem. I know how to get a AWTGLCanvasBinding (org.fenggui.render.lwjgl.AWTGLCanvasBinding()), but I'm having trouble figuring out how exactly to create the Binding. It seems to need a AWTGLCanvas, but I have no idea where I could get the corresponding AWTGLCanvas for the Canvas that I paint on?


If I remember correctly, I was able to get FengGUI to work in an applet by passing the glCanvas defined in *JmeApplet to AWTGLCanvasBinding's constructor. glCanvas is private, so I changed it to protected, and everything worked. I don't have the code, must have lost it somehow, but if you have trouble I'll probably be able to recover it (I think I should have it in my repository).



I'm not sure if this is the best way, however, but I wasn't able to find any other solution. Also, I only tried this for jme1; when I switched to jme2, I switched to gbui (where I'm still drawing to glCanvas, by the way). If you run into problems - post here, I might be able to help you out (well, or not :slight_smile: I haven't solved all my problems myself yet, and have been busy for the last month or so).

Maybe something in here can help…



import java.awt.Canvas;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.util.concurrent.Callable;

import com.jme.input.InputSystem;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.system.DisplaySystem;
import com.jme.system.canvas.JMECanvas;
import com.jme.system.canvas.JMECanvasImplementor;
import com.jme.util.GameTaskQueue;
import com.jme.util.GameTaskQueueManager;
import com.jmex.awt.input.AWTKeyInput;
import com.jmex.awt.input.AWTMouseInput;
import com.jmex.awt.lwjgl.LWJGLAWTCanvasConstructor;
import org.lwjgl.opengl.AWTGLCanvas;


public class GfxCanvas {

    private final JMECanvasImplementor implementor;
    private final Canvas gfxCanvas;

    public GfxCanvas( final JMECanvasImplementor imp, int width, int height ) throws Exception {
        this.implementor = imp;

        final DisplaySystem display = DisplaySystem.getDisplaySystem();

        display.registerCanvasConstructor( "AWT", LWJGLAWTCanvasConstructor.class );
        gfxCanvas = (Canvas) display.createCanvas( width, height );

        gfxCanvas.addComponentListener( new ComponentAdapter() {

            @Override
            public void componentResized( ComponentEvent ce ) {
                doResize();
            }
        } );

        gfxCanvas.addFocusListener( new FocusListener() {

            public void focusGained( FocusEvent arg0 ) {
                ( (AWTKeyInput) KeyInput.get() ).setEnabled( true );
                ( (AWTMouseInput) MouseInput.get() ).setEnabled( true );
            }

            public void focusLost( FocusEvent arg0 ) {
                ( (AWTKeyInput) KeyInput.get() ).setEnabled( false );
                ( (AWTMouseInput) MouseInput.get() ).setEnabled( false );
            }
        } );

        setImplementor( implementor );

        if( !KeyInput.isInited() ){
            KeyInput.setProvider( InputSystem.INPUT_SYSTEM_AWT );
        }
        if( !MouseInput.isInited() ){
            MouseInput.setProvider( InputSystem.INPUT_SYSTEM_AWT );
            AWTMouseInput.setup( gfxCanvas, false );
        }


        ( (AWTMouseInput) MouseInput.get() ).setEnabled( true );
        gfxCanvas.addMouseListener( (MouseListener) MouseInput.get() );
        gfxCanvas.addMouseWheelListener( (MouseWheelListener) MouseInput.get() );
        gfxCanvas.addMouseMotionListener( (MouseMotionListener) MouseInput.get() );

        ( (AWTKeyInput) KeyInput.get() ).setEnabled( true );
        KeyListener kl = (KeyListener) KeyInput.get();
        gfxCanvas.addKeyListener( kl );

        setTargetRate( 60 );
        setDrawWhenDirty( false );
        setUpdateInput( true );
    }

    public Canvas getCanvas() {
        return gfxCanvas;
    }

    public void setImplementor( JMECanvasImplementor impl ) {
        ( (JMECanvas) gfxCanvas ).setImplementor( impl );
    }

    public void setUpdateInput( boolean doUpdate ) {
        ( (JMECanvas) gfxCanvas ).setUpdateInput( doUpdate );
    }

    public int getTargetSyncRate() {
        return ( (JMECanvas) gfxCanvas ).getTargetSyncRate();
    }

    public boolean isDrawWhenDirty() {
        return ( (JMECanvas) gfxCanvas ).isDrawWhenDirty();
    }

    public boolean isUpdateInput() {
        return ( (JMECanvas) gfxCanvas ).isUpdateInput();
    }

    public void makeDirty() {
        ( (JMECanvas) gfxCanvas ).makeDirty();
    }

    public void setDrawWhenDirty( boolean whenDirty ) {
        ( (JMECanvas) gfxCanvas ).setDrawWhenDirty( whenDirty );
    }

    public void setTargetRate( int fps ) {
        ( (JMECanvas) gfxCanvas ).setTargetRate( fps );
    }

    public void exit() {
        ( (JMECanvas) gfxCanvas ).killGfxContext();
    }

    private void doResize() {

        if( !implementor.isSetup() ){
            return;
        }

        GameTaskQueueManager.getManager().getQueue( GameTaskQueue.UPDATE ).enqueue(
                new Callable() {

                    public Object call() {
                        implementor.resizeCanvas( gfxCanvas.getWidth(), gfxCanvas.getHeight() );
                        return null;
                    }
                } );
    }
}

hello! I recently updated jmonkey source from svn, in order to get access to changes in applets classes for use with LWGL 2.0, I had been using fenggui and had the problems showed in this thread (and solved like this tread said…) but now, with the new applets, things go wrong again!

the problem is again the binding with Fenggui.



as this thread suggested, the old solution was to use  AWTGLCanvasBinding rather than a LWJGLBinding.

the former class need a instance of AWTGLCanvas, and the old JME applets provide that.



but, new applets are using awt.Canvas, so, there is no way to use the old binding.

trying to use the LWGLBinding throws the "Mouse must be created" Exception…     :?


well.. no answers about this.. so, I solved this delaying one frame the initialization of fenggui, so, there is mouse and display ready, and I can use LWGLBinding after all.