I want a basic GUI for the game I am building, I've tried GBUI and FengGUI but had no luck getting either to work with JME2.0, so I'm stuck with JMEDesktop … this is fine with me but the problem is I can't seem to get a JLable to show up … I've taken and used all the code from the JMEDesktop example … all I did was add a Jlabel, everything alse shows up but the lable … why is that?? Any ideas??
I can assure you GBUI works just fine with JME 2.0 - if you let me know what issues you were having trouble with we can find a solution.
As for your JLabel issue, please post your code so we can know exactly what you're looking at and let's see if we can find a solution for that issue as well
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import com.jme.input.InputHandler;
import com.jme.input.action.InputActionEvent;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jmex.awt.swingui.JMEAction;
import com.jmex.awt.swingui.JMEDesktop;
public class GUI {
private Node guiNode;
private Node rootNode;
private InputHandler input;
private Terrain terrain;
private LightState light;
private Camera cam;
public GUI(Terrain t, Camera c, InputHandler i, Node r, LightState lightNode) {
terrain = t;
rootNode = r;
input = i;
light = lightNode;
cam = c;
Init();
}
private void Init() {
// /////// Create GUI
// create a node for ortho gui stuff
guiNode = new Node("gui");
guiNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
// create the desktop Quad
final JMEDesktop desktop = new JMEDesktop("desktop", DisplaySystem
.getDisplaySystem().getWidth(), 100, input);
// and attach it to the gui node
guiNode.attachChild(desktop);
// center it on screen
desktop.getLocalTranslation().set(512, 100, 0);
// perform all the swing stuff in the swing thread
// (Only access the Swing UI from the Swing event dispatch thread!
// See SwingUtilities.invokeLater()
// and
// http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
// for details.)
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// make it transparent blue
desktop.getJDesktop().setBackground(new Color(0, 0, 1, 0.2f));
desktop.getJDesktop().setBorder(
BorderFactory.createLineBorder(Color.red));
// create a swing button
final JButton button1 = new JButton("Sol");
final JButton button = new JButton("Star Map");
final JLabel moneyLabel = new JLabel("Test"); // this label is not visible
desktop.getJDesktop().add(button1);
// desktop has no layout - we layout ourselfes (could assign a
// layout to desktop here instead)
button1.setLocation(50, 25);
button1.setSize(button1.getPreferredSize());
// create a swing button
// and put it directly on the desktop
desktop.getJDesktop().add(button);
// desktop has no layout - we layout ourselfes (could assign a
// layout to desktop here instead)
button.setLocation(100, 25);
button.setSize(button.getPreferredSize());
String money = String
.valueOf(terrain.homeBase.properties.money);
moneyLabel.setText("Avaliable Funds " + money);
desktop.getJDesktop().add(moneyLabel);
moneyLabel.setSize(25, 100);
moneyLabel.setLocation(50, 75);
moneyLabel.setForeground(Color.white);
moneyLabel.setVisible(true);
// add some actions
// standard swing action:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// this gets executed in swing thread
// alter swing components ony in swing thread!
// button.setLocation( FastMath.rand.nextInt( 400 ),
// FastMath.rand.nextInt( 300 ) );
// logger.info( "clicked!" );
}
});
// action that gets executed in the update thread:
button.addActionListener(new JMEAction("my action", input) {
public void performAction(InputActionEvent evt) {
// this gets executed in jme thread
// do 3d system calls in jme thread only!
terrain.buildStructure("Bank");
guiNode.updateRenderState(); // this call has no effect
// but should be done in
// jme thread :)
}
});
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// terrain.showBuildMenu = true;
}
});
// action that gets executed in the update thread:
button1.addActionListener(new JMEAction("my action", input) {
public void performAction(InputActionEvent evt) {
// this gets executed in jme thread
// do 3d system calls in jme thread only!
terrain.showBuildMenu = true;
guiNode.updateRenderState(); // this call has no effect
// but should be done in
// jme thread :)
}
});
}
});
// don't cull the gui away
guiNode.setCullHint(Spatial.CullHint.Never);
// gui needs no lighting
// guiNode.setLightCombineMode( LightState.LIGHTS_ENABLED);
// update the render states (especially the texture state of the
// deskop!)
guiNode.updateRenderState();
// update the world vectors (needed as we have altered local translation
// of the desktop and it's
// not called in the update loop)
guiNode.updateGeometricState(0, true);
}
public Node getGuiNode() {
return guiNode;
// DisplaySystem.getDisplaySystem().getRenderer().draw( guiNode );
}
}
as you can see all I did was add a JLabel named moneyLabel, everything else shows up fine except the JLabel. Also ... after reading your reply I again set up GBUI on my Eclips IDE ... I followed the directions from this link http://code.google.com/p/gbui/wiki/CreatingYourJmeInterfaceUsingGbui1 which I got from this forum ... still all I get is this ...
java.lang.VerifyError: class com.jmex.bui.PolledRootNode overrides final method findCollisions.(Lcom/jme/scene/Spatial;Lcom/jme/intersection/CollisionResults;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"
I'll keep trying ... I'm assuming it has something to do with the build path/libraries ect.
standtrooper said:
I can assure you GBUI works just fine with JME 2.0 - if you let me know what issues you were having trouble with we can find a solution.
As for your JLabel issue, please post your code so we can know exactly what you're looking at and let's see if we can find a solution for that issue as well
Well after a little work I did get GBUI to work ... thanks for the assurance I'm glad I gave it another go because I'm already days ahead in building my GUI than I would have been if I continued to try and work with JMEDesktop.