adding text field to the applet

Hi,

I am new to Java applets. I am trying to create a Hangman program. For this, I need textfields for the number of letters the word has. I wrote the following code, but it did not create any textfields. Could you kindly tell me where I am going wrong ?

TextField letter;

for (int i = 0; i < 5; i++){ //suppose the word is 5 letters long

letter = new TextField(" ",1);

add(letter);

}

I have written this code in the init() method.

Thank you for your help,

priyanka

[530 byte] By [priyankabhara] at [2007-11-27 4:48:38]
# 1

> TextField letter;

> I have written this code in the init() method.

First of all this must be declared as a class field

for example

class HangMe extends Applet

{

//Notice the array and its declared here so that its accessible for checking and other calculations done outside the init()

TextField letter[];

..........

..........

public void init()

{

....

....

letter=new TextField[NO_OF_LETTERS];//This is the no of letters

for(int i=0 ; i < NO_OF_LETTERS ; i++ )

{

letter[i]=new TextField(2); //Wide enough for 2 characters

add(letter[i]);

}

}

}

Message was edited by:

ArcherKing

made a correction

ArcherKinga at 2007-7-12 10:01:35 > top of Java-index,Java Essentials,New To Java...