Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.collections.*;
- 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.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.scene.text.TextAlignment;
- 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.Double;
- import java.lang.String;
- import java.util.ArrayList;
- import java.io.PrintStream;
- import java.util.Scanner;
- import java.io.IOException;
- import java.io.File;
- public class CashRegister extends Application
- {
- private int count = 0;
- private Label myLabel = new Label("0");
- private int lokasi = 0;
- private int discount = 0;
- private ArrayList<barang> product = new ArrayList<barang>();
- private ArrayList<barang> Keranjang = new ArrayList<barang>();
- private ArrayList<Integer> JumlahPembelian = new ArrayList<Integer>();
- private int Sum;
- private int Penghasilan = 0;
- private int lokasi2 = 0;
- private int lokasi3 = 0;
- @Override
- public void start(Stage stage)
- {
- inisialisasi();
- stage.setTitle("Cash Register");
- Label labelNo = new Label("No.");
- Label labelNo2 = new Label("No.");
- Label labelNama = new Label("Nama");
- Label labelJumlah = new Label("Jumlah");
- Label labelJumlah2 = new Label("Jumlah");
- Label labelHarga = new Label("Harga");
- Label labelTotal = new Label("Total");
- Label labelDiscount = new Label("Diskon");
- Label labelDiscountOutput = new Label(Integer.toString(discount)+"%");
- Label labelTotalOutput = new Label();
- Label productNo[] = new Label[4];
- Label productNama[] = new Label[4];
- Label productJumlah[] = new Label[4];
- Label productHarga[] = new Label[4];
- for(int i=0;i<4;i++){
- productNo[i] = new Label();
- productNama[i] = new Label();
- productJumlah[i] = new Label();
- productHarga[i] = new Label();
- }
- TextField inputNo = new TextField();
- TextField inputJumlah = new TextField();
- Button buttonEnter = new Button("Enter");
- /*
- Button button1 = new Button("1");
- Button button2 = new Button("2");
- Button button3 = new Button("3");
- Button button4 = new Button("4");
- Button button5 = new Button("5");
- Button button6 = new Button("6");
- Button button7 = new Button("7");
- Button button8 = new Button("8");
- Button button9 = new Button("9");
- Button button0 = new Button("0");
- Button button00 = new Button("00");
- Button buttonDot = new Button("1");*/
- //Button button7 = new Button("Receipt\nOn/Off"); //Receipt On/Off
- Button buttonCancel = new Button("Cancel"); //Error/Cancel
- Button buttonSettings = new Button("Settings"); //PLU
- //Button button10 = new Button("X/DATE-\nTIME"); //Multi or Date/Time
- Button buttonClear = new Button("Clear"); //Clear
- Button buttonDiscount = new Button("%-"); //Discount
- Button buttonStok = new Button("Open Stok"); //Coupon
- Button buttonUp = new Button("^"); //Button Up
- Button buttonDown = new Button("v"); //Button Down
- Button buttonOpenDrawer = new Button("Open Drawer"); //Open Drawer
- Button buttonSubTotal = new Button("Sub Total"); //Sub Total
- Button buttonPrint = new Button("Print"); //Print
- for(int i=0;i+lokasi<Keranjang.size();i++){
- productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
- productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
- productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
- productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
- }
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonSettings){
- stage.close();
- settings();
- }
- else if(e.getSource()==buttonEnter){
- int pNo = Integer.parseInt(inputNo.getText());
- if(pNo<product.size()){
- int pHarga = Integer.parseInt(inputJumlah.getText());
- addkeranjang(pNo,pHarga);
- if(Keranjang.size()>4){
- lokasi++;
- }
- for(int i=0;i+lokasi<Keranjang.size();i++){
- productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
- productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
- productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
- productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
- }
- }
- }
- else if(e.getSource()==buttonCancel){
- while(Keranjang.size()>0){
- Keranjang.remove(0);
- JumlahPembelian.remove(0);
- }
- lokasi=0;
- for(int i=0;i<4;i++){
- productNo[i].setText(" ");
- productNama[i].setText(" ");
- productJumlah[i].setText(" ");
- productHarga[i].setText(" ");
- }
- }
- else if(e.getSource()==buttonClear){
- if(Keranjang.size()>0){
- Keranjang.remove(Keranjang.size()-1);
- JumlahPembelian.remove(JumlahPembelian.size()-1);
- if(Keranjang.size()>4){
- lokasi--;
- }
- for(int i=0;i+lokasi<Keranjang.size();i++){
- productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
- productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
- productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
- productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
- }
- for(int i=Keranjang.size();i<4;i++){
- productNo[i].setText(" ");
- productNama[i].setText(" ");
- productJumlah[i].setText(" ");
- productHarga[i].setText(" ");
- }
- }
- }
- else if(e.getSource()==buttonDiscount){
- stage.close();
- addDiscount();
- }
- else if(e.getSource()==buttonStok){
- stage.close();
- Stok();
- }
- else if(e.getSource()==buttonUp){
- if(lokasi>0){
- lokasi--;
- for(int i=0;i+lokasi<Keranjang.size();i++){
- productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
- productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
- productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
- productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
- }
- }
- }
- else if(e.getSource()==buttonDown){
- if((lokasi+4)<product.size()){
- lokasi++;
- for(int i=0;i+lokasi<Keranjang.size();i++){
- productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
- productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
- productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
- productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
- }
- }
- }
- else if(e.getSource()==buttonSubTotal){
- Sum=0;
- for(int i=0;i<Keranjang.size();i++){
- Sum+=JumlahPembelian.get(i)*Keranjang.get(i).getharga_barang();
- }
- Sum=Sum*(100-discount)/100;
- labelTotal.setText(Integer.toString(Sum));
- }
- else if(e.getSource()==buttonPrint){
- Sum=0;
- for(int i=0;i<Keranjang.size();i++){
- Sum+=JumlahPembelian.get(i)*Keranjang.get(i).getharga_barang();
- }
- Sum=Sum*(100-discount)/100;
- Penghasilan += Sum;
- stage.close();
- Transaksi();
- while(Keranjang.size()>0){
- Keranjang.remove(0);
- JumlahPembelian.remove(0);
- }
- lokasi = 0 ;
- for(int i=0;i<4;i++){
- productNo[i].setText(" ");
- productNama[i].setText(" ");
- productJumlah[i].setText(" ");
- productHarga[i].setText(" ");
- }
- }
- else if(e.getSource()==buttonOpenDrawer){
- stage.close();
- Penghasilan();
- }
- }
- };
- buttonSettings.setOnAction(event);
- buttonCancel.setOnAction(event);
- buttonEnter.setOnAction(event);
- buttonClear.setOnAction(event);
- buttonDiscount.setOnAction(event);
- buttonStok.setOnAction(event);
- buttonUp.setOnAction(event);
- buttonDown.setOnAction(event);
- buttonSubTotal.setOnAction(event);
- buttonPrint.setOnAction(event);
- buttonOpenDrawer.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(labelNo, 1, 0);
- grid.add(labelNama, 2, 0);
- grid.add(labelJumlah, 3, 0);
- grid.add(labelHarga, 4, 0);
- for(int i=0;i<4;i++){
- grid.add(productNo[i],1,i+1);
- grid.add(productNama[i],2,i+1);
- grid.add(productJumlah[i],3,i+1);
- grid.add(productHarga[i],4,i+1);
- }
- grid.add(labelTotal, 3, 5);
- grid.add(labelTotalOutput,4,5);
- grid.add(labelDiscount,3,7);
- grid.add(labelDiscountOutput,4,7);
- grid.add(labelNo2,1,6);
- grid.add(inputNo,2,6);
- grid.add(labelJumlah2,3,6);
- grid.add(inputJumlah,4,6);
- grid.add(buttonEnter,5,6);
- buttonEnter.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonUp,0,1);
- buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonDown,0,4);
- buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonSettings,5,0);
- buttonSettings.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonClear,6,6);
- buttonClear.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonOpenDrawer,2,7);
- buttonOpenDrawer.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonDiscount,5,7);
- buttonDiscount.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonSubTotal,4,8);
- buttonSubTotal.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonCancel,2,9);
- buttonCancel.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonPrint,4,9);
- buttonPrint.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonStok,2,8);
- buttonStok.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void buttonClick(ActionEvent event)
- {
- count = count + 1;
- myLabel.setText(Integer.toString(count));
- }
- private void settings(){
- Stage stage = new Stage();
- Button buttonNew = new Button("Tambah Produk");
- Button buttonRemove = new Button("Hapus Produk");
- Button buttonEdit = new Button("Edit Data Produk");
- Button buttonBack = new Button("Kembali ke Cash Register");
- Button buttonLoad = new Button("Mengambil Produk");
- Button buttonStore = new Button("Menyiman Data Produk");
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- start(new Stage());
- }else if(e.getSource()==buttonNew){
- stage.close();
- newProduct();
- }else if(e.getSource()==buttonRemove){
- stage.close();
- RemoveProduct();
- }else if(e.getSource()==buttonEdit){
- stage.close();
- editProduct();
- }else if(e.getSource()==buttonLoad){
- Load();
- }else if(e.getSource()==buttonStore){
- Store();
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonNew.setOnAction(event);
- buttonRemove.setOnAction(event);
- buttonEdit.setOnAction(event);
- buttonLoad.setOnAction(event);
- buttonStore.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(buttonNew,2,0);
- buttonNew.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonRemove,2,1);
- buttonRemove.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonEdit,2,2);
- buttonEdit.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonLoad,2,3);
- buttonLoad.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonStore,2,4);
- buttonStore.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonBack,2,5);
- buttonBack.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void Stok(){
- Stage stage = new Stage();
- stage.setTitle("Data_Produk");
- Label labelNo = new Label("No.");
- Label labelNama = new Label("Nama");
- Label labelHarga = new Label("Harga");
- Label labelTotal = new Label("Total");
- Button buttonUp = new Button("^"); //Button Up
- Button buttonDown = new Button("v");
- Label productNo[] = new Label[7];
- Label productNama[] = new Label[7];
- Label productHarga[] = new Label[7];
- for(int i=0;i<7;i++){
- productNo[i] = new Label();
- productNama[i] = new Label();
- productHarga[i] = new Label();
- }
- lokasi2=0;
- for(int i=0;i+lokasi2<product.size()&&i<7;i++){
- productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
- productNama[i].setText(product.get(i+lokasi2).getnama_barang());
- productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
- }
- Button buttonBack = new Button("Kembali");
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- start(new Stage());
- }else if(e.getSource()==buttonUp){
- if(lokasi2>0){
- lokasi2--;
- for(int i=0;i+lokasi2<product.size();i++){
- productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
- productNama[i].setText(product.get(i+lokasi2).getnama_barang());
- productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
- }
- }
- }
- else if(e.getSource()==buttonDown){
- if(lokasi2<product.size()-7){
- lokasi2++;
- for(int i=0;i+lokasi2<product.size();i++){
- productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
- productNama[i].setText(product.get(i+lokasi2).getnama_barang());
- productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
- }
- }
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonUp.setOnAction(event);
- buttonDown.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(buttonUp,0,1);
- buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonDown,0,4);
- buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonBack,0,9);
- grid.add(labelNo, 1, 0);
- grid.add(labelNama, 3, 0);
- grid.add(labelHarga, 5, 0);
- for(int i=0;i<7;i++){
- grid.add(productNo[i],1,i+1);
- grid.add(productNama[i],3,i+1);
- grid.add(productHarga[i],5,i+1);
- }
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void Transaksi(){
- Stage stage = new Stage();
- stage.setTitle("Transaksi");
- Label labelDiscountOutput = new Label(Integer.toString(discount)+"%");
- Label labelDiscount = new Label("Diskon");
- Label labelNo = new Label("No.");
- Label labelNama = new Label("Nama");
- Label labelHarga = new Label("Harga");
- Label labelTotal = new Label("Total");
- Label labelTotal2 = new Label();
- Label labelJumlah = new Label("Jumlah");
- Label labelJumlahHarga = new Label("Total");
- Label KeranjangNo[] = new Label[7];
- Label KeranjangNama[] = new Label[7];
- Label KeranjangHarga[] = new Label[7];
- Label KeranjangJumlah[] = new Label[7];
- Label KeranjangJumlahHarga[] = new Label [7];
- for(int i=0;i<7;i++){
- KeranjangNo[i] = new Label();
- KeranjangJumlah[i] = new Label();
- KeranjangNama[i] = new Label();
- KeranjangHarga[i] = new Label();
- KeranjangJumlahHarga[i] = new Label();
- }
- lokasi3=0;
- for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
- KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
- KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
- KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
- KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
- KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
- }
- Button buttonUp = new Button("^"); //Button Up
- Button buttonDown = new Button("v");
- Button buttonBack = new Button("Kembali");
- labelTotal2.setText(Integer.toString(Sum));
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- start(new Stage());
- }else if(e.getSource()==buttonUp){
- if(lokasi3>0){
- lokasi3--;
- for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
- KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
- KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
- KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
- KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
- KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
- }
- }
- }
- else if(e.getSource()==buttonDown){
- if(lokasi3<product.size()-7){
- lokasi3++;
- for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
- KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
- KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
- KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
- KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
- KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
- }
- }
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonUp.setOnAction(event);
- buttonDown.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(buttonUp,0,1);
- buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonDown,0,4);
- buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
- grid.add(buttonBack,0,9);
- grid.add(labelTotal,4,9);
- grid.add(labelTotal2,5,9);
- grid.add(labelDiscount,2,9);
- grid.add(labelDiscountOutput,3,9);
- grid.add(labelNo, 1, 0);
- grid.add(labelNama, 2, 0);
- grid.add(labelHarga, 3, 0);
- grid.add(labelJumlah, 4, 0);
- grid.add(labelJumlahHarga, 5, 0);
- for(int i=0;i<7;i++){
- grid.add(KeranjangNo[i],1,i+1);
- grid.add(KeranjangNama[i],2,i+1);
- grid.add(KeranjangHarga[i],3,i+1);
- grid.add(KeranjangJumlah[i],4,i+1);
- grid.add(KeranjangJumlahHarga[i],5,i+1);
- }
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- //------------------------------------------------------------------------------------------
- private void newProduct(){
- Stage stage = new Stage();
- stage.setTitle("Tambah Produk");
- Label labelNama = new Label("Nama Produk: ");
- Label labelHarga = new Label("Harga Produk: ");
- TextField inputNama = new TextField();
- TextField inputHarga = new TextField();
- Button buttonBack = new Button("Kembali");
- Button buttonSave = new Button("Simpan");
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- settings();
- }
- if(e.getSource()==buttonSave){
- int pNo = product.size()+1;
- String pNama = inputNama.getText();
- int pHarga = Integer.parseInt(inputHarga.getText());
- addslot(pHarga,pNama);
- stage.close();
- settings();
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonSave.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(labelNama,0,1);
- grid.add(labelHarga,0,2);
- grid.add(inputNama,1,1);
- grid.add(inputHarga,1,2);
- grid.add(buttonBack,0,3);
- grid.add(buttonSave,1,3);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void RemoveProduct(){
- Stage stage = new Stage();
- stage.setTitle("Menghapus Data Produk");
- Label labelNo = new Label("No. Produk: ");
- Label labelNama = new Label("Nama Produk: ");
- TextField inputNo = new TextField();
- TextField inputNama = new TextField();
- Button buttonBack = new Button("Kembali");
- Button buttonDelete = new Button("Hapus");
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- settings();
- }
- if(e.getSource()==buttonDelete){
- if(Integer.parseInt(inputNo.getText()) > 0&& Integer.parseInt(inputNo.getText())<=product.size()){
- barang Item = new barang();
- product.remove(Integer.parseInt(inputNo.getText())-1);
- for(int i = Integer.parseInt(inputNo.getText())-1;i < product.size();i++){
- Item = product.get(i);
- Item.setno_barang(i+1);
- product.remove(i);
- product.add(i,Item);
- }
- stage.close();
- settings();
- }else{
- String pNama = inputNama.getText();
- for(int i=0;i<product.size();i++){
- if((pNama.equals(product.get(i).getnama_barang()))){
- barang Item = new barang();
- product.remove(Integer.parseInt(inputNo.getText())-1);
- for(int j = i;j < product.size();j++){
- Item = product.get(j);
- Item.setno_barang(j+1);
- product.remove(j);
- product.add(j,Item);
- }
- }
- }
- }
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonDelete.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(labelNo,0,0);
- grid.add(labelNama,0,1);
- grid.add(inputNo,1,0);
- grid.add(inputNama,1,1);
- grid.add(buttonBack,0,3);
- grid.add(buttonDelete,1,3);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void editProduct(){
- Stage stage = new Stage();
- stage.setTitle("Ubah Data Produk");
- Label labelNo = new Label("No. Produk: ");
- Label labelNama = new Label("Nama Produk: ");
- Label labelHarga = new Label("Harga Produk: ");
- TextField inputNo = new TextField();
- TextField inputNama = new TextField();
- TextField inputHarga = new TextField();
- Button buttonBack = new Button("Kembali");
- Button buttonSave = new Button("Simpan");
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==buttonBack){
- stage.close();
- settings();
- }
- if(e.getSource()==buttonSave){
- if(Integer.parseInt(inputNo.getText()) > 0&& Integer.parseInt(inputNo.getText())<=product.size()){
- String pNama = inputNama.getText();
- int pHarga = Integer.parseInt(inputHarga.getText());
- barang Item = new barang();
- Item.edit(Integer.parseInt(inputNo.getText()),pHarga,pNama);
- product.remove(Integer.parseInt(inputNo.getText())-1);
- product.add(Integer.parseInt(inputNo.getText())-1,Item);
- stage.close();
- settings();
- }
- }
- }
- };
- buttonBack.setOnAction(event);
- buttonSave.setOnAction(event);
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- grid.add(labelNo,0,0);
- grid.add(labelNama,0,1);
- grid.add(labelHarga,0,2);
- grid.add(inputNo,1,0);
- grid.add(inputNama,1,1);
- grid.add(inputHarga,1,2);
- grid.add(buttonBack,0,3);
- grid.add(buttonSave,1,3);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void addDiscount() {
- Stage stage = new Stage();
- stage.setTitle("Diskon");
- Label labelDiscount = new Label("Diskon:");
- TextField inputDiscount = new TextField();
- Button confirm = new Button("Confirm");
- Button cancel = new Button("Cancel");
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==cancel){
- stage.close();
- start(new Stage());
- }
- else if(e.getSource()==confirm){
- int dc = Integer.parseInt(inputDiscount.getText());
- if(dc>100)
- dc = 100;
- discount = dc;
- stage.close();
- start(new Stage());
- }
- }
- };
- confirm.setOnAction(event);
- cancel.setOnAction(event);
- grid.add(labelDiscount,0,0);
- grid.add(inputDiscount,1,0);
- grid.add(cancel,0,1);
- grid.add(confirm,1,1);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void Penghasilan() {
- Stage stage = new Stage();
- stage.setTitle("Penghasilan");
- Label pengusaha = new Label("Penghasilan:");
- Label hasilusaha = new Label();
- hasilusaha.setText(Integer.toString(Penghasilan));
- Button usaha = new Button("OK");
- GridPane grid = new GridPane();
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.setMinSize(300, 300);
- grid.setVgap(3);
- grid.setHgap(3);
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
- public void handle(ActionEvent e)
- {
- if(e.getSource()==usaha){
- stage.close();
- start(new Stage());
- }
- }
- };
- usaha.setOnAction(event);
- grid.add(pengusaha,0,0);
- grid.add(hasilusaha,2,0);
- grid.add(usaha,0,1);
- Scene scene = new Scene(grid);
- stage.setScene(scene);
- stage.show();
- }
- // menyimpan data ke dalam bentuk file
- void Store(){
- try
- { PrintStream writer = new PrintStream( new File("Data_produk.txt"));
- int Limit = product.size();
- for(int i = 0; i < Limit; i++)
- {
- writer.println(product.get(i).getAll());
- }
- writer.close();
- }
- catch(IOException e)
- {
- System.out.println("An error occured while trying to write to the file");
- }
- }
- // mengambil data dari file ke dalam program
- void Load(){
- try
- { Scanner Data = new Scanner( new File("Data_produk.txt") );
- while( Data.hasNextInt() )
- { Data.nextInt();
- addslot(Data.nextInt(),Data.next());
- }
- }
- catch(IOException e)
- {
- System.out.println("An error occured while trying to reading from the file");
- }
- }
- // to add item into the product
- void addslot(int harga_barang, String nama_barang){
- int i;
- for(i=0;i<product.size();i++){
- if((nama_barang.equals(product.get(i).getnama_barang()))){
- i=-1;
- break;
- }
- }
- if(i==product.size()){
- barang Item = new barang();
- Item.edit(product.size()+1,harga_barang,nama_barang);
- product.add(Item);
- }
- }
- void addkeranjang(int no_barang, int jumlah_barang){
- barang Item = new barang();
- Item.edit(Keranjang.size()+1,product.get(no_barang-1).getharga_barang(),product.get(no_barang-1).getnama_barang());
- Keranjang.add(Item);
- JumlahPembelian.add(jumlah_barang);
- }
- void inisialisasi(){
- addslot(100,"jagung");
- addslot(700,"jamur");
- addslot(600,"kedelai");
- addslot(500,"tulang");
- addslot(200,"tomat");
- addslot(1040,"kaki");
- addslot(419,"ampela");
- addslot(200,"botol");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement