我在Java中建立一个计算器,通过使用Eclipse - 月神,但添加的“输入号码”的代码时,我得到两个错误信息如下:对于Java中的类型String,未定义方法setText()和getText()?
验证码:
JButton btn8 = new JButton("8");
btn8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String EnterNumber = TxtDisplay.getText() + btn8.getText();
TxtDisplay.setText(EnterNumber);
}
});
btn8.setFont(new Font("Tahoma", Font.BOLD, 18));
btn8.setBounds(79, 137, 50, 50);
frame.getContentPane().add(btn8);
错误信息:
The method getText() is undefined for the type String
The method setText(String) is undefined for the type String
请问谁能帮助我?
你的TxtDisplay是什么?检查它是否是一个String变量或UI上的一个控件。 – htpvl
我想你想'TxtDisplay'是一个JTextField –
可怕的Wombat:我可以使用JTextField的getText和setText – Maged