1. Program untuk membuat scene dan eksekusi
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javax.swing.*;
import java.lang.Integer;
import java.lang.String;
public class MenuInput extends Application {
String kodeKasir;
String kodeBarang;
String namaBarang;
int hargaBarang;
int jumlahBarang;
int totalHarga;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Input Barang");
Text tkasir = new Text("Kasir: ");
Text tkode = new Text("Kode Barang: ");
Text tnama = new Text("Nama Barang: ");
Text tharga = new Text("Harga Satuan: ");
Text tjumlah = new Text("Jumlah Barang: ");
TextField kasir = new TextField();
TextField kode = new TextField();
TextField nama = new TextField();
TextField harga = new TextField();
TextField jumlah = new TextField();
Button confirm = new Button("Konfirmasi");
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
grid.setPadding(new Insets(10,10,10,10));
grid.add(tkasir,0,0);
grid.add(kasir,1,0);
grid.add(tkode,0,1);
grid.add(kode,1,1);
grid.add(tnama,0,2);
grid.add(nama,1,2);
grid.add(tharga,0,3);
grid.add(harga,1,3);
grid.add(tjumlah,0,4);
grid.add(jumlah,1,4);
grid.add(confirm,1,5);
grid.setAlignment(Pos.CENTER);
Scene menu = new Scene(grid);
primaryStage.setTitle("Simple POS");
primaryStage.setScene(menu);
primaryStage.show();
/*
* Scene untuk Konfirmasi Pembelian
*/
EventHandler<ActionEvent> eventconfirm = new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e){
kodeKasir = kasir.getText();
kodeBarang = kode.getText();
namaBarang = nama.getText();
hargaBarang = Integer.parseInt(harga.getText());
jumlahBarang = Integer.parseInt(jumlah.getText());
totalHarga = hargaBarang * jumlahBarang;
confirm();
primaryStage.close();
}
};
confirm.setOnAction(eventconfirm);
}
public static void main(String[] args){
launch(args);
}
public void confirm(){
Stage stage = new Stage();
stage.setTitle("Konfirmasi Pembelian");
Button bconfirm = new Button("Ya");
Button bdeny = new Button("Tidak");
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
grid.setPadding(new Insets(10,10,10,10));
grid.add(new Text("Kode Barang : " + kodeBarang),0,0);
grid.add(new Text("Nama Barang : " + namaBarang),0,1);
grid.add(new Text("Harga Satuan : " + hargaBarang),0,2);
grid.add(new Text("Jumlah Barang : " + jumlahBarang),0,3);
grid.add(new Text("Total Harga : " + totalHarga),0,4);
grid.add(new Text("Apakah Anda yakin ingin membeli barang?"),1,5);
grid.add(bconfirm,2,5);
grid.add(bdeny,3,5);
grid.setAlignment(Pos.CENTER);
Scene scene = new Scene(grid);
EventHandler<ActionEvent> yes = new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e){
confirmBuy();
stage.close();
}
};
EventHandler<ActionEvent> no = new EventHandler<ActionEvent>()
{
public void handle(ActionEvent e){
denyBuy();
stage.close();
}
};
bconfirm.setOnAction(yes);
bdeny.setOnAction(no);
stage.setScene(scene);
stage.show();
}
public void confirmBuy(){
Stage stage = new Stage();
stage.setTitle("Nota Pembelian");
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
grid.setPadding(new Insets(10,10,10,10));
grid.add(new Text("Pembelian Sukses"),0,0);
grid.add(new Text("Kode Barang : " + kodeBarang),0,1);
grid.add(new Text("Nama Barang : " + namaBarang),0,2);
grid.add(new Text("Harga Satuan : " + hargaBarang),0,3);
grid.add(new Text("Jumlah Barang : " + jumlahBarang),0,4);
grid.add(new Text("Total Harga : " + totalHarga),0,5);
grid.add(new Text("Terima Kasih telah menggunakan layanan Simple POS"),0,6);
Scene scene = new Scene(grid);
stage.setScene(scene);
stage.show();
}
public void denyBuy(){
Stage stage = new Stage();
stage.setTitle("Pembelian dibatalkan");
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
grid.setPadding(new Insets(10,10,10,10));
grid.add(new Text("Pembelian Dibatalkan"),0,0);
grid.add(new Text("Terima Kasih telah menggunakan layanan Simple POS"),0,1);
Scene scene = new Scene(grid);
stage.setScene(scene);
stage.show();
}
}
2.Screenshot
Comments
Post a Comment