/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxlogin;
import javafx.application.Application;
import javafx.stage.Stage;
/**
*
* @author Joko Adianto
*/
public class JavaFXFriends extends Application {
LoginScreen loginScreen;
@Override
public void start(Stage primaryStage) {
loginScreen = new LoginScreen(primaryStage);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Program ini akan membuat sebuah login screen :
- Class ini dipanggil oleh JavaFXFriends
- Jika button Login DIpencet akan menampilkan object FriendsEntri.java
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxlogin;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
*
* @author Joko Adianto
*/
public class LoginScreen {
Stage stage;
Label lblUser;
TextField txfUser;
Label lblPassword;
PasswordField pswPassword;
Button btnLogin;
Button btnExit;
HBox hBoxUser;
HBox hBoxPassword;
HBox hBoxButton;
VBox vBoxLogin;
Group root;
Scene scene;
ButtonHandler bh;
private void displayFriendsEntri(Stage stage){
FriendsEntri friendsEntri = new FriendsEntri(stage);
}
class ButtonHandler implements EventHandler{
@Override
public void handle(Event event) {
if (event.getSource().equals(btnLogin)){
displayFriendsEntri(stage);
}
if (event.getSource().equals(btnExit)){
stage.close();
}
}
}
LoginScreen(Stage pStage){
bh = new ButtonHandler();
//User
hBoxUser = new HBox();
lblUser = new Label("User");
lblUser.setMinWidth(80);
txfUser = new TextField();
hBoxUser.getChildren().addAll(lblUser, txfUser);
//Password
hBoxPassword = new HBox();
lblPassword = new Label("Password");
lblPassword.setMinWidth(80);
pswPassword = new PasswordField();
hBoxPassword.getChildren().addAll(lblPassword, pswPassword);
//Button
hBoxButton = new HBox();
btnLogin = new Button("Login");
btnLogin.setMinWidth(80);
btnExit = new Button("Exit");
btnExit.setMinWidth(80);
hBoxButton.setSpacing(65);
btnLogin.setOnAction(bh);
btnExit.setOnAction(bh);
hBoxButton.getChildren().addAll(btnLogin, btnExit);
vBoxLogin = new VBox();
vBoxLogin.getChildren().addAll(hBoxUser, hBoxPassword, hBoxButton);
root = new Group();
root.getChildren().addAll(vBoxLogin);
scene = new Scene(root, vBoxLogin.getMinWidth(),
vBoxLogin.getMinHeight(), Color.BEIGE);
stage = pStage;
stage.setScene(scene);
stage.setTitle("Login");
stage.show();
}
}
&& && &&
great
ReplyDelete