简体   繁体   English

我正在尝试在我的方法中使用小程序

[英]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.

相关问题 我正在尝试在Applet中放置音频URL - I am trying to put an audio url in Applet 我正在尝试使用java applet开发游戏,球的运动会停止整个游戏? - I am trying to develop a game using java applet, the motion of a ball halts whole of my game? 我正在尝试使用线程在小程序中移动球,但它没有移动 - I am trying to move a ball in applet using thread but its not moving 当我尝试调用在主方法中创建的方法时,出现错误 - While I am trying to call my method, which is created in the main method, I am getting errors 我如何在我的applet中使用JXMapViewer? - how can i use JXMapViewer in my applet? 在IE9和IE9 Platform Preview中,我不再能够从Java Applet调用Javascript方法 - In IE9 and IE9 Platform Preview, I am no longer able to call a Javascript method from my Java Applet 我应该如何从Java Applet绘制图像? - How am I supposed to draw an image from my Java Applet? 检测Applet上下文(我在applet中吗?) - Detect Applet context (am I inside an applet?) 我正在尝试在我的 Cucumber 跑步者中使用标签,但不起作用。 我是 Cucumber 的新手 - I am trying use tag in my Cucumber runner but doesn't work. I am new to Cucumber 如何在我的Java小程序中的paint()方法之外使用Graphics? - How to use Graphics out side the paint() method in my Java applet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM