I currently have two know problems with my current code.
First, I can't seem to get the image to display. I have the gallows already displaying and I want to get the head (that is the next pic that shows the gallows with the head) to display but its not working.. I believe I have the right code but I'm thinking that I am putting the wrong file path in? I'm using a JOptionPane to double check the image and it always comes up blank. So, I'm clearly not getting the image. Here's what I'm attempting to use for that:
My next problem is this. I'm limiting my words to four letters and using four labels to represent the word. My code works fine for getting the first letter and displaying it in the correct spot. But any letters after that move the other letters around or make them completely go away and the letter I just used duplicates. (I'm using one button per letter so it's like a small keyboard on the screen). Here's a snippet of my code for the 'A' button:
It continues on like this with three more if statements, they just go from if(chc == 0) to if(chc == 3).
First, I can't seem to get the image to display. I have the gallows already displaying and I want to get the head (that is the next pic that shows the gallows with the head) to display but its not working.. I believe I have the right code but I'm thinking that I am putting the wrong file path in? I'm using a JOptionPane to double check the image and it always comes up blank. So, I'm clearly not getting the image. Here's what I'm attempting to use for that:
Code:
if(wrong == true) {
wrongnum++;
//JOptionPane.showMessageDialog(null, wrongnum);
if(wrongnum == 1) {
ImageIcon icon = new ImageIcon("head.png");
JOptionPane.showMessageDialog(null,icon);
jLabel2.setIcon(icon);
jButton1.setEnabled(false);
}
}
Code:
int chc = 0;
boolean wrong = false;
for(int i = 0; i < chw.length; i++){
if(chw[i] == 'A' | chw[i] == 'a') {
if(chc == 0)
{
chc = i;
us1Label.setText("A");
AButton.setEnabled(false);
wrong = false;
}
if(chc == 1)
{
chc = i;
us2Label.setText("A");
AButton.setEnabled(false);
wrong = false;
}