vendredi 20 février 2015

Java: call a runnable in actionListener to repaint canvas

I am doing a program to implement a simple version of blackjack as an applet.


I have four classes:



  1. Game21Pane(extends Panel):


It has a canvas to display the card users pick and the game state where they are currently at. It also has three buttons (start, pick and restart) and three button listeners for those buttons



  1. GameCanvas(extends Canvas):


It is designed to paint the canvas object in Game21Pane



  1. displayThread(implement runnable):


It call GameCanvas to actually do the painting



  1. GameApplet:


I use this the call the main applet program.


My question is:


What kind of design pattern can i use to make my code easier to be understand and maintained?


My original thought would be call canvas inside my runnable class, and then call runnable inside my button listener. But does it seem to be a high coupling design? I could not come up with a good way to put everything together.


Thank you in advance.


Aucun commentaire:

Enregistrer un commentaire