我的追加方法赢了';我不能用Java工作

我的追加方法赢了';我不能用Java工作,java,Java,我有一个程序,我试图制作一个计算器,但是append方法不起作用。编译器将给出以下错误:找不到符号-方法append(java.lang.String) 这是我的代码: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Calculator extends Frame implements ActionListener,WindowListener { Button one,two

我有一个程序,我试图制作一个计算器,但是append方法不起作用。编译器将给出以下错误:找不到符号-方法append(java.lang.String)

这是我的代码:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Calculator extends Frame implements ActionListener,WindowListener
{
    Button one,two,three,four,five,six,seven,eight,nine,zero,plus,minus,divide,times,equals,one2,two2,three2,four2,five2,six2,seven2,eight2,nine2,zero2;

TextField numOne,operation,numTwo;

Label fill;
public static void main(String[] args)
{
    Calculator calc = new Calculator("Calculator");
    calc.setVisible(true);
    calc.setSize(380,153);
    calc.setLocationRelativeTo(null);
    calc.setBackground(Color.white);
}

public Calculator(String title)
{
    super(title);
    setLayout(new FlowLayout(FlowLayout.LEFT));
    addWindowListener(this);

    one = new Button("1");
    two = new Button("2");
    three = new Button("3");
    four = new Button("4");
    five = new Button("5");
    six = new Button("6");
    seven = new Button("7");
    eight = new Button("8");
    nine = new Button("9");
    zero = new Button("0");

    one2 = new Button("1");
    two2 = new Button("2");
    three2 = new Button("3");
    four2 = new Button("4");
    five2 = new Button("5");
    six2 = new Button("6");
    seven2 = new Button("7");
    eight2 = new Button("8");
    nine2 = new Button("9");
    zero2 = new Button("0");

    minus = new Button("-");
    plus = new Button("+");
    divide = new Button("/");
    times = new Button("X");

    equals = new Button("=");

    numOne = new TextField(10);
    operation = new TextField(10);
    numTwo = new TextField(10);

    fill = new Label("                                ");

    add(numOne);
    add(one);
    add(two);
    add(three);
    add(four);
    add(five);
    add(six);
    add(seven);
    add(eight);
    add(nine);
    add(zero);

    add(operation);
    add(minus);
    add(plus);
    add(divide);
    add(times);

    add(fill);
    add(numTwo);
    add(one2);
    add(two2);
    add(three2);
    add(four2);
    add(five2);
    add(six2);
    add(seven2);
    add(eight2);
    add(nine2);
    add(zero2);

    add(equals);

    one.addActionListener(this);
    two.addActionListener(this);
    three.addActionListener(this);

    minus.addActionListener(this);

    four.addActionListener(this);
    five.addActionListener(this);
    six.addActionListener(this);

    plus.addActionListener(this);

    seven.addActionListener(this);
    eight.addActionListener(this);
    nine.addActionListener(this);

    one2.addActionListener(this);
    two2.addActionListener(this);
    three2.addActionListener(this);
    four2.addActionListener(this);
    five2.addActionListener(this);
    six2.addActionListener(this);
    seven2.addActionListener(this);
    eight2.addActionListener(this);
    nine2.addActionListener(this);
    zero2.addActionListener(this);

    times.addActionListener(this);

    equals.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
    //This is where my append method won't work
    if(e.getSource() == one)
    {
        numOne.append("1");
    }
    if(e.getSource() == two)
    {
        numOne.append("2");
    }
    if(e.getSource() == three)
    {
        numOne.append("3");
    }
    if(e.getSource() == four)
    {
        numOne.append("4");
    }
    if(e.getSource() == five)
    {
        numOne.append("5");
    }
    if(e.getSource() == six)
    {
        numOne.append("6");
    }
    if(e.getSource() == seven)
    {
        numOne.append("7");
    }
    if(e.getSource() == eight)
    {
        numOne.append("8");
    }
    if(e.getSource() == nine)
    {
        numOne.append("9");
    }
    if(e.getSource() == zero)
    {
        numOne.append("0");
    }
    if(e.getSource() == minus)
    {
        operation.setText("-");
    }
    if(e.getSource() == times)
    {
        operation.setText("X");
    }
    if(e.getSource() == plus)
    {
        operation.setText("+");
    }
    if(e.getSource() == divide)
    {
        operation.setText("/");
    }
    if(e.getSource() == one2)
    {
        numTwo.append("1");
    }
    if(e.getSource() == two2)
    {
        numTwo.append("2");
    }
    if(e.getSource() == three2)
    {
        numTwo.append("3");
    }
    if(e.getSource() == four2)
    {
        numTwo.append("4");
    }
    if(e.getSource() == five2)
    {
        numTwo.append("5");
    }
    if(e.getSource() == six2)
    {
        numTwo.append("6");
    }
    if(e.getSource() == seven2)
    {
        numTwo.append("7");
    }
    if(e.getSource() == eight2)
    {
        numTwo.append("8");
    }
    if(e.getSource() == nine2)
    {
        numTwo.append("9");
    }
    if(e.getSource() == zero2)
    {
        numTwo.append("0");
    }
}

public void windowClosing(WindowEvent e)
{
    dispose();
    System.exit(0);
}

public void windowOpened(WindowEvent e) {}

public void windowActivated(WindowEvent e) {}

public void windowIconified(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

public void windowDeactivated(WindowEvent e) {}

public void windowClosed(WindowEvent e) {}

}numOne是一个文本字段,没有这样的方法。请参阅。

您正在对
TextField
对象调用
append()
方法,该对象没有该方法。请改为尝试
setText(“字符串”)

您正在调用的方法
append()
TextArea
控件的方法。对于
TextField
控件,您需要使用
setText()
方法

来源


您只需输入以下字符串之间的连接:

numOne.setText(numOne.getText() + "1" );

非常感谢。这真的帮助了我。