EAS PBO SEM GASAL 2019/2020


Hasil Screenshot dari Program mesin transaksi

Tampilan menu :
 Tampilan menambahkan barang :
 Tampilan list barang :
 Tampilan saat akan mengedit barang :

 Tampilan saat ingin menghapus barang :

 Tampilan saat melakukan transaksi :
 Tampilan saat akan mencetak hasil transaksi :


Video :






Source Code (Gabungan , Tiap kelas dipisahkan oleh "//Source Code untuk Class ..."):

//Source Code untuk Class Main :
package application;
    
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Path;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;

import javafx.stage.Stage;
public class Main extends Application
{
    public static TableView<Databarang> table = new TableView<>();
    public static ObservableList<Databarang> data = FXCollections.observableArrayList();

    @Override
    public void start(Stage primaryStage) throws IOException, ClassNotFoundException 
    {
        TableColumn column1 = new TableColumn("Kode Barang");
        column1.prefWidthProperty().bind(table.widthProperty().multiply(0.25));
        column1.setCellValueFactory(new PropertyValueFactory<Databarang, String>("kodebar"));

        TableColumn column2 = new TableColumn("Nama Barang");
        column2.prefWidthProperty().bind(table.widthProperty().multiply(0.25));
        column2.setCellValueFactory(new PropertyValueFactory<Databarang, String>("namabar"));

        TableColumn column3 = new TableColumn("Harga Barang");
        column3.prefWidthProperty().bind(table.widthProperty().multiply(0.25));
        column3.setCellValueFactory(new PropertyValueFactory<Databarang, Integer>("hargabar"));

        TableColumn column4 = new TableColumn("Satuan Barang");
        column4.prefWidthProperty().bind(table.widthProperty().multiply(0.25));
        column4.setCellValueFactory(new PropertyValueFactory<Databarang, String>("satuanbar"));
        table.getColumns().setAll(column1, column2, column3, column4 );
        table.setItems(data);
        table.autosize();
        table.setEditable(false);
        Stage stage = new Stage();
        VBox box=new VBox();
        box.setPadding(new Insets(20));
        box.setSpacing(20);
        box.setAlignment(Pos.CENTER);
         Button List = new Button("Daftar Barang");
         List.setMaxWidth(Double.MAX_VALUE);
         EventHandler<ActionEvent> event1 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                    daftarbarang a = new daftarbarang(); 
                }
            };
            List.setOnAction(event1);
         Button Add = new Button("Tambah Barang");
         Add.setMaxWidth(Double.MAX_VALUE);
         EventHandler<ActionEvent> event2 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                    tambah b = new tambah();
                }
            };
            Add.setOnAction(event2);
         Button Edit = new Button("Edit Barang");
         Edit.setMaxWidth(Double.MAX_VALUE);
         EventHandler<ActionEvent> event3 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                    edit d = new edit();
                }
            };
           Edit.setOnAction(event3);
         Button Hapus= new Button("Hapus Barang");
         Hapus.setMaxWidth(Double.MAX_VALUE);
         EventHandler<ActionEvent> event4 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                    hapus c = new hapus();
                }
            };
            Hapus.setOnAction(event4);
         Button Transaksi = new Button("Transaksi baru");
         Transaksi.setMaxWidth(Double.MAX_VALUE);
         EventHandler<ActionEvent> event6 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                    transaksi x = new transaksi();
                }
            };
            Transaksi.setOnAction(event6);
         BufferedWriter writer = new BufferedWriter(new FileWriter("databarang.txt"));
         Button Keluar = new Button("Keluar");
         Keluar.setMaxWidth(Double.MAX_VALUE);
         String tab = "\t";
         String enter = "\n";
         EventHandler<ActionEvent> event5 = new EventHandler<ActionEvent>() 
            {
                public void handle(ActionEvent e) 
                { 
                     for(Databarang a: data)
                     {
                         try {
                            writer.write(a.getKodebar());
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                         try {
                            writer.write(tab);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                         try {
                            writer.write(a.getNamabar());
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                         try {
                            writer.write(tab);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                         try {
                            writer.write(Integer.toString(a.getHargabar()));
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                         try {
                            writer.write(tab);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                         try {
                            writer.write(a.getSatuanbar());
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                         try {
                            writer.write(enter);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                     }
                     try {
                        writer.close();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                     primaryStage.close();
                }
            };
         Keluar.setOnAction(event5);
         box.getChildren().add(List);
         box.getChildren().add(Add);
         box.getChildren().add(Edit);
         box.getChildren().add(Hapus);
         box.getChildren().add(Transaksi);
         box.getChildren().add(Keluar);
         Scene scene=new Scene(box,500,500);
         primaryStage.setTitle("POINT OF SALES");
         primaryStage.setScene(scene);
         primaryStage.show();   
         
    }
    public static void main(String[] args) 
    {
        launch(args);
    }
}

//Source Code Untuk Class transaksi :
package application;

import java.awt.print.PrinterException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.security.Timestamp;
import java.util.Optional;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.print.DocPrintJob;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.swing.JTextPane;
import java.util.Date;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class transaksi
{
    TextField addkodebar;
    TextField textjumlah;
    int cek;
    Text namabarang;
    Text harga;
    String x;
    Integer y;
    Integer z;
    Button add;
    Button cetak;
    Text nb = new Text();
    Text hb = new Text();
    Integer total = 0;
    public static ObservableList<barangdibeli> datadibeli = FXCollections.observableArrayList();
    public static TableView<barangdibeli> tabelbeli = new TableView<>();
    public transaksi()
    {
         
         TableColumn column1 = new TableColumn("Nama Barang");
         column1.prefWidthProperty().bind(tabelbeli.widthProperty().multiply(0.25));
         column1.setCellValueFactory(new PropertyValueFactory<barangdibeli, String>("namabar"));

         TableColumn column2 = new TableColumn("Jumlah Barang");
         column2.prefWidthProperty().bind(tabelbeli.widthProperty().multiply(0.25));
         column2.setCellValueFactory(new PropertyValueFactory<barangdibeli, Integer>("jumlahbar"));

         TableColumn column3 = new TableColumn("Harga Barang");
         column3.prefWidthProperty().bind(tabelbeli.widthProperty().multiply(0.25));
         column3.setCellValueFactory(new PropertyValueFactory<Databarang, Integer>("hargabar"));

         TableColumn column4 = new TableColumn("Harga Total Barang");
         column4.prefWidthProperty().bind(tabelbeli.widthProperty().multiply(0.25));
         column4.setCellValueFactory(new PropertyValueFactory<Databarang, Integer>("hargatotbar"));
         tabelbeli.getColumns().setAll(column1, column2, column3, column4 );
         Stage stage = new Stage();
         VBox box=new VBox();
         box.setAlignment(Pos.TOP_LEFT);
         addkodebar = new TextField();
         Text atas = new Text();
         atas.setText("Masukkan kode barang yang akan dibeli");
         addkodebar.setPromptText("Kode Barang Yang Akan Dibeli");
         namabarang = new Text("Nama Barang: ");
         harga = new Text("Harga Satuan: ");
         Button Cek = new Button("Cek");
            Cek.setOnAction(new EventHandler<ActionEvent>() 
            {
            @Override
                public void handle(ActionEvent arg0) 
                {
                    mengecek();
                    addkodebar.clear();
                }
            });
            
            textjumlah = new TextField();
            add = new Button("Tambahkan");
            add.setOnAction(new EventHandler<ActionEvent>() 
            {
            @Override
                public void handle(ActionEvent arg0) 
                {
                    menambah();
                    textjumlah.clear();
                }
            });
            Button button = new Button("Kembali");
             button.setOnAction(new EventHandler<ActionEvent>() 
             {

                @Override
                public void handle(ActionEvent arg0) 
                {
                    stage.close();
                    datadibeli.clear();
                }
            });
             cetak = new Button("Cetak");
            
             cetak.setOnAction(new EventHandler<ActionEvent>() 
             {
                  @Override
                    public void handle(ActionEvent arg0) 
                      {
                      StringBuilder final_string = new StringBuilder();
                        Integer jumlah_total_harga = 0;
                        for (barangdibeli items: datadibeli) 
                        {
                            
                            String namabarang = items.getNamabar();
                            String jumlahbarang = Integer.toString(items.getJumlahbar());
                            String hargabarang = Integer.toString(items.getHargabar());
                            String totalharga = Integer.toString(items.getHargatotbar());
                            jumlah_total_harga += Integer.parseInt(totalharga);
                            final_string.append(namabarang).append("\t").append(jumlahbarang).append("\t").append(hargabarang).append(" \t").append(totalharga).append("\t").append("\n");
                        }
                        final_string.append("\nTotal Harga: ").append(jumlah_total_harga);
                        BufferedWriter writer;
                        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                        Date date = new Date();
                        try 
                        {
                            writer = new BufferedWriter(new FileWriter("datatransaksi.txt"));
                            writer.write("Transaksi" + "\t" + dateFormat.format(date) + "\tRp. " + jumlah_total_harga);
                            writer.close();
                        } 
                        catch (IOException e) 
                        {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        };
                      
                        ButtonType print_button = new ButtonType("Print", ButtonData.OK_DONE);
                        ButtonType ok_button = new ButtonType("Ok",ButtonData.CANCEL_CLOSE);
                        Alert a = new Alert(Alert.AlertType.CONFIRMATION, final_string.toString(), print_button, ok_button);
                        a.setTitle("Nota : ");
                        Optional<ButtonType> result = a.showAndWait();
                        if (result.orElse(ok_button) == print_button) 
                        {
                            print(final_string.toString());
                        } 
                    }
             
                   
             });
             
            tabelbeli.setItems(datadibeli);
            box.getChildren().add(tabelbeli);
            box.getChildren().add(atas);
            box.getChildren().add(addkodebar); 
            box.getChildren().add(Cek);
            box.getChildren().add(namabarang);
            box.getChildren().add(nb);
            box.getChildren().add(harga);
            box.getChildren().add(hb);
            box.getChildren().add(textjumlah);
            box.getChildren().add(add);
            box.getChildren().add(button);
            box.getChildren().add(cetak);
            Scene scene1=new Scene(box,600,500);
            stage.setTitle("BELI BARANG");
            stage.setScene(scene1);
            stage.show();
    }
    public void mengecek()
    {

        String kodebar = addkodebar.getText();
        Alert b = new Alert(AlertType.INFORMATION);
         for(Databarang a : Main.data)
         {
             if(a.getKodebar().equals(kodebar))
             {
                 cek=1;         
                 x= a.getNamabar();
                 nb.setText(x);
                 z= a.getHargabar();
                 hb.setText("Rp. " + Integer.toString(z));
                 break;
             }
         }
         if(cek!=1)
         {
             b.setContentText("Kode barang yang anda masukkan tidak ada dalam daftar barang");
             b.show(); 
         }
    }
     private void print(String print_text) 
     {
            JTextPane textPane = new JTextPane();
            textPane.setText(print_text);
            try 
            {
                textPane.print();
            } 
            catch (PrinterException e) 
            {
                e.printStackTrace();
            }

        };
    public void menambah()
    {
        y=Integer.parseInt(textjumlah.getText());
        total += z*y;
        datadibeli.add(new barangdibeli(x,y,z,z*y));
        cek=0;
        nb.setText("");
        hb.setText("");
    }
    class PrintJobWatcher {
        boolean done = false;

        PrintJobWatcher(DocPrintJob job) {
            job.addPrintJobListener(new PrintJobAdapter() 
            {
                public void printJobCanceled(PrintJobEvent pje) 
                {
                    allDone();
                }
                public void printJobCompleted(PrintJobEvent pje) 
                {
                    allDone();
                }
                public void printJobFailed(PrintJobEvent pje) 
                {
                    allDone();
                }
                public void printJobNoMoreEvents(PrintJobEvent pje) 
                {
                    allDone();
                }
                void allDone() 
                {
                    synchronized (PrintJobWatcher.this) 
                    {
                        done = true;
                        System.out.println("Printing done ...");
                        PrintJobWatcher.this.notify();
                    }
                }
            });
        }
        public synchronized void waitForDone() 
        {
            try {
                while (!done) {
                    wait();
                }
            } catch (InterruptedException e) {
            }
        }
    }

}


//Source Code untuk Class daftarbarang :
package application;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class daftarbarang 
{
    public daftarbarang()
    {
        
         Stage stage = new Stage();
         VBox box=new VBox();
         box.setPadding(new Insets(20));
         box.setSpacing(20);
         box.setAlignment(Pos.TOP_LEFT);
         Button button = new Button("Kembali");
         button.setOnAction(new EventHandler<ActionEvent>() 
         {

            @Override
            public void handle(ActionEvent arg0) {
                stage.close();       
            }
        });
        box.getChildren().add(Main.table);
        box.getChildren().add(button);
        Scene scene1=new Scene(box,800,400);
        stage.setTitle("DAFTAR BARANG");
        stage.setScene(scene1);
        stage.show();
    }
}


//Source Code untuk Class editbarang :
package application;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class editbarang 
{
    TextField addkodebar;
    TextField addnamabar;
    TextField addharga;
    TextField addsatuan;
    Alert b = new Alert(AlertType.INFORMATION);
    public editbarang(Databarang x)
    {
        Stage stage = new Stage();
        VBox box=new VBox();
        box.setPadding(new Insets(20));
        box.setSpacing(20);
        box.setAlignment(Pos.CENTER);
        addkodebar = new TextField();
        addkodebar.setText(x.getKodebar());
        addnamabar = new TextField();
        addnamabar.setText(x.getNamabar());
        addharga = new TextField();
        addharga.setText(Integer.toString(x.getHargabar()));
        addsatuan = new TextField();
        addsatuan.setText(x.getSatuanbar());
        Button saveButton = new Button("Simpan");
        EventHandler<ActionEvent> event2 = new EventHandler<ActionEvent>() 
        {
            public void handle(ActionEvent e) 
            {
                 menyimpan(x);
            }
        }; 
        saveButton.setOnAction(event2);
        Button button = new Button("Kembali");
        button.setOnAction(new EventHandler<ActionEvent>() 
        {

            @Override
            public void handle(ActionEvent arg0) {
                stage.close();       
            }
        });
        box.getChildren().add(addkodebar);
        box.getChildren().add(addnamabar);
        box.getChildren().add(addharga);
        box.getChildren().add(addsatuan);
        box.getChildren().add(saveButton);
        box.getChildren().add(button);
        Scene scene1=new Scene(box,600,350);
        stage.setTitle("EDIT BARANG YANG SUDAH ADA");
        stage.setScene(scene1);
        stage.show();
    }
    public void menyimpan(Databarang x)
    {
        x.setKodebar(addkodebar.getText());
        x.setNamabar(addnamabar.getText());
        x.setHargabar(addharga.getText());
        x.setSatuanbar(addsatuan.getText());
        b.setContentText("Berhasil mengedit data barang");
        b.show(); 
         addnamabar.clear();
         addkodebar.clear();
         addharga.clear();
         addsatuan.clear();
    }
}

//Source Code untuk Class barangdibeli:
package application;

public class barangdibeli 
{
         private String namabar;
        private Integer jumlahbar;
        private Integer hargabar;
        private Integer hargatotbar;

        
        public barangdibeli(String namabar, Integer jumlah, Integer hargabar, Integer hargatotbar) 
        {
            this.namabar = namabar;
            this.jumlahbar = jumlah;
            this.hargabar = hargabar;
            this.hargatotbar = hargatotbar;
        }

        public String getNamabar() 
        {
            return namabar;
        }

        public void setNamabar(String namabar) 
        {
            this.namabar = namabar;
        }

        public Integer getJumlahbar() 
        {
            return jumlahbar;
        }

        public void setJumlahbar(Integer jumlah) 
        {
            this.jumlahbar = jumlahbar;
        }

        public int getHargabar() 
        {
            return hargabar;
        }

        public void setHargabar(Integer hargabar)
        {
            this.hargabar = hargabar;
        }

        public Integer getHargatotbar() 
        {
            return hargatotbar;
        }

        public void setHargatotbar(Integer hargatotbar) 
        {
            this.hargatotbar = hargatotbar;
        }
}

//Source Code untuk Class edit :
package application;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType; 

public class edit 
{
    TextField addkodebar;
    int cek;
    public edit()
    {
         Stage stage = new Stage();
         VBox box=new VBox();
         addkodebar = new TextField();
         Text atas = new Text();
         atas.setText("Masukkan kode barang yang akan dihapus");
         addkodebar.setPromptText("Kode Barang Yang Akan Diedit");
         Button edit = new Button("Edit");
            edit.setOnAction(new EventHandler<ActionEvent>() 
            {
            @Override
                public void handle(ActionEvent arg0) 
                {
                    mengedit();      
                }
            });
         box.setPadding(new Insets(20));
         box.setSpacing(20);
         box.setAlignment(Pos.CENTER);
         Button button = new Button("Kembali");
         button.setOnAction(new EventHandler<ActionEvent>() 
         {

            @Override
            public void handle(ActionEvent arg0) {
                stage.close();       
            }
        });
        box.getChildren().add(atas);
        box.getChildren().add(addkodebar); 
        box.getChildren().add(edit);
        box.getChildren().add(button);
        Scene scene1=new Scene(box,400,300);
        stage.setTitle("EDIT BARANG");
        stage.setScene(scene1);
        stage.show();
    }
    public void mengedit()
    {
        String kodebar = addkodebar.getText();
        Alert b = new Alert(AlertType.INFORMATION);
         for(Databarang a : Main.data)
         {
             if(a.getKodebar().equals(kodebar))
             {
                 cek=1;         
                 editbarang x = new editbarang(a);
                 addkodebar.clear();
                 break;
             }
         }
         if(cek!=1)
         {
             b.setContentText("Kode barang yang anda masukkan tidak ada dalam daftar barang");
             b.show(); 
         }
        
    }
}

//Source Code untuk Class tambah :
package application;

import java.io.BufferedWriter;
import java.io.FileWriter;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class tambah
{
    TextField addkodebar;
    TextField addnamabar;
    TextField addharga;
    TextField addsatuan;
    public tambah()
    {
        Stage stage = new Stage();
        VBox box=new VBox();
        box.setPadding(new Insets(20));
        box.setSpacing(20);
        box.setAlignment(Pos.CENTER);
        addkodebar = new TextField();
        addkodebar.setPromptText("Kode Barang");
        addnamabar = new TextField();
        addnamabar.setPromptText("Nama Barang");
        addharga = new TextField();
        addharga.setPromptText("Harga Barang");
        addsatuan = new TextField();
        addsatuan.setPromptText("Satuan Barang");
        Button addButton = new Button("Tambahkan");
        EventHandler<ActionEvent> event2 = new EventHandler<ActionEvent>() 
        {
            public void handle(ActionEvent e) 
            {
                 menambah();
            }
        }; 
        addButton.setOnAction(event2);
        Button button = new Button("Kembali");
        button.setOnAction(new EventHandler<ActionEvent>() 
        {

            @Override
            public void handle(ActionEvent arg0) {
                stage.close();       
            }
        });
        box.getChildren().add(addkodebar);
        box.getChildren().add(addnamabar);
        box.getChildren().add(addharga);
        box.getChildren().add(addsatuan);
        box.getChildren().add(addButton);
        box.getChildren().add(button);
        Scene scene1=new Scene(box,400,300);
        stage.setTitle("TAMBAHKAN BARANG");
        stage.setScene(scene1);
        stage.show();
    }
    public void menambah()
    {
        Main.data.add(new Databarang(addkodebar.getText(), addnamabar.getText(), Integer.parseInt(addharga.getText()), addsatuan.getText()));
         addnamabar.clear();
         addkodebar.clear();
         addharga.clear();
         addsatuan.clear();
    }
}

//Source Code untuk Class hapus :
package application;

import javax.swing.text.html.HTMLDocument.Iterator;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class hapus
{
    int cek;
    TextField addkodebar;
    public hapus()
    {
        Stage stage = new Stage();
        VBox box=new VBox();
        Text atas = new Text();
        atas.setText("Masukkan kode barang yang akan dihapus");
        addkodebar = new TextField();
        addkodebar.setPromptText("Kode Barang Yang Akan Dihapus");
        box.setPadding(new Insets(20));
        box.setSpacing(20);
        box.setAlignment(Pos.CENTER);
        Button back = new Button("Kembali");
        back.setOnAction(new EventHandler<ActionEvent>() 
        {
        @Override
            public void handle(ActionEvent arg0) 
            {
                stage.close();       
            }
        });
        Button delete = new Button("Hapus");
        delete.setOnAction(new EventHandler<ActionEvent>() 
        {
        @Override
            public void handle(ActionEvent arg0) 
            {
                menghapus();      
            }
        });
        box.getChildren().add(atas);
        box.getChildren().add(addkodebar);
        box.getChildren().add(delete);
        box.getChildren().add(back);
        Scene scene1=new Scene(box,400,300);
        stage.setTitle("HAPUS BARANG");
        stage.setScene(scene1);
        stage.show();

    }
    public void menghapus()
    {
        String kodebar = addkodebar.getText();
        Alert b = new Alert(AlertType.INFORMATION);
        //Main.data.removeIf(Databarang -> Databarang.getKodebar().equals(kodebar));
        for(Databarang a : Main.data)
        {
            if(a.getKodebar().equals(kodebar))
            {
                cek=1;
                Main.data.remove(a);
                break;
            }
        }
        if(cek!=1)
        {
            b.setContentText("Kode barang yang anda masukkan tidak ada dalam daftar barang");
            b.show();
        }
         else
         {
             b.setContentText("Barang berhasil dihapus!");
             b.show();     
         }
    }
}

//Source Code untuk Class Databarang :
package application;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Databarang  
{
    private String namabar;
    private String kodebar;
    private Integer hargabar;
    private String satuanbar;

    
    public Databarang(String kodebar, String namabar, Integer hargabar, String satuanbar) {
        this.namabar = namabar;
        this.kodebar = kodebar;
        this.hargabar = hargabar;
        this.satuanbar = satuanbar;
    }
    


    public String getNamabar() {
        return namabar;
    }

    public void setNamabar(String namabar) {
        this.namabar = namabar;
    }

    public String getKodebar() {
        return kodebar;
    }

    public void setKodebar(String kodebar) {
        this.kodebar = kodebar;
    }

    public int getHargabar() {
        return hargabar;
    }

    public void setHargabar(String hargabar) {
        this.hargabar = Integer.parseInt(hargabar);
    }

    public String getSatuanbar() {
        return satuanbar;
    }

    public void setSatuanbar(String satuanbar) {
        this.satuanbar = satuanbar;
    }
}


Comments