Given the above discussion on using a panel to draw on and the fact that overriding paintComponent() really is the better way to go, I'd recommend the following, which is only a minor re-arrangement of your existing code (see comments on changes)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Hangman extends JFrame implements ActionListener {
// DECLARATIONS
JLabel inputL,
lettersL,
wordL;
JTextField inputTF,
lettersTF,
wordTF;
JButton checkB,
exitB;
final String WORD[] = {"SPLINTER", "MAGICAL", "FUNDAMENTAL", "ONYX", "UNIVERSAL", "MYSTERIOUS", "QUAIL", "DISCOVER", "UNIQUE", "OLYMPICS"};
static int index;
int chances = 6;
char[] blanks, guess;
String usedLetters = "";
// New reference to your hangman panel
JPanel graphicPanel;
public Hangman() {
// override paintComponent to call the drawHangman() method
graphicPanel = new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawHangman(g);
}
};
graphicPanel.setBackground(Color.black);
inputL = new JLabel("Enter a letter");
lettersL = new JLabel("Used Letters");
wordL = new JLabel("The Word");
inputTF = new JTextField();
lettersTF = new JTextField(26);
wordTF = new JTextField(16);
inputTF.setFont(new Font("Arial", Font.BOLD, 20));
inputTF.setHorizontalAlignment(0);
lettersTF.setFont(new Font("Arial", Font.BOLD, 20));
lettersTF.setEditable(false);
lettersTF.setHorizontalAlignment(JTextField.CENTER);
wordTF.setFont(new Font("Arial", Font.BOLD, 20));
wordTF.setEditable(false);
wordTF.setHorizontalAlignment(JTextField.CENTER);
String text = "";
for(int ctr = 0; ctr<WORD[index].length(); ctr++) {
text = text+"_ ";
}
wordTF.setText(text);
blanks = text.toCharArray();
checkB = new JButton("Check");
checkB.addActionListener(this);
exitB = new JButton("EXIT");
exitB.addActionListener(this);
Container pane = getContentPane();
pane.setLayout(new GridLayout(1, 2, 10, 0));
Container pane1 = new Container();
pane1.setLayout(new GridLayout(8, 1, 8, 8));
pane1.add(wordL);
pane1.add(wordTF);
pane1.add(lettersL);
pane1.add(lettersTF);
pane1.add(inputL);
pane1.add(inputTF);
pane1.add(checkB, BorderLayout.EAST);
pane1.add(exitB, BorderLayout.SOUTH);
pane.add(graphicPanel);
pane.add(pane1);
setResizable(false);
setTitle("Hangman BETA VERSION");
setLocation(120, 120);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500, 500);
}
/** draws the hangman graphic */
private void drawHangman(Graphics g) {
// the gallows
g.setColor(Color.red);
g.drawLine(130, 450, 240, 450);
g.drawLine(185, 40, 185, 450);
g.drawLine(110, 40, 185, 40);
g.drawLine(110, 40, 110, 100);
// intentional switch fall-through to
// draw the man as chances decrease
switch(chances) {
case 0:
g.drawArc(85, 150, 50, 30, 0, 180);
case 1:
g.drawLine(90, 130, 105, 130);
g.drawLine(115, 130, 130, 130);
case 2:
g.drawLine(70, 230, 150, 230);
case 3:
g.drawLine(110, 350, 70, 400);
g.drawLine(110, 350, 150, 400);
case 4:
g.drawLine(110, 180, 110, 350);
case 5:
g.drawOval(70, 100, 80, 80);
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==exitB) {
System.exit(0);
} else if(e.getSource()==checkB) {
char letter;
String input;
Boolean correct = false;
input = inputTF.getText();
letter = Character.toUpperCase(input.charAt(0));
if(input.equals(null)) {
JOptionPane.showMessageDialog(null, "You Have to Enter Something!", "ERROR", JOptionPane.WARNING_MESSAGE);
} else if(input.length()!=1) {
JOptionPane.showMessageDialog(null, "ENTER A SINGLE CHARACTER!", "ERROR", JOptionPane.WARNING_MESSAGE);
} else if(Character.isDigit(letter)) {
JOptionPane.showMessageDialog(null, "ENTER A CHARACTER NOT A NUMBER", "ERROR", JOptionPane.WARNING_MESSAGE);
} else {
guess = WORD[index].toCharArray();
for(int ctr = 0; ctr<WORD[index].length(); ctr++) {
if(letter==guess[ctr]) {
blanks[ctr*2] = guess[ctr];
correct = true;
}
}
if(!correct) {
usedLetters = usedLetters+letter+" ";
// update chances and repaint the panel
chances--;
graphicPanel.repaint();
if(chances==0) {
JOptionPane.showMessageDialog(null, "GAMEOVER!\n The Word is "+WORD[index], "GAMEOVER!", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
wordTF.setText(new String(blanks));
}
lettersTF.setText(new String(usedLetters));
inputTF.setText("");
}
}
public static void main(String[] args) {
index = (int)((Math.random())*10);
Hangman theFrame = new Hangman();
}
}