• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to change a JFrame class to non GUI  RSS feed

 
dirk dj jaeckel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
my first steps with java architecture ;)


i want to rewrite a GUI application of a game client who is declared like this:


My first goal is to run an application without all the GUI stuff so i made it:


is this okay like that ?

what i wanna do later is to use this class every time when a player is missing playing randomly.

comments welcome

dirk
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should only extend the Thread class if you want to alter the functionality of a thread. If you just want a class that can be run in a separate thread, you should implement the Runnable interface instead.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just go replacing classes with other classes.
You rarely ever need to extend Thread and it's unlikely that you need to do so in your scenario.
Why do you need to rewrite this code in the first place?
 
dirk dj jaeckel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:

Why do you need to rewrite this code in the first place?


As i wrote i wanna have an aplication without GUI, because the GUI is a gameclient showing game cards and so on, the Randomplayer should act randomly like the GUIclient but not showing anything

also i want in later steps taking this code over to the serverside so a new thread ist started everytime a player is missing ( the randomplayer will be replacable by other strategies i.e MCTS implementation)
 
dirk dj jaeckel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian Burkett wrote:You should only extend the Thread class if you want to alter the functionality of a thread. If you just want a class that can be run in a separate thread, you should implement the Runnable interface instead.


isnt it a problem that i need to implement Observer also ? Can i implement runnable in addition ? and how ?
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dirk dj jaeckel wrote:
Adrian Burkett wrote:You should only extend the Thread class if you want to alter the functionality of a thread. If you just want a class that can be run in a separate thread, you should implement the Runnable interface instead.


isnt it a problem that i need to implement Observer also ? Can i implement runnable in addition ? and how ?


A class can only extend one other class. It can implement as many interfaces as you want.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dirk dj jaeckel wrote:
Adrian Burkett wrote:You should only extend the Thread class if you want to alter the functionality of a thread. If you just want a class that can be run in a separate thread, you should implement the Runnable interface instead.


isnt it a problem that i need to implement Observer also ? Can i implement runnable in addition ? and how ?

If you are asking these questions then you really shouldn't be trying to read GUI code at all or worse trying to automagically transform it to an equivalent non gui app.
Better start by reading and understanding these basics. Otherwise there are lots of things you are going to omit/miss from the original code.
 
dirk dj jaeckel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E Armitage wrote:
If you are asking these questions then you really shouldn't be trying to read GUI code at all or worse trying to automagically transform it to an equivalent non gui app.
Better start by reading and understanding these basics. Otherwise there are lots of things you are going to omit/miss from the original code.



Some men have no choice ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!