Disini kita akan membuat halaman untuk memasukkan data. Saya akan membuat class MemberEntriScreen. Class ini ditujukan untuk memasukkan data. Data yang dimasukkan disimpan didalam database. Program ini akan menampilkan Text Field untuk menerima Member Id, Member Name, Member Address.
Program ini menggunakan 3 buah label dan 3 buah field. Tetapi tanpa button, yang akan diimplementasi oleh ANDA : BE A HERO. Program ini hanya bisa dan pasti hanya bisa MEMASUKKAN SATU BARIS DATA SAJA : KARENA SETIAP KALI BERJALAN PERNYATAAN BERIKUT INI DIEKSEKUSI DAN PRIMARY KEY MENUNJUK NILAI YANG UNIK DIDALAM TABEL TERSEBUT.
.....
memasukkan 1 (satu) member SAJA : Karena pernyataan berikut :
this.stage.setTitle("Login To Application");
Statement stmt = conApp.createStatement();
stmt.execute("insert into member values('12345678', 'Budi Subudi',"
+ "'Jl. ABCDEFG NO 12345678')");
this.stage.show();
.....
Adapun kode program lengkapnya adalah sebagai berikut :
/**
*
* @author Joko Adianto
* Released under GPLv3
*/
package javafxorganization;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MemberEntriScreen {
Group root;
Stage stage;
Scene scene;
Connection conApp;
Label lblId;
TextField txfId;
HBox hbxId;
Label lblName;
TextField txfName;
HBox hbxName;
Label lblAddress;
TextField txfAddress;
HBox hbxAddress;
VBox vbxMember;
{
lblId = new Label("Member Id");
lblId.setMinWidth(80);
txfId = new TextField();
txfId.setMinWidth(120);
hbxId = new HBox();
hbxId.getChildren().addAll(lblId, txfId);
lblName = new Label("Name");
lblName.setMinWidth(80);
txfName = new TextField();
txfName.setMinWidth(120);
hbxName = new HBox();
hbxName.getChildren().addAll(lblName, txfName);
lblAddress = new Label("Address");
lblAddress.setMinWidth(80);
txfAddress = new TextField();
txfAddress.setMinWidth(120);
hbxAddress = new HBox();
hbxAddress.getChildren().addAll(lblAddress, txfAddress);
vbxMember = new VBox();
vbxMember.getChildren().addAll(hbxId, hbxName, hbxAddress);
}
MemberEntriScreen(Stage stage, Connection conApp) throws SQLException{
this.stage = stage;
this.conApp = conApp;
root = new Group();
root.getChildren().addAll(vbxMember);
scene = new Scene(root, 800, 600, Color.BEIGE);
this.stage.setScene(scene);
this.stage.setTitle("Login To Application");
//YOU WILL IMPLEMENT THIS IN A BUTTON DEFINITION
Statement stmt = conApp.createStatement();
stmt.execute("insert into member values('12345678', 'Budi Subudi',"
+ "'Jl. ABCDEFG NO 12345678')");
//THIS STATEMENT USES conApp passed by previous Class
this.stage.show();
}
}
No comments:
Post a Comment