如何在applet文本字段中等待用户输入

时间:2016-05-30 00:27:05

标签: java applet awt textfield

如何让我的程序等到用户在程序检查它是否相等之前将某些内容输入到文本字段中。

当我在网上搜索时,我只看到Jtextfields的结果而不是文本字段,idk知道相同的东西是否适用于两者。他们都非常复杂,超出了我的水平。是否有更简单的方法或有人愿意解释更复杂的方式。以下是必要的代码。

文本字段名为Answer,我为输入分配ananswer,然后将其与realanswer进行比较

public void getquestion (int level, Graphics g)
{
    Answer.setVisible (true);
    double realanswer;
    super.paint (g);
    int shape = 1;
    if (shape == 1)
    {
        double radius = 0;
        double height = 0;
        double diameter = 0;
        double volume = 0;
        double surfacearea = 0;
        double radius2 = 0;
        double height2 = 0;
        realanswer = 0;
        switch (level)
        {
            case 1:
                g.drawImage (cylinder, 100, 150, this);
                radius = 1 + (int) (Math.random () * 10);
                height = 1 + (int) (Math.random () * 10);
                g.drawString ("The Height of the Cylinder is " + height, 400, 100);
                g.drawString ("The Radius of the Cylinder is " + radius, 400, 120);
                g.drawString ("What is the volume of the Cylinder?", 100, 140);
                realanswer = Math.round(Math.PI * radius * radius * height);
                break;

            default:
                height2 = 1 + (Math.random () * 100);
                radius2 = 1 + (Math.random () * 100);
                height = height2 + (Math.random () * 100);
                radius = radius2 + (Math.random () * 100);
                break;
        }

        if (realanswer == ananswer)
        {
            g.drawImage (mathmeme1, 100, 150, this);
        }
        else
        {
            g.drawImage (fail1, 100, 150, this);
        }
    }
}
    public void actionPerformed (ActionEvent evt)
    {
        ananswer = Integer.parseInt (Answer.getText ());
    }

0 个答案:

没有答案