I want to make a very simple hangman program with a GUI that uses 6 images to show the progression of the game. I want to hardcode the word "Hello" and for each mistake the user makes the image changes. (Total of 6 progressive images).
I've managed to make the GUI using the Swing library on Netbeans, but I'm stumped as to how I can proceed with the actual code. Any pointers?
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.util.Random;
import java.io.*;
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ruzni
*/
public class GuessTheWord extends javax.swing.JPanel {
/**
* Creates new form GuessTheWord
*/
public GuessTheWord() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
char0 = new javax.swing.JLabel();
char1 = new javax.swing.JLabel();
char2 = new javax.swing.JLabel();
char3 = new javax.swing.JLabel();
char4 = new javax.swing.JLabel();
char5 = new javax.swing.JLabel();
aLetter = new javax.swing.JTextField();
TryLetter = new javax.swing.JButton();
Img = new javax.swing.JButton();
char0.setText("X");
char1.setText("X");
char2.setText("X");
char3.setText("X");
char4.setText("X");
char5.setText("X");
aLetter.setText("e");
aLetter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aLetterActionPerformed(evt);
}
});
TryLetter.setText("TryLetter");
TryLetter.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
TryLetterMouseClicked(evt);
}
});
Img.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img000.png"))); // NOI18N
Img.setText("jButton3");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(TryLetter)
.addComponent(aLetter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(char0)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(char1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(char2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(char3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(char4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(char5)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
.addComponent(Img, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(aLetter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(char0)
.addComponent(char1)
.addComponent(char2)
.addComponent(char3)
.addComponent(char4)
.addComponent(char5))
.addGap(71, 71, 71)
.addComponent(TryLetter))
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(Img, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(36, Short.MAX_VALUE))
);
}// </editor-fold>
private void aLetterActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_guessActionPerformed
}
private void TryLetterMouseClicked(java.awt.event.MouseEvent evt) {
}
// Variables declaration - do not modify
private javax.swing.JButton Img;
private javax.swing.JButton TryLetter;
private javax.swing.JTextField aLetter;
private javax.swing.JLabel char0;
private javax.swing.JLabel char1;
private javax.swing.JLabel char2;
private javax.swing.JLabel char3;
private javax.swing.JLabel char4;
private javax.swing.JLabel char5;
// End of variables declaration
}