473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Having trouble creating a Hangman game in Java using Netbeans.

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:
Expand|Select|Wrap|Line Numbers
  1. if(wrong == true) {
  2.       wrongnum++;
  3.       //JOptionPane.showMessageDialog(null, wrongnum);
  4.  
  5.       if(wrongnum == 1) {
  6.          ImageIcon icon = new ImageIcon("head.png");
  7.          JOptionPane.showMessageDialog(null,icon);
  8.          jLabel2.setIcon(icon);
  9.          jButton1.setEnabled(false);
  10.             }
  11.         }
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:
Expand|Select|Wrap|Line Numbers
  1.   int chc = 0;
  2.         boolean wrong = false;
  3.  
  4.         for(int i = 0; i < chw.length; i++){
  5.             if(chw[i] == 'A' | chw[i] == 'a') {
  6.                 if(chc == 0)
  7.                 {
  8.                     chc = i;
  9.                     us1Label.setText("A");
  10.                     AButton.setEnabled(false);
  11.                     wrong = false;
  12.                 }
  13.              if(chc == 1)
  14.                 {
  15.                     chc = i;
  16.                     us2Label.setText("A");
  17.                     AButton.setEnabled(false);
  18.                     wrong = false;
  19.                 }
  20.  
It continues on like this with three more if statements, they just go from if(chc == 0) to if(chc == 3).
May 9 '11 #1
0 1631

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: adolph | last post by:
Over the last two years I've written an MS accedd based program. The back end is also backend. It is a realestate inventory management program. It uses a third party program to manipulate...
1
by: Jozef | last post by:
Hello. I'm having trouble creating a blank solution (and ASP.net web application) from my laptop. I own the server (in fact it's sitting right next to me) and have added the URL to the trusted...
2
by: Dave | last post by:
It seems that if I put just html inside a master page, everything works fine. But if I put other controls (such as WebControls and/or my own custom controls), I can't seem to access the content...
3
by: mutaher | last post by:
geography(name, region, area, population, gdp) Table Name = Geography Column Name = Name, Region, Area, Population, GDP Help me execute this statement List the name and region of countries...
2
by: tesa | last post by:
I am not able to figure out how to make this work. I am trying to create a hangman game. I am in a basic javascripting class. I am to only use very basic code as you can see. I am able to use any...
0
by: Madmartigan | last post by:
Hi I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way. I have included my code thus...
0
by: pinbot | last post by:
Can anyone tell me how to make a file readable as far as permissions go? Thanks for any help given!
8
by: tidiz | last post by:
Hi, I'm trying to make a hangman game that should look like this: Welcome to Hangman ______ Your guess: c Success! __cc__ Your guess: b
0
by: Ajinkya Doshi | last post by:
I want the stepwise description of publishing the web service through netbeans......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.