import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public abstract class login extends Application
{
Stage window;
public static void main(String arvg[])
{
launch(arvg);
}
@Override
public void start(Stage primaryStage) throws Exception
{
window= primaryStage;
window.setTitle("Login");
GridPane grid=new GridPane();
grid.setPadding(new Insets(10,10,10,10));
grid.setVgap(8);
grid.setHgap(8);
//Label1
Label lbl1=new Label("User Name");
GridPane.setConstraints(lbl1,0,0);
//label2
Label lbl2=new Label("Password");
GridPane.setConstraints(lbl2,0,1);
//userinput
TextField username=new TextField();
username.setPromptText("UserName");
GridPane.setConstraints(username,1,0);
//Password
TextField password=new TextField();
password.setPromptText("Password");
GridPane.setConstraints(password,1,1);
//login
Button button=new Button("Log In");
GridPane.setConstraints(button,0,2);
grid.getChildren().addAll(lbl1,lbl2,username,password,button);
Scene s=new Scene(grid,300,200);
window.setScene(s);
window.show();
}
}
这是一个登录页面。当我尝试运行它时,它在Application构造函数中显示Exception,并在线程“main”中出现很多错误,例如异常java.lang.RuntimeException:无法构造Application实例:class login 在com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907) at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication $ 155(LauncherImpl.java:182) 在java.lang.Thread.run(Thread.java:745) 我不知道是什么问题。那么任何人都可以解释或帮助我解决它?感谢。
答案 0 :(得分:0)
为什么要让课程抽象化?如果它是抽象的,应用程序将无法从类中创建对象。从类定义中删除abstract
关键字。