Really any ideas will help but id like to try and make the game hangman. id like to mak it simples in a gui(i dont really need the image of the hangman) but id like to atleast have it show all the letters and make them dissappear as they guess the word. I just would like any ideas of helo from anyone?
Thanks alot

Use a JLabel to display the guessed-so-far word. If a letter hasn't been guessed correctly it should display "_" instead of the letter, which is why you'll need to space your word also (so the _ don't run together, looking like a line). Use a String internally in your program to remember the correct word. Use a keyboard of JButtons to display the letters a-z. Once the user clicks one, use jbutton.setEnabled(false) so they can't accidentally click the same letter again.

There are undoubtedly a thousand other ways to do this program but if you don't want to do it my way, then think a little for yourself, try to do the project, and tell us where you're getting stuck. If you want, you can propose specifics about how you plan to do your project and I'll tell you if it is going to work or not.

you can use a text box to draw your hangman if you want and just use character based graphics.

i.e.
____________ __________
| |
\ /
|
/|\
/ | \
|
/ \
just draw your hangman in the textbox in stages.

Mike

Okay so I was thinkin I would need to gong a way to compare the word I . I figur I can take the random word make it a string and when they choose a letter compare it to string. It there an easy way to compare or do I have to split the string. Also is there some type of structure I could randomly store strings in. Like a struct.
Thanks again any help will do

You are comparing a letter at a time. maybe 3 strings can be used.

String TheWord;

String LettersGuesses;

String GuessedWord;

check if they gussed a new letter in letters guessed. then i'd say you check if its in the word, and you write the new letter to all spots in guessed word. use like _ if you dont know the letter in guessed word.

Mike

mport java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.awt.Color;
public class Project extends JFrame {

public Project() {

super();


String[] array;
array = new String[15];
array[0] = "cool";
System.out.println(array[0]);


TextArea out = new TextArea();

JButton a = new JButton("A");
JButton b = new JButton("B");
JButton c = new JButton("C");
JButton d = new JButton("D");
JButton e = new JButton("E");
JButton f = new JButton("F");
JButton g = new JButton("G");
JButton h = new JButton("H");
JButton i = new JButton("I");
JButton j = new JButton("J");
JButton k = new JButton("K");
JButton l = new JButton("L");
JButton m = new JButton("M");
JButton n = new JButton("N");
JButton o = new JButton("O");
JButton p = new JButton("P");
JButton q = new JButton("Q");
JButton r = new JButton("R");
JButton s = new JButton("S");
JButton t = new JButton("T");
JButton u = new JButton("U");
JButton v = new JButton("V");
JButton w = new JButton("W");
JButton x = new JButton("X");
JButton y = new JButton("Y");
JButton z = new JButton("Z");

out.setText(array[0]);


add(new JLabel());

setLayout(new FlowLayout(3,3,3));


add(a);
add(b);
add(c);
add(d);
add(e);
add(f);
add(g);
add(h);
add(i);
add(j);
add(k);
add(l);
add(m);
add(n);
add(o);
add(p);
add(q);
add(r);
add(s);
add(t);
add(u);
add(v);
add(w);
add(x);
add(y);
add(z);


add(out);
}
}

class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){

}
}
// So this is what i have so far, i need help linking up the buttons. When a button is clicked i would like it to test to see if the letter is in the word. i need help with the button listener part. how can i link it up, right now i just want to use array[0] which is "cool" as the test value

first your class needs in addition to extend JFrame it needs
extends JFrame implements ActionListener // think that's the caplitzliation
maybe an include i dont remember.

then I do in the method that adds(a) after my adds to set up a,

a.addActionListener(this);

action listeners in java windowing set up design elements to listen for events.

then i use this function to catch events happening:

public void actionPerformed(ActionEvent event){
if(event.getActionCommand().equals("A"))
{	
// A was pressed, its matching the text of the field associated with the command in this case "A"
}

} // end method

Also convention is to have a panel defined as well. dont know if that is done or not.

Mike

This article has been dead for over six months. Start a new discussion instead.