I have this issue that when i include the jme scene in a jFrame with other components, it steals the focus, and cannot edit values in like jTextfield.
The problem is, this only happens in my pc, i’ve tried to run the code on another pc and it worked just fine.
Use AWT Panels if you want to use swing. I have to say though that if you want to do your GUI in swing just because you have a visual editor you don’t do yourself a favor. The separate awt and opengl thread will give you headaches and things like these integration details as well. Furthermore you can only use the application on desktop.
but why did it work on other machines?!
and would you explain more what you mean please.
thanks in advance.
@bigt said:
but why did it work on other machines?!
and would you explain more what you mean please.
thanks in advance.
a) Because LWJGL's canvas display is bugged beyond recognition.
b) AWT and the update loop are separate threads, you have to enqueue the calls to either side properly which makes for an inconvenient ride. Furthermore AWT only exists in desktop java, not Android.
@normen said:
b) AWT and the update loop are separate threads, you have to enqueue the calls to either side properly which makes for an inconvenient ride. Furthermore AWT only exists in desktop java, not Android.
How can I do that? A code example would be great, thanks for your help.
Read the tutorial I linked you to, it even includes code examples.
You do know about the Swing threading model right? (If you don’t then you need to go read up on it and understand it before you do anything substantial using Swing).
@zarch said:
Read the tutorial I linked you to, it even includes code examples.
You do know about the Swing threading model right? (If you don't then you need to go read up on it and understand it before you do anything substantial using Swing).
I did read it, but i thought it concerns threads of my creation, i'll read about the threading model and retry, thanks.
It works the same as swingUtilities.invokeLater, see the example code right in the first Paragraph of the linked Document. But again, if this is new to you it will easily nullify any time you gain by not learning nifty gui.
Here is my class, what do i need to change?
i read about the swing threading model, but i still don’t understand.
[java]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package jme3test.bullet;
import com.jme3.system.JmeCanvasContext;
import java.awt.Canvas;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
/**
*
-
@author Dell
*/
public class TestPInput extends javax.swing.JFrame {
public int ang = 45, length = 1, mass = 1;
TestPhysicsHingeJoint in=new TestPhysicsHingeJoint(length, mass, ang);
static Canvas cc;
static JmeCanvasContext c;
Timer ts = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
jTextArea1.setText("Swings: " + (in.sw - 1) / 2 + "n" + "Time taken: " + in.time2 / 1000);
}
});
/**
- Creates new form TestPInput
*/
public TestPInput() {
initComponents();
jTextField1.setText("1");
jTextField2.setText("1");
jTextField3.setText("45");
// in = new TestPhysicsHingeJoint(length, mass, ang);
in.setPauseOnLostFocus(false);
in.createCanvas();
c = (JmeCanvasContext) in.getContext();
cc = c.getCanvas();
cc.setBounds(0, 0, 640, 480);
cc.setVisible(true);
add(cc);
ts.start();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mass = Integer.parseInt(jTextField1.getText());
length = Integer.parseInt(jTextField2.getText());
ang = Integer.parseInt(jTextField3.getText());
in.reUpdate(length, mass, ang);
in.setupJoint();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
in.stop();
c.destroy(true);
cc.setVisible(false);
in = new TestPhysicsHingeJoint(length, mass, ang);
in.createCanvas();
c = (JmeCanvasContext) in.getContext();
cc = c.getCanvas();
cc.setBounds(0, 0, 640, 480);
cc.setVisible(true);
add(cc);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
in.reUpdate(Integer.parseInt(jTextField2.getText()), Integer.parseInt(jTextField1.getText()), Integer.parseInt(jTextField3.getText()));
in.setupJoint();
// in.simpleUpdate(100);
// cc.repaint();
// add(cc);
}
/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/ Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestPInput().setVisible(true);
}
});
}
[/java]
Sorry, I won’t write your code for you.
don’t write, i only need guidance where the problem is.
The problem is you don’t enqueue the calls from awt or gl, as said.
i’m kinda a beginner, so I don’t know what does that mean, i tried to read about threading but in vain.
So what I said already sets in, you have problems with this integration you cannot solve. I told you the example is right first on the linked page, if that doesn’t help its too hard for you I’m afraid.
i’m afraid that is the case. what should i do then?!
Maybe read up on Java concurrency and threading in a pure Java context, from basics.
It might help you understand it better than the quick example given in the link, although the example given does contain everything you need it doesn’t go into tons of detail.
Just use nifty for your gui…
Bigt: Threading is hard. 3d programming is hard. Swing programming (with decent results) is hard.
If you are trying to learn all three at once you are in trouble.
Use Nifty for the GUI (it’s already integrated into JME3 for you). No threading to worry about.
Now you only need to learn Nifty (read the Nifty Bible, linked to the right) and 3d programming. One less thing to worry about (and Nifty is simpler than Swing).
Ok, thank you all for your help.