Reputation: 1
I am creating a crossword puzzle program that displays the crossword through applet. I'm attempting to create a method that will allow the user to enter his/her desired word. I call this enterWord()
My issue comes in when I try to implement applet into it. I want my enterWord()
method to allow the user to put in their newWord
, the x coordinate and the y coordinate.
How can I change this code:
import java.awt.Graphics;
import java.applet.Applet;
public class crosswordMain extends Applet {
String word;
int wordlen;
public crosswordMain(){
}
public void enterWord(String newWord, int xCoordinate, int yCoordinate){
word = newWord;
public void paint(Graphics g){
g.drawString(newWord, xCoordinate, yCoordinate);
}
}
}
To make it work? The issue comes at the public void paint(Graphics g){
part.
Any help would be great! Thanks!
Upvotes: 0
Views: 34
Reputation: 1857
You cannot define a method inside another method in Java.
To implement this,you could:
1. Create a TextField and store it in a global variable.
TextField inputLine = new TextField(15);
2. Next,simply add this input string inside your drawString
method like this:
g.drawString(inputLine,x,y)
Upvotes: 4