简体   繁体   中英

I am trying to use applet in my method

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM