Wednesday, December 13, 2017

Kontrol dengan javafx

Berikut ini adalah FXMLDocument.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane"  xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxmlcontrol.FXMLDocumentController">
    <children>
        <VBox fx:id="vbx" >
        <padding><Insets top="25" right="25" bottom="25" left="25"/></padding>
            <children>
                <HBox id = "hbxName">
                    <children>
                        <Label fx:id = "lblName" minWidth="100" text="Name"/>
                        <TextField fx:id = "txfName" minWidth="200"/>
                    </children>                   
                </HBox>
                <HBox id = "hbxAddress">
                    <padding><Insets top="5" />
                        </padding>
                    <children>
                        <Label fx:id = "lblAddress" minWidth="100" text="Alamat"/>
                        <TextField fx:id = "txfAddress" minWidth="200"/>
                    </children>                   
                </HBox>
                <HBox id = "hbxButton" spacing = "100">
                    <padding><Insets top="10" />
                        </padding>
                    <children>                       
                        <Button fx:id= "btnSave" minWidth="100"
                            text="Save"/>
                       
                        <Button fx:id= "btnCancel" minWidth="100"                           
                            text="Cancel"/>
                    </children>                   
                </HBox>               
            </children>
        </VBox>
    </children>
</AnchorPane>

Selanjutnya kita memiliki FXMLDocumentController.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 javafxmlcontrol;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;


public class FXMLDocumentController implements Initializable {
   
   
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
       
    }   
   
}

Yang terakhir adalah file aplikasi :

/*
 * 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 javafxmlcontrol;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


/**
 *
 * @author FASILKOM
 */
public class JavaFXMLControl extends Application {
   
    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Control Exercise");
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
   
}




No comments:

Post a Comment