[英]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. 我将此
enterWord()
。当我尝试在其中实现小程序时,出现了我的问题。 I want my enterWord()
method to allow the user to put in their newWord
, the x coordinate and the y coordinate. 我希望我的
enterWord()
方法允许用户放入他们的newWord
,x坐标和y坐标。
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. 问题出在
public void paint(Graphics g){
部分。
Any help would be great! 任何帮助将是巨大的! Thanks!
谢谢!
You cannot define a method inside another method in Java. 您不能在Java中的另一个方法内定义一个方法。
To implement this,you could: 要实现此目的,您可以:
1. Create a TextField and store it in a global variable. 1.创建一个TextField并将其存储在全局变量中。
TextField inputLine = new TextField(15);
2. Next,simply add this input string inside your drawString
method like this: 2.接下来,只需将此输入字符串添加到您的
drawString
方法中,如下所示:
g.drawString(inputLine,x,y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.