Original Post
🔒 Locked
[java] Threads
Advertisement
This is in fact my problem;
I create a JFrame where I just added a yellow label to the content pane, to work as a game presentation screen…
There’s also a JMenu too, where the user must click “Start” (a JmenuItem) to play the game…
That’s the point: selecting Start in the Menu will make this:
- Create a new JPanel object
- Create an instance of the GameArea class
- Add the gameArea object to the JPanel
- Set the JPanel as the content pane of the JFrame
It’s important to say that the GameArea extends JComponent and implements the Runnable interface, so in some moment it would be a good idea to create a Thread, and make it run…My doubt is if this is possible?
Help me please!!
Thanks for all!!
I create a JFrame where I just added a yellow label to the content pane, to work as a game presentation screen…
There’s also a JMenu too, where the user must click “Start” (a JmenuItem) to play the game…
That’s the point: selecting Start in the Menu will make this:
- Create a new JPanel object
- Create an instance of the GameArea class
- Add the gameArea object to the JPanel
- Set the JPanel as the content pane of the JFrame
It’s important to say that the GameArea extends JComponent and implements the Runnable interface, so in some moment it would be a good idea to create a Thread, and make it run…My doubt is if this is possible?
Help me please!!
Thanks for all!!
You don't need to give GameArea a Runnable Interface.
Just create a thread that affects GameArea.
Its not a good idea to make a main class also a thread or whatever.
Just create a class lets ,say GameThread, like this:
Hope this helps.
Just create a thread that affects GameArea.
Its not a good idea to make a main class also a thread or whatever.
Just create a class lets ,say GameThread, like this:
public class GameThread extends Thread{ private Component mComp; /* Pass GameArea through here - comp */ public GameThread(Component comp) { if(comp == null) throw new NullPointerException(); mComp = comp; } public void run() { /* Use GameArea */ }}Hope this helps.
Quote:
Original post by Last Attacker
You don't need to give GameArea a Runnable Interface.
Just create a thread that affects GameArea.
Its not a good idea to make a main class also a thread or whatever.
Why not? I have never had a problem doing that. If you do it in a separate class, then you need to expose a lot more functionality than you might want to.
Hello you people!!
Hey, hold your horses man!! It’s just a 2D sprites based game, a plagiarism of the Atari’s Tennis game, I don’t remember the real name, it’s a classical, very old…
Although it’s a simple game, I think it’s nice and necessary to create a thread to control de frps.
My paint method, with an off screen implementation is in this class I mentioned…
But, as Last Attacker says:
I got it! I create a thread that invokes the paint method, calling repaint() ,
20 times per second, so 20 frps!
To be honest I think that I made a confusion to explain my problem, well I’m not a fluent English speaker, and neither writer!!
But some problems were solved and I thank you all!!
I restart my work and now I have to look for the error in the old version…
When I find it, I’ll post here, OK?
Thanks everybody!! See ya!!
Quote:
Is it a RTS, RPG or FPS game?
Hey, hold your horses man!! It’s just a 2D sprites based game, a plagiarism of the Atari’s Tennis game, I don’t remember the real name, it’s a classical, very old…
Quote:
…why in hell are you trying to Thread this?
Although it’s a simple game, I think it’s nice and necessary to create a thread to control de frps.
My paint method, with an off screen implementation is in this class I mentioned…
But, as Last Attacker says:
Quote:
Just create a thread that affects GameArea.
I got it! I create a thread that invokes the paint method, calling repaint() ,
20 times per second, so 20 frps!
Quote:
I might have misunderstood the context
To be honest I think that I made a confusion to explain my problem, well I’m not a fluent English speaker, and neither writer!!
But some problems were solved and I thank you all!!
I restart my work and now I have to look for the error in the old version…
When I find it, I’ll post here, OK?
Thanks everybody!! See ya!!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement