Some comments:
- Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.
Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.
- You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.
You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.
- Consider making a subclass of
JFrame
for your game view. It will be the only thing responsible for setting up the visuals. You can pass it aGameStructure
object (which would be only the game logic), so it can combine everything.Consider making a subclass of
JFrame
for your game view. It will be the only thing responsible for setting up the visuals. You can pass it aGameStructure
object (which would be only the game logic), so it can combine everything. for(j = 0; j<64; j++)
— Instead of hard-coding the length of theworldList
, you should be able to adjust automatically if I add new words to the word list without changing anything else.for(j = 0; j<64; j++)
— Instead of hard-coding the length of theworldList
, you should be able to adjust automatically if I add new words to the word list without changing anything else.tf.addActionListener(new ActionListener() { …
— Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implementActionListener
, so you can passthis
toaddActionListener
.tf.addActionListener(new ActionListener() { …
— Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implementActionListener
, so you can passthis
toaddActionListener
.