Created
October 2, 2018 13:03
-
-
Save BalicantaYao/894adf1919acf9603a4077bfb7eb8fe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package application; | |
import javafx.application.Application; | |
import javafx.geometry.Pos; | |
import javafx.stage.Stage; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Label; | |
import javafx.scene.control.PasswordField; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.BorderPane; | |
import javafx.scene.layout.GridPane; | |
import javafx.scene.text.Font; | |
import javafx.scene.text.FontWeight; | |
import javafx.scene.text.Text; | |
public class Main extends Application { | |
@Override | |
// Start GUI 程式的入口點 | |
public void start(Stage primaryStage) { | |
try { | |
// 背板 - Pane | |
GridPane grid = new GridPane(); // Grid排版 | |
grid.setAlignment(Pos.CENTER); // Layout置中 | |
grid.setHgap(10); // 水平距離 | |
grid.setVgap(10); // 垂直距離 | |
// 歡迎的字 | |
Text title = new Text("歡迎"); | |
title.setFont(Font.font("Serif", FontWeight.BLACK, 20)); | |
grid.add(title, 0, 0, 2, 1); // 2,1是指這個元件要佔用2格的column和1格的row | |
// new 一個元件 | |
Label userName = new Label("帳號:"); | |
// 放到指定的位置 | |
grid.add(userName, 0, 1); // 0 代表,第 0 欄,1 代表第一行 | |
// new 一個元件 | |
TextField userTextField = new TextField(); | |
grid.add(userTextField, 1, 1); | |
Label pw = new Label("密碼:"); | |
grid.add(pw, 0, 2); | |
PasswordField pwBox = new PasswordField(); | |
grid.add(pwBox, 1, 2); | |
Button btn = new Button("登入"); | |
grid.add(btn, 1, 4); | |
// 場景 | |
Scene scene = new Scene(grid, 300, 300); | |
// 主要舞台先設定場景 | |
primaryStage.setScene(scene); | |
// 出現 | |
primaryStage.show(); | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment