将MySQL嵌入JavaFx

时间:2018-04-19 03:11:17

标签: mysql javafx

我目前正在开展一个项目,我试图将MySQL中的数据项嵌入到JavaFX应用程序中。还有四个按钮可以遍历每一列,一个用于第一列,上一页,下一页和最后一列。这是我迄今为止所做的,但我不确定如何处理这个问题。任何反馈都会有所帮助。

    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.TextField;
    import javafx.scene.control.Label;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.VBox;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.application.Application;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.Priority;
    import java.sql.*;

    public class ImpoundGUI1 extends Application{
        private static final String JDBC_DRIVER = "com.mysql.jdbc.driver";
        private static final String DB_URL = "jdbimpoundc:mysql://localhost.impound?autoReconnect=true&useSSL=false";

    public void start(Stage stage){
        Button first = new Button("First");
        Button prev = new Button("Previous");
        Button next = new Button("Next");
        Button last = new Button("Last");

        TextField vin = new TextField();
        TextField plateNumber = new TextField();
        TextField make = new TextField();
        TextField model = new TextField();
        TextField year = new TextField();
        TextField color = new TextField();

        Label v = new Label("VIN");
        Label p = new Label("License Plate");
        Label m1 = new Label("Make");
        Label m2 = new Label("Model");
        Label y = new Label ("Year");
        Label c = new Label ("Color");

        GridPane pane = new GridPane();

        pane.add(v, 0, 0);
        pane.add(p, 0, 1);
        pane.add(m1, 0, 2);
        pane.add(m2, 0, 3);
        pane.add(y, 0, 4);
        pane.add(c, 0, 5);
        pane.add(vin, 9, 0);
        pane.add(plateNumber, 9, 1);
        pane.add(make, 9, 2);
        pane.add(model, 9, 3);
        pane.add(year, 9, 4);
        pane.add(color, 9, 5);

        HBox hbox = new HBox();
        hbox.setHgrow(first, Priority.ALWAYS);
        hbox.setHgrow(prev, Priority.ALWAYS);
        hbox.setHgrow(next, Priority.ALWAYS);
        hbox.setHgrow(last, Priority.ALWAYS);
        hbox.getChildren().addAll(first,prev,next,last);

        VBox vbox = new VBox();
        vbox.getChildren().addAll(pane,hbox);

        Connection connect = null;
        Statement stmt = null;
        final String userName = "root";
        final String password = "bakq";

        first.setOnAction(new EventHandler<ActionEvent>(){;


        public void handle(ActionEvent event){
            try{
                Class.forName(JDBC_DRIVER);
                connect = DriverManager.getConnection(DB_URL,userName,password);

            }
        });


        stage.setTitle("Impound Lot");
        Scene scene = new Scene(pane, 400, 205);
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args){
        launch(args);
    }
}

*我想可以调用.getText()方法。 感谢。

0 个答案:

没有答案