Button 类型未定义方法 getText()
The method getText() is undifined for the type Button
我正在尝试在 Eclipse 中创建简单的计算器 ide,当时我正面临这个问题
Button btn7 = new Button("7");
btn7.setFont(new Font("Arial", Font.BOLD, 18));
btn7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String EnterNumber = btn7.getText();
txtDisplay.setText(EnterNumber);
}
});
我在第 1 行遇到问题。 5, 显示他们 'The method getText() is undefined for the type button'
Button
不要与 JButton
混淆。您可能正在寻找 getLabel()
?
String EnterNumber = btn7.getLabel();
https://docs.oracle.com/javase/7/docs/api/java/awt/Button.html#getLabel()
JButton
继承了一个叫做getText()
的方法,也许你混淆了这两种类型的按钮? https://docs.oracle.com/javase/7/docs/api/javax/swing/JButton.html
我正在尝试在 Eclipse 中创建简单的计算器 ide,当时我正面临这个问题
Button btn7 = new Button("7");
btn7.setFont(new Font("Arial", Font.BOLD, 18));
btn7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String EnterNumber = btn7.getText();
txtDisplay.setText(EnterNumber);
}
});
我在第 1 行遇到问题。 5, 显示他们 'The method getText() is undefined for the type button'
Button
不要与 JButton
混淆。您可能正在寻找 getLabel()
?
String EnterNumber = btn7.getLabel();
https://docs.oracle.com/javase/7/docs/api/java/awt/Button.html#getLabel()
JButton
继承了一个叫做getText()
的方法,也许你混淆了这两种类型的按钮? https://docs.oracle.com/javase/7/docs/api/javax/swing/JButton.html