拜托,我是Java的新手,我目前正在学习有关Java的教程,但遇到与setText()方法不仅仅有效有关的错误,我无法告知其不起作用的原因。
这是我尝试的代码:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.awt.*;
public class Demo extends Application {
Button button = new Button();
public static void main(String args[])
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("This is a title");
button.setText("This is a button");
StackPane stackPane = new StackPane();
stackPane.getChildren().add(button);
Scene scene = new Scene(stackPane,400,400);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误越来越:
Error:(23, 15) java: cannot find symbol
symbol: method setText(java.lang.String)
location: variable button of type java.awt.Button
Run Code Online (Sandbox Code Playgroud)