Originally Posted by araujo2nd
my name is andre, im from south africa, i was wondering if any1 could help me with a hangman application, im now in grade 11 and have a huge portfolio piece to do by the 15th which i have just started now, i have always struggled with java and would rele appreciate all the help that i can get. Pls could some1 help me as much as u can, im nt asking u to do the program for me but if u could pls take me steps through it as i really would like to pass the piece as it goes into my matric portfolio for college. at the moment im using DR JAVA and netbeans for GUI
The program should be a hangman program which stores random words, it must keep a high score table with the number of tries each user takes and my ask user to input their name before they play the game.
many thanks in advanced
Andre
47 11371
Originally Posted by araujo2nd
my name is andre, im from south africa, i was wondering if any1 could help me with a hangman application, im now in grade 11 and have a huge portfolio piece to do by the 15th which i have just started now, i have always struggled with java and would rele appreciate all the help that i can get. Pls could some1 help me as much as u can, im nt asking u to do the program for me but if u could pls take me steps through it as i really would like to pass the piece as it goes into my matric portfolio for college. at the moment im using DR JAVA and netbeans for GUI
The program should be a hangman program which stores random words, it must keep a high score table with the number of tries each user takes and my ask user to input their name before they play the game.
many thanks in advanced
Andre
Hi and welcome to TSDN. Hope you'll have a great time here.
You realize of course that the first step is to design your program.
You need to decide how to store all the words (with an allowance for easy addition of other categories say, countries, actors, Bible books e.t.c).
Then you have to write down your hangman algorithm. This shoild be pretty stright forward but just make sure you consider all the special cases.
The last thing to design is your interface. You need to design which components make up your interface and whether or not you're going to add a bit of animation in there e.t.c
After the design is done, writing the program will be so easy it will be such a bore.
Hi,
do you want your program to have a graphical user interface?
I'd be happy to help you with some advice and feedback.
How familiar are you with java?
keep me posted.
Cheers
Hi sir thank you for the reply
Yes i would like a GUI for the program
Im familiar with java but just not really good with it, the teacher at school is not great and i got lost in it, i can do most basics etc
preferably i would like to create a program that presents a blank frame, and the user gets 7 inputs to guess the word (he can either type the whole word or letter by letter), each time he gets one wrong, a piece of the hangman is displayed, and once all of the hangman is put together, it must tell the user the word and that he has lost.
many thanks
Hi sir thank you for the reply
Yes i would like a GUI for the program
Im familiar with java but just not really good with it, the teacher at school is not great and i got lost in it, i can do most basics etc
preferably i would like to create a program that presents a blank frame, and the user gets 7 inputs to guess the word (he can either type the whole word or letter by letter), each time he gets one wrong, a piece of the hangman is displayed, and once all of the hangman is put together, it must tell the user the word and that he has lost.
many thanks
You really should create the interface last.
It will all be much easier and faster if you start with the design like I said.
I have already made that in Netbeans, should i show u the screen shot?
I have already made that in Netbeans, should i show u the screen shot?
What I'd really like to see is your hangman algorithm but I guess it won't hurt to attach it. You'd have to make a post, click the edit button on the post and then add the attachment from there.
i dont have an algorithm:( i dont ever do them correctly.
The GUI is just very basic, i still do not know how to implement an image of the hangman into the Jframe
im struggling to upload the pic, could i email it or PM to u?
I have to work on it a lot tonight
i dont have an algorithm:( i dont ever do them correctly.
The GUI is just very basic, i still do not know how to implement an image of the hangman into the Jframe
im struggling to upload the pic, could i email it or PM to u?
I have to work on it a lot tonight
No need for emails or PMs.
We prefer to have all the help provided on the open forum.
Sorry to say this but chances are if you can't design it, then you can't code it. You really need to work on the design part of programing if you want to make your programing life easier.
Have you listed down the various parts that make up this program yet?
yes i have, previously a good friend of mine helped me code this program but he has left an im stuck with the program that builds but will not compile. it says no class found, he is really good with java so i dont know how he could have made that error.
the code is (netbeans): - package hangman;
-
-
import java.awt.*;
-
import javax.swing.*;
-
import java.util.*;
-
import java.lang.*;
-
import java.applet.*;
-
import java.awt.event.*;
-
-
public class Main extends Applet implements ActionListener,ItemListener
-
{
-
Button button[];
-
TextField word,letter;
-
TextField guess;
-
Label label1,label2,label3;
-
String alphabuttons[];
-
Panel panel1,panel2,panel3,pana,panb,panc;
-
Font font;
-
CheckboxGroup group;
-
Checkbox beg,inte,adv;
-
String begin[];
-
String inter[];
-
String advan[];
-
int lives,select;
-
String answer = " ";
-
String missy;
-
String buffy = "--------";
-
StringBuffer store2= new StringBuffer(buffy);
-
int counta = lives;
-
public void Main()
-
{
-
this.setLayout(new BorderLayout());
-
// sets up the array to produce the alphabet buttons on the grid
-
alphabuttons = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
-
-
// sets up the arrays with the words to be guessed in all three stages
-
begin = new String[]{"CAT","POWER","UNDER"};
-
inter = new String[]{"SECTION","VISITOR","INTENDED"};
-
advan = new String[]{"BEAUTIFUL","CHEERFUL","ENTHUSIASM"};
-
-
// create and arrange panel 1 which will house the text fields and the labels
-
-
panel1 = new Panel(); // panel 1 will hold the two labels and text fields at the top of the applet
-
add("North",panel1);
-
-
panel1.setLayout(new BorderLayout());
-
label1 = new Label("GUESS THE WORD"); // create the label
-
font = new Font("TimesRoman",Font.ITALIC,16);
-
label1.setFont(font); // set the font to the label
-
-
pana = new Panel();
-
panel1.add("North",pana);
-
pana.add(label1); // add the label to the panel
-
label1.setAlignment(label1.CENTER); // set the label to the centre
-
-
panb = new Panel();
-
panel1.add("Center",panb);
-
word = new TextField(24); // creates the text field for the word set to 24 chars
-
word.addActionListener(this);
-
word.setEditable(true); // allows text to be edited
-
panb.add(word,"CENTER"); // adds the text field to the panel
-
label3 = new Label("Win/Lose");
-
label3.setFont(font);
-
panb.add(label3);
-
label1.setAlignment(label1.RIGHT);
-
letter = new TextField(10);
-
letter.addActionListener(this);
-
panb.add(letter,"RIGHT");
-
-
panc = new Panel();
-
panel1.add("South",panc);
-
-
label2 = new Label("How Many Goes Left"); // create the label and intiliase
-
label2.setFont(font); // sets the font previously defined for label 1
-
panc.add(label2);
-
label2.setAlignment(label2.LEFT); // Sets the label left
-
-
guess = new TextField(3); // initialises the guess text field to 3 chars
-
guess.addActionListener(this);
-
panc.add(guess);
-
-
// create and arrange panel 2 which will house the alphabet grid
-
-
panel2 = new Panel();
-
add("Center",panel2);
-
-
// set gridLayout for panel2(int rows , int col, int hgap, int vgap
-
panel2.setLayout(new GridLayout(4,7,3,3));
-
-
button = new Button[28];
-
-
for (int i=0;i<26;i+=1)
-
{
-
// set the buttons of the alphabet up using the array
-
button[i] = new Button(alphabuttons[i]);
-
panel2.add(button[i]);
-
button[i].addActionListener(this);
-
}
-
-
button[26] = new Button("Answer"); // creates the answer button
-
button[26].setForeground(Color.green);
-
button[26].addActionListener(this);
-
-
button[27] = new Button("Reset"); // creates the reset button
-
button[27].setForeground(Color.yellow);
-
button[27].addActionListener(this);
-
-
// add the remaining buttons to panel 2
-
panel2.add(button[26]);
-
panel2.add(button[27]);
-
-
// create and arrange panel 3 which will house the radio buttons for the level
-
-
panel3 = new Panel();
-
add("South",panel3);
-
-
group = new CheckboxGroup();
-
-
// create the radio buttons
-
-
beg = new Checkbox("Beginner",group,false);
-
beg.addItemListener(this);
-
-
inte = new Checkbox("Intermediate",group,false);
-
inte.addItemListener(this);
-
-
adv = new Checkbox("Advanced",group,false);
-
adv.addItemListener(this);
-
-
// add the radio buttons to panel3
-
panel3.add(beg);
-
panel3.add(inte);
-
panel3.add(adv);
-
}
-
-
-
public void actionPerformed(ActionEvent e)
-
{
-
int j=0;
-
int count=0;
-
int k=0;
-
String currentLetter;
-
String temp="";
-
StringBuffer Sanswer = new StringBuffer(answer);
-
Sanswer.setLength(answer.length());
-
boolean hang = false;
-
boolean correct=true;
-
store2.setLength(answer.length());
-
count = Sanswer.length();
-
-
-
for(k=0;k<=25;k+=1)
-
{
-
if (e.getSource()==button[k])
-
{
-
currentLetter = (button[k].getLabel());
-
letter.setText(currentLetter);
-
-
for (j=0;j<count;j++)
-
{
-
//cycles through the letters in the word
-
if (currentLetter.equals(String.valueOf(answer.charAt(j))))
-
{
-
// replaces the letter if it is within the word
-
store2.replace(j,j+1,currentLetter);
-
temp=store2.toString();
-
lives+=1; // does not decrement the lives
-
if(temp.equals(word.getText()))
-
{
-
letter.setText("YOU WIN");
-
letter.setForeground(Color.blue);
-
}
-
}
-
-
}
-
lives-=1; // decrements the lives
-
guess.setText(Integer.toString(lives));
-
word.setText(store2.toString());
-
-
if (lives<1)
-
{
-
letter.setText("YOU LOSE");
-
letter.setForeground(Color.red);
-
}
-
-
}
-
}
-
-
if(e.getSource()==button[26]) // answer button
-
{
-
-
word.setText(answer);
-
word.setForeground(Color.darkGray);
-
letter.setText("Unlucky");
-
}
-
-
if(e.getSource()==button[27]);
-
{
-
/* word.setText(null);
-
guess.setText(null);
-
letter.setText("delete");
-
for(int x=0;x<9;x++)
-
{
-
store2.replace(x,x+1,"-");
-
}
-
count = Sanswer.length();
-
count=answer.length(); */
-
}
-
} // ends actionPerformed
-
-
// invoked with the radio buttons are selected or deselected
-
-
public void itemStateChanged(ItemEvent e)
-
{
-
// checks if the button is pressed
-
select = (int)(java.lang.Math.random()*4); // random number generator for the arrays
-
StringBuffer miss = new StringBuffer(answer);
-
if (e.getSource()==beg)
-
{
-
if(beg.getState()==true)
-
{
-
lives = 9;
-
answer = (begin[select]);
-
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
else if (e.getSource()==inte)
-
{
-
if(inte.getState()==true)
-
{
-
lives = 8;
-
answer = (inter[select]);
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
else if(e.getSource()==adv)
-
{
-
if(adv.getState()==true)
-
{
-
lives = 7;
-
answer = (advan[select]);
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
} // ends itemStateChanged for the radio buttons
-
-
}//ends the class
1.) Use code tags when posting code. It's one of the site rules.
2.) I wanted to help because I though you wanted to write the program yourself.
sorry wat are code tags?? im still new here
i do want to do it myself and i know if i do im definately not going to be finished by next monday:(. It is a really important piece and if i start now ill neva finish, i just dont have the experience yet
sorry wat are code tags?? im still new here
i do want to do it myself and i know if i do im definately not going to be finished by next monday:(. It is a really important piece and if i start now ill neva finish, i just dont have the experience yet
If you start today and devote a few hours to it a day from today you will be done before this weekend. The important thing is to approach it the correct way.
ok will do, could u pls tell me what was wrong with the other program tho...
ok how exactly should i start it? should i write down exactly what to do etc (im not sure exactly what ill need thats the problem), i no ill use an array to store the words etc
ok will do, could u pls tell me what was wrong with the other program tho...
ok how exactly should i start it? should i write down exactly what to do etc (im not sure exactly what ill need thats the problem), i no ill use an array to store the words etc
Why not store the words in a text file or even in a database table?
Then you can change the words or add new words easily. Adding new words gives you the option of changing the category of the words being guessed.
kewl i just did that, i stored 200 words in a text file, its called dictionary.txt
kewl i just did that, i stored 200 words in a text file, its called dictionary.txt
Great. Now you need to know how to read words from that text file.
This article will show you how. Make sure you also read the comments posted in that thread. After you're done reading that you should try the code and read words from your textfile. Also try to get a random word to display to the screen.
Hint: For the random word display part you may find the java.util.Random class helpful.
ok, i just managed to read and print all the words, im not familiar with the java.util.Random class so do not know how to display a random word instead of all of them
ok, i just managed to read and print all the words, im not familiar with the java.util.Random class so do not know how to display a random word instead of all of them
You should have opened the API docs page for it.
From here there are two ways of going about it.
Read all the words into an ArrayList<String> one word at a time. Then generate a number (using the Random class) between 0 and the number of words in the ArrayList (minus one). If the generated number is n, then displaying the nth string in the list is equivalent to displaying a random string.
P.S Always refuse to write any code if you do not have the API specs with you.
P.P.S We are still just playing around with some stuff here. The next step involves the algorithm which you are going to write.
Okay. Will attempt it first thing tomorrow morning. How exactly should i set out the algorithm. I dont normally use algorithms as i dont really understand how to make them:(.. But once i get the random word to work ill let u know. I hope i can get that by tomorrow morning.
Okay. Will attempt it first thing tomorrow morning. How exactly should i set out the algorithm. I dont normally use algorithms as i dont really understand how to make them:(.. But once i get the random word to work ill let u know. I hope i can get that by tomorrow morning.
An algorithm is basically just a step by step list of whats going to happen in your program.
its also helpful to make a list of all the things your going to need.
You need to read a file
get user input
display user input as output
etc
etc
I have found recently that when i have a daunting project on my hands if you break it down and say "ok, today I am going to do this and if i have time start this, or polish this" the project seems to flow more smoothly. Sitting down and just starting to hack out code leads to problems. Even though coding it right away might seem like the quickest way to finish the project, its not.
This is a great site to come to for help, you just need to show your doing the work yourself and all the developers, admins, mods and experts are more then willing to guide us:)
i have decided to go with the applet above, most of it was done by me in any case, i have to continue with it because its so close to done, and i rele do not have time to start from nothing, it has to be done by monday with the documentation which will take me hours:(
so all help with my applet would be much appreciated, i would like to change the applet into a java application, i only use NETBEANS and DRJava
i have decided to go with the applet above, most of it was done by me in any case, i have to continue with it because its so close to done, and i rele do not have time to start from nothing, it has to be done by monday with the documentation which will take me hours:(
so all help with my applet would be much appreciated, i would like to change the applet into a java application, i only use NETBEANS and DRJava
I thought you said it was written by a good friend of yours.
Anyway good luck with it.
Edit: Please do not double post. It's against the site rules. Just keep one problem in one thread.
So i take it that u dont want to help me? My friend did not code it, he helped me do the coding. But now that he left i have no help which is why i came here. Anyway thanks
So i take it that u dont want to help me? My friend did not code it, he helped me do the coding. But now that he left i have no help which is why i came here. Anyway thanks
Of course I want to help, but only if you want to do it the correct way.
Sir pls can u just help me from where i am, there is still a lot to do, i rele do not have time and have exams soon:(, i just rele want to get this off my chest, i managed to get it to finally run the applet (needed a main method), but now pls could u just help me in getting a high scores table which stores user name and number of tries, and also the reset button does not work and i have tried everything to fix it...i also have no idea how to get the hangman to appear in the gui
Sir pls can u just help me from where i am, there is still a lot to do, i rele do not have time and have exams soon:(, i just rele want to get this off my chest, i managed to get it to finally run the applet (needed a main method), but now pls could u just help me in getting a high scores table which stores user name and number of tries, and also the reset button does not work and i have tried everything to fix it...i also have no idea how to get the hangman to appear in the gui
That's because you never designed for any of those things before you started.
So what's your current code now? Use code tags if you're going to post it. (It's the # icon on the reply controls menu when you're posting the code)
My java code is:
That doesnt work:(
and the applet code now is: - package hangman;
-
-
import java.awt.*;
-
import javax.swing.*;
-
import java.util.*;
-
import java.lang.*;
-
import java.applet.*;
-
import java.awt.event.*;
-
-
-
public class Main extends Applet implements ActionListener,ItemListener
-
{
-
-
public static void main(String[] args) {
-
JFrame f = new JFrame("applet");
-
f.setSize(800, 600);
-
Main m = new Main();
-
m.Main();
-
f.add(m);
-
f.setVisible(true);
-
}
-
-
Button button[];
-
TextField word,letter;
-
TextField guess;
-
Label label1,label2,label3;
-
String alphabuttons[];
-
Panel panel1,panel2,panel3,pana,panb,panc;
-
Font font;
-
CheckboxGroup group;
-
Checkbox beg,inte,adv;
-
String begin[];
-
String inter[];
-
String advan[];
-
int lives,select;
-
String answer = " ";
-
String missy;
-
String buffy = "--------";
-
StringBuffer store2= new StringBuffer(buffy);
-
int counta = lives;
-
public void Main()
-
{
-
this.setLayout(new BorderLayout());
-
// sets up the array to produce the alphabet buttons on the grid
-
alphabuttons = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
-
-
// sets up the arrays with the words to be guessed in all three stages
-
begin = new String[]{"CAT","POWER","UNDER"};
-
inter = new String[]{"SECTION","VISITOR","INTENDED"};
-
advan = new String[]{"BEAUTIFUL","CHEERFUL","ENTHUSIASM"};
-
-
// create and arrange panel 1 which will house the text fields and the labels
-
-
panel1 = new Panel(); // panel 1 will hold the two labels and text fields at the top of the applet
-
add("North",panel1);
-
-
panel1.setLayout(new BorderLayout());
-
label1 = new Label("GUESS THE WORD"); // create the label
-
font = new Font("TimesRoman",Font.ITALIC,16);
-
label1.setFont(font); // set the font to the label
-
-
pana = new Panel();
-
panel1.add("North",pana);
-
pana.add(label1); // add the label to the panel
-
label1.setAlignment(label1.CENTER); // set the label to the centre
-
-
panb = new Panel();
-
panel1.add("Center",panb);
-
word = new TextField(24); // creates the text field for the word set to 24 chars
-
word.addActionListener(this);
-
word.setEditable(true); // allows text to be edited
-
panb.add(word,"CENTER"); // adds the text field to the panel
-
label3 = new Label("Win/Lose");
-
label3.setFont(font);
-
panb.add(label3);
-
label1.setAlignment(label1.RIGHT);
-
letter = new TextField(10);
-
letter.addActionListener(this);
-
panb.add(letter,"RIGHT");
-
-
panc = new Panel();
-
panel1.add("South",panc);
-
-
label2 = new Label("How Many Goes Left"); // create the label and intiliase
-
label2.setFont(font); // sets the font previously defined for label 1
-
panc.add(label2);
-
label2.setAlignment(label2.LEFT); // Sets the label left
-
-
guess = new TextField(3); // initialises the guess text field to 3 chars
-
guess.addActionListener(this);
-
panc.add(guess);
-
-
// create and arrange panel 2 which will house the alphabet grid
-
-
panel2 = new Panel();
-
add("Center",panel2);
-
-
// set gridLayout for panel2(int rows , int col, int hgap, int vgap
-
panel2.setLayout(new GridLayout(4,7,3,3));
-
-
button = new Button[28];
-
-
for (int i=0;i<26;i+=1)
-
{
-
// set the buttons of the alphabet up using the array
-
button[i] = new Button(alphabuttons[i]);
-
panel2.add(button[i]);
-
button[i].addActionListener(this);
-
}
-
-
button[26] = new Button("Answer"); // creates the answer button
-
button[26].setForeground(Color.green);
-
button[26].addActionListener(this);
-
-
button[27] = new Button("Reset"); // creates the reset button
-
button[27].setForeground(Color.yellow);
-
button[27].addActionListener(this);
-
-
// add the remaining buttons to panel 2
-
panel2.add(button[26]);
-
panel2.add(button[27]);
-
-
// create and arrange panel 3 which will house the radio buttons for the level
-
-
panel3 = new Panel();
-
add("South",panel3);
-
-
group = new CheckboxGroup();
-
-
// create the radio buttons
-
-
beg = new Checkbox("Beginner",group,false);
-
beg.addItemListener(this);
-
-
inte = new Checkbox("Intermediate",group,false);
-
inte.addItemListener(this);
-
-
adv = new Checkbox("Advanced",group,false);
-
adv.addItemListener(this);
-
-
// add the radio buttons to panel3
-
panel3.add(beg);
-
panel3.add(inte);
-
panel3.add(adv);
-
}
-
-
-
public void actionPerformed(ActionEvent e)
-
{
-
int j=0;
-
int count=0;
-
int k=0;
-
String currentLetter;
-
String temp="";
-
StringBuffer Sanswer = new StringBuffer(answer);
-
Sanswer.setLength(answer.length());
-
boolean hang = false;
-
boolean correct=true;
-
store2.setLength(answer.length());
-
count = Sanswer.length();
-
-
-
for(k=0;k<=25;k+=1)
-
{
-
if (e.getSource()==button[k])
-
{
-
currentLetter = (button[k].getLabel());
-
letter.setText(currentLetter);
-
-
for (j=0;j<count;j++)
-
{
-
//cycles through the letters in the word
-
if (currentLetter.equals(String.valueOf(answer.charAt(j))))
-
{
-
// replaces the letter if it is within the word
-
store2.replace(j,j+1,currentLetter);
-
temp=store2.toString();
-
lives+=1; // does not decrement the lives
-
if(temp.equals(word.getText()))
-
{
-
letter.setText("YOU WIN");
-
letter.setForeground(Color.blue);
-
}
-
}
-
-
}
-
lives-=1; // decrements the lives
-
guess.setText(Integer.toString(lives));
-
word.setText(store2.toString());
-
-
if (lives<1)
-
{
-
letter.setText("YOU LOSE");
-
letter.setForeground(Color.red);
-
}
-
-
}
-
}
-
-
if(e.getSource()==button[26]) // answer button
-
{
-
-
word.setText(answer);
-
word.setForeground(Color.darkGray);
-
letter.setText("Unlucky");
-
}
-
-
if(e.getSource()==button[27]);
-
{
-
/* word.setText(null);
-
guess.setText(null);
-
letter.setText("delete");
-
for(int x=0;x<9;x++)
-
{
-
store2.replace(x,x+1,"-");
-
}
-
count = Sanswer.length();
-
count=answer.length(); */
-
}
-
} // ends actionPerformed
-
-
// invoked with the radio buttons are selected or deselected
-
-
public void itemStateChanged(ItemEvent e)
-
{
-
// checks if the button is pressed
-
select = (int)(java.lang.Math.random()*4); // random number generator for the arrays
-
StringBuffer miss = new StringBuffer(answer);
-
if (e.getSource()==beg)
-
{
-
if(beg.getState()==true)
-
{
-
lives = 9;
-
answer = (begin[select]);
-
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
else if (e.getSource()==inte)
-
{
-
if(inte.getState()==true)
-
{
-
lives = 8;
-
answer = (inter[select]);
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
else if(e.getSource()==adv)
-
{
-
if(adv.getState()==true)
-
{
-
lives = 7;
-
answer = (advan[select]);
-
for (int y=0;y<answer.length();y++)
-
{
-
miss.replace(y,y+1,"-");
-
}
-
word.setText(miss.toString());
-
missy = miss.toString();
-
word.setForeground(Color.black);
-
guess.setText(Integer.toString(lives));
-
}
-
}
-
} // ends itemStateChanged for the radio buttons
-
-
}//ends the class
Those are two different programs. So which one do you want to work with?
P.S It will have to be one that you understand because you will be making the changes to make it work.
any, whichever 1 i could do quicker i suppose
any, whichever 1 i could do quicker i suppose
Well it was supposed to be your choice ...
Since you're keen on using the second program (which your friend helped you make) ....
First it needs quite a lot of cleaning up:
2.) Import only the packages you need to use. i.e Remove the imports for java.lang (already imported for you), leave only the imports for
java.awt and java.awt.event. You haven't used the other packages in your program (yet)
2.) Constructors do not return a value (refer to your textbook) so you need to change that.
3.) Your Frame does not have a size. It probably shows as a very small icon when you run it. set it's size to something reasonable e.g (500, 500)
4.) You are creating a Java application so remove the extends applet and put extends Frame instead.
5.) Your Frame does not seem to have closing functionality.
You forgot - addWindowListener(new WindowAdapter() {
-
public void windowClosing(WindowEvent w) {
-
System.exit(0);
-
}
-
-
});
in the constructor
6.) I don't see any setVisible(true) at the end of that constructor as well so that Frame will not show.
See if you can clean those things up for now.
ok i think i fixed it up
the beginning code is now - package hangman;
-
package hangman;
-
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.JFrame;
-
-
-
public class Main extends Frame implements ActionListener,ItemListener
-
{
-
-
public static void main(String[] args) {
-
JFrame f = new JFrame();
-
f.setSize(500, 500);
-
Main m = new Main();
-
m.Main();
-
f.add(m);
-
f.setVisible(true);
-
}
-
Is that a bit better?
ok i think i fixed it up
the beginning code is now
package hangman;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
public class Main extends Frame implements ActionListener,ItemListener
{
public static void main(String[] args) {
JFrame f = new JFrame();
f.setSize(500, 500);
Main m = new Main();
m.Main();
f.add(m);
f.setVisible(true);
}
Is that a bit better?
Not really.
When you extend Frame, Main becomes a Frame itself so creating both a Frame and a Main object is actually creating two Frames. you should create a Main object only.
huh??
ok im confused:(, i cant even get the first part right, how the heck am i gonna get the program running by monday... im really bad at java so please forgive me. Do you think the other program i did would be easier because this 1 does seem very sophisticated and im not sure im at the level to do such sophisticated programs at the moment.
huh??
ok im confused:(, i cant even get the first part right, how the heck am i gonna get the program running by monday... im really bad at java so please forgive me. Do you think the other program i did would be easier because this 1 does seem very sophisticated and im not sure im at the level to do such sophisticated programs at the moment.
Well, we were going very well yesterday until you decided to switch back to this version of the program and lost a full day. It's obvious you haven't gone through some basics tutorials yet and that's what I was going to point you to bit by bit until you get it working.
Of course you can revert to your version of the program and still be able to do it by Monday.
Willingness to learn and read are the important things here.
If you want to revert to your old version, get the part to read all the words from a file into an ArrayList working first and then post a version of your intended hangman algorithm.
P.S A lesson worth learning from all this is "Never postpone for tomorrow what you can do today"
okay i have a plan, the program which my teacher helped me with (the first 1). just gets 1 error when compiled, its in the line: "String s = ConsoleInput.readString();"
Pls could u tell me how i could fix that error, once i have fixed that i promise that i will be willing to learn how to improve the program so that it does exactly what i would like it to. its already 9:37pm here and im willing to stay up till 11 tonight
okay i have a plan, the program which my teacher helped me with (the first 1). just gets 1 error when compiled, its in the line: "String s = ConsoleInput.readString();"
Pls could u tell me how i could fix that error, once i have fixed that i promise that i will be willing to learn how to improve the program so that it does exactly what i would like it to. its already 9:37pm here and im willing to stay up till 11 tonight
what is the error?
Could you use something like - String name_of_string = stdin.readline();
the error i get is " Hangman.java:115: cannot find symbol
symbol : variable ConsoleInput
location: class Hangman
String s = ConsoleInput.readString(); "
I tried the code u gave me and i got "Hangman.java:115: cannot find symbol
symbol : variable stdin
location: class Hangman
String s = stdin.readline(); "
the error i get is " Hangman.java:115: cannot find symbol
symbol : variable ConsoleInput
location: class Hangman
String s = ConsoleInput.readString(); "
I tried the code u gave me and i got "Hangman.java:115: cannot find symbol
symbol : variable stdin
location: class Hangman
String s = stdin.readline(); "
If you are using 1.5 or higher you can use the Scanner class to get input from the user. - Scanner input = new Scanner(System.in);
-
String s = input.nextLine();
You should open the API docs for it and see how to use it.
oka i have worked on it a bit, could i pls send some1 my project so that they can edit it and pls help me, when i click new game i would like it o reset everything, when i click ok i would like the text box called output to be filled:( pls help!! ill do anything, im so desperate im willing to pay a programmer to come help me
oka i have worked on it a bit, could i pls send some1 my project so that they can edit it and pls help me, when i click new game i would like it o reset everything, when i click ok i would like the text box called output to be filled:( pls help!! ill do anything, im so desperate im willing to pay a programmer to come help me
If you are looking for someone to pay try www.rentacoder.com.
If you want free help here, just post your code (wrapped in code tags) and explain where you are getting problems.
If you are looking for someone to pay try www.rentacoder.com.
If you want free help here, just post your code (wrapped in code tags) and explain where you are getting problems.
the thing is that im not have problems, i just cant get the proigram to do wat i would like it to do, im not advanced enough. Since its in netbeans i have 2 programs in the project, the only way some1 could help me is if i send u the project file and u open in in netbeans then edit that for me. i would very much appreciate it
the thing is that im not have problems, i just cant get the proigram to do wat i would like it to do, im not advanced enough. Since its in netbeans i have 2 programs in the project, the only way some1 could help me is if i send u the project file and u open in in netbeans then edit that for me. i would very much appreciate it
You realize of course that you are going no where with this.
You heven't been paying attention to the responses I was giving at all.
You realize of course that you are going no where with this.
You heven't been paying attention to the responses I was giving at all.
ok well sir i just got a code for many different classes. I have saved them as txt files and was wondering if u could pls help me add them all into a java application. It is a hangman appet but the last class called HangmanAppletImpl has a thing at the bottom showing how to change it into application, pls help me..i was paying attention its just that u do not understand how urgent this is, i did not have time to start the program from scratch, i just do not have the skills for that, sorry
ok well sir i just got a code for many different classes. I have saved them as txt files and was wondering if u could pls help me add them all into a java application. It is a hangman appet but the last class called HangmanAppletImpl has a thing at the bottom showing how to change it into application, pls help me..i was paying attention its just that u do not understand how urgent this is, i did not have time to start the program from scratch, i just do not have the skills for that, sorry
The reason for the assignment was to give you the skill to do this yourself. If you had started early enough and followed my advice, you'd have the program working by now and also you'd be understanding every line of code in it.
Instead you resorted to code hunting which has left you none the wiser.
Now you want us to help you piece together the code you've hunted?
The probability that a posted problem is successfully solved is inversely proportional
to the number of replies in the thread.
kind regards,
Jos
The probability that a posted problem is successfully solved is inversely proportional
to the number of replies in the thread.
kind regards,
Jos
Wise words indeed.
Wise words indeed.
I know and you just lowered chances that this thread terminates successfully ;-)
kind regards,
Jos (<--- oops! I did so too ;-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: GM |
last post by:
Hello. I am starting my 7th week of an intro to programming class and have
a problem I have been working on. My instructor said we could look for
source code on the internet and use it as long as...
|
by: Brent W. Hughes |
last post by:
I recently downloaded HelpMaker for free, but there was no documentation
with it. Does someone know where I can find such documentation? Or,
alternatively, where I can find another good free Help...
|
by: atreide_son |
last post by:
hello all...
yes i'm a newbie and i need help.
i have an assignment due for class, but I don't know i'm stuck and
can't get out from under myself.
here's the focus of the program:
Write...
|
by: k1ckthem1dget |
last post by:
I dont even know how to do this program can someone help me.
I am to create a program that when
(1) Given the following:
· A list of 11 integers; 1,2,3,3,3,2,2,1,3,4,5
...
|
by: princessfrost |
last post by:
Hi! I was wondering if someone could please help me with a hangman program that I have to do. I have some ideas, but really don't know what to do or where to start. My program needs to be:...
|
by: kaka_hunter |
last post by:
#include <iostream>
#include <fstream>
using namespace std;
const int max_tries=7;
int earnings=0;
int wordnum;
void getword ()
{
ifstream fin;
|
by: ilogboy |
last post by:
Below is a copy of my Hangman project... I am missing a couple more functions and I don't know how to enhance it... Here are the things I want it to do: 1) I want it to determine the scores for...
|
by: av3rage |
last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get...
|
by: yottabyte |
last post by:
Hey, I just started programming this September and I have an assignment in which I am supposed to create a hangman game. This is my first post on this forum so forgive me for any "noob" mistakes Now...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |