HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Hangman game background image possibly inefficient

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
imagebackgroundpossiblyhangmaninefficientgame

Problem

I'm making a Hangman game and it seems that my code doesn't provide me much freedom with using layouts. I added an image to my JFrame then I added a JPanel to my image which I'm using for all the JLabels and JTextFields but it seems to me that it's inefficient because in order to change the layout of my JTextFields or JLabels I have to change the layout of my image which messes up the entire looks of the game.

How can I make this code more efficient and give myself more freedom to change the layouts of my JLabels and JTextFields without messing everything up?

```
/PACKAGE DECLARATION/
package Game;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/****
GAME MECHANICS CLASS
***/
public class GameStructure {

/ INSTANCE DECLARATIONS /
private String []wordList = {"computer","java","activity","alaska","appearance","article",
"automobile","basket","birthday","canada","central","character","chicken","chosen",
"cutting","daily","darkness","diagram","disappear","driving","effort","establish","exact",
"establishment","fifteen","football","foreign","frequently","frighten","function","gradually",
"hurried","identity","importance","impossible","invented","italian","journey","lincoln",
"london","massage","minerals","outer","paint","particles","personal","physical","progress",
"quarter","recognise","replace","rhythm","situation","slightly","steady","stepped",
"strike","successful","sudden","terrible","traffic","unusual","volume","yesterday"};
private int []length = new int [64];
private JTextField tf;//text field instance variable (used)
private JLabel jl2;//label instance variable (used)
private JLabel jl3;//label instance (working on)
private String letter;

/***
LENGTH METHOD
/
public

Solution

You will need to do two things:

  • Split your image into multiple pieces that will be loaded into different panels.



  • Use appropriate layout managers when adding components so that you can control how components are arranged. Layout Manager Guide



Since I can't see your image, I can't make specific suggestions, but remember that you can layer multiple Layout Managers together.

Context

StackExchange Code Review Q#37916, answer score: 4

Revisions (0)

No revisions yet.