@g-manio007 said:
I thought that this form can provide help even in basic matters instead of discourage. I think that there is misunderstanding. I can promise that I won't bother you once again. And don't tell me what is impossible. Just two month ago I didn't know Java at all and I learnt java by myself and no one helped me. In my opinion it's not a sin to ask some advanced user for advice.
Don't be insulted when people offer you a more gradual way of learning something that you are clearly struggling with. From your perspective you don't see how badly you are struggling but we can easily see the dozens of concepts you are still not understanding about this subject. You still don't "know Java". It takes years. I'm just offering advice. You will struggle daily on this path for about a year if you keep going, I think.
But to be nice. I will give you the exact answer you need because I'm feeling generous today.
First, a few things:
-if you ever find yourself creating your main class or "application" over and over... you are doing something wrong. Take a step back and rethink what you are doing.
-If you ever find yourself having your main class or a panel or something implement an interface like Callable or XXXListener then you are also probably doing something wrong. Take a step back and rethink what you are doing.
-read carefully the examples people give you until you understand them. Look for many existing examples because they are everywhere. You haven't really understood the examples provided yet. If you can't explain why every line of code is there then you didn't really understand it.
I will try to modify your own example as best as I can...
[java]
(....)
//HERE IS MY SWING PANEL WHERE I AM ADDING JME CANVAS
class forum extends JPanel {
private static final long serialVersionUID = 1L;
public forum() {
prawo=new animation_test();
prawo.createCanvas();
rootNode=prawo.getRootNode();
JmeCanvasContext ctx = (JmeCanvasContext) prawo.getContext();
ctx.setSystemListener(prawo);
Dimension dim = new Dimension(100, 100);
canvas = ctx.getCanvas();
canvas.setPreferredSize(dim);
add(canvas);
listener sluchacza=new listener();
Timer czas=new Timer(2000,sluchacza);
czas.start();
}
private class listener implements java.awt.event.ActionListener
{
public void actionPerformed(ActionEvent e) {
a++;
if(a==2)
a=0;
}
}
public void doTheStuffInJme() {
animation_test.enqueue( new Callable() {
public Object call() {
return animation_test.doSomeStuff();
}
});
}
private Node rootNode;
private Canvas canvas;
private animation_test prawo;
private int a=0;
}
//AND THERE IS MY SIMPLE JME CLASS (ONLY UPDATE LOOP)
class animation_test extends SimpleApplication {
public void simpleInitApp() {
(...)
}
public Object doSomeStuff() {
// Do the stuff here that needs to happen on the JME thread
// And we have nothing to return but we could
return null;
}
public void simpleUpdate(float tpf) {
if(h==1)
{
player.rotate(0, 0, tpf);
h=-1;
}
}
}
[/java]
Or something like that.
If you want to learn Java, I suggest writing something simpler like a text adventure. You get to learn most of the elements of Java structure and game design without all of the 3D graphics, threading, etc. complexity. A decent Java programmer could churn one out over a weekend... which is a pretty good gauge of skill level achieved.