POINT OF SALES JAVAFX

Berikut ini contoh Program Point of Sales dengan JavaFX:
Syntax:

 
import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.*; 
import javafx.scene.layout.*; 
import javafx.stage.Stage; 
import javafx.scene.layout.*; 
import javafx.scene.paint.*; 
import javafx.scene.text.*; 
import javafx.geometry.*; 
import javafx.scene.layout.*; 
import javafx.scene.shape.*; 
import javafx.collections.*; 
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import java.lang.Integer; 
/**
 * Write a description of JavaFX class FortuneTeller here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class FortuneTeller extends Application
{
       int harganya;
       int jumlahbar;
       int total;
    @Override
    public void start(Stage stage) throws Exception
    {
      GridPane gridPane = new GridPane();  
      gridPane.setMinSize(400, 200);
      gridPane.setPadding(new Insets(10, 10, 10, 10));
      gridPane.setVgap(5); 
      gridPane.setHgap(5);       
       
       
       Text kasir=new Text("Nama Petugas Kasir: ");
       kasir.setFont(Font.font("SanSerif",20));
       
       Text kodebarang = new Text("Kode Barang: ");
       kodebarang.setFont(Font.font("SanSerif",20));
       
       Text namabarang = new Text("Nama Barang: ");
       namabarang.setFont(Font.font("SanSerif",20));
       
       Text harga = new Text("Harga: ");
       harga.setFont(Font.font("SanSerif",20));
      
       Text jumlah = new Text("Jumlah: ");
       jumlah.setFont(Font.font("SanSerif",20));
       
       Text totalbayar = new Text("Total Bayar" );
       totalbayar.setFont(Font.font("SanSerif",20));
       
       TextField textjumlah = new TextField(); 
       TextField textkasir = new TextField();
       Text namabox = new Text();
       Text hargabox = new Text();
       Text hasiltotal = new Text();
       gridPane.add(kasir,0,0);
       gridPane.add(textkasir, 1,0);
       gridPane.add(kodebarang,0,1);
       gridPane.add(namabarang,0,2);
       gridPane.add(harga,0,3);
       gridPane.add(jumlah,0,4);
       gridPane.add(totalbayar, 0,5);
       
       String kode_barang[] = {"B001", "B002", "B003", "B004"};
       ComboBox combo_box = new ComboBox(FXCollections.observableArrayList(kode_barang));
       gridPane.add(combo_box, 1,1); 
       EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() 
        { 
            public void handle(ActionEvent e) 
            {
                ;

                if(combo_box.getValue() == "B001")
                {
                    namabox.setText("Aqua galon");
                    hargabox.setText("Rp. 12.000");
                    harganya = 12000;
                }
                else if(combo_box.getValue() == "B002")
                {
                    namabox.setText("Buku tulis");
                    hargabox.setText("Rp. 4.000");
                    harganya = 4000;
                }
                else if(combo_box.getValue() == "B003")
                {
                    namabox.setText("Tas sekolah");
                    hargabox.setText("Rp. 100.000");
                    harganya = 100000;
                }
                else if(combo_box.getValue() == "B004")
                {
                    namabox.setText("Jas Hujan");
                    hargabox.setText("Rp. 50.000");
                    harganya = 50000;
                } 
               
            }
        };  
        // Set on action 
        combo_box.setOnAction(event); 
        gridPane.add(namabox, 1, 2);
        gridPane.add(hargabox, 1, 3);
   
         EventHandler<ActionEvent>eventnew = new EventHandler<ActionEvent>() 
         { 
            public void handle(ActionEvent e) 
            { 
                jumlahbar= Integer.parseInt(textjumlah.getText());
                total = jumlahbar * harganya;
                hasiltotal.setText("Rp. " + total);
            } 
        }; 
        textjumlah.setOnAction(eventnew); 
        gridPane.add(textjumlah,1,4);
        gridPane.add(hasiltotal, 1, 5);
        Button cetak = new Button("Cetak"); 
        
        EventHandler<ActionEvent> event2 = new EventHandler<ActionEvent>() 
        {
          
            public void handle(ActionEvent e) 
            { 
                 VBox box=new VBox();
                 box.setPadding(new Insets(20));
                 box.setSpacing(20);
                 box.setAlignment(Pos.TOP_LEFT);
                 Text text1 = new Text("BUKTI PEMBELIAN");
                 text1.setFont(Font.font("SanSerif",20));
                 Text text2 = new Text("Nama barang: " + namabox.getText());
                 text2.setFont(Font.font("SanSerif",20));
                 Text text3 = new Text("Harga barang: " + hargabox.getText());
                 text3.setFont(Font.font("SanSerif",20));
                 Text text4 = new Text("Jumlah barang: " + jumlahbar);
                 text4.setFont(Font.font("SanSerif",20));
                 Text text5 = new Text("Total Pembayaran: Rp. " + total);
                 text5.setFont(Font.font("SanSerif",20));
                  box.getChildren().add(text1);
                  box.getChildren().add(text2);
                  box.getChildren().add(text3);
                  box.getChildren().add(text4);
                  box.getChildren().add(text5);
                  Scene scene1=new Scene(box,500,250);
                  stage.setTitle("BUKTI PEMBELIAN");
                  stage.setScene(scene1);
                  stage.show();
                  
            } 
        }; 
        cetak.setOnAction(event2);
        gridPane.add(cetak, 6,6);
       Scene scene=new Scene(gridPane,800,500);
       stage.setTitle("POINT OF SALES");
       stage.setScene(scene);
       stage.show();
      
    }
}
 



Hasil run:

Hasil run setelah diklik tombol cetak:


Komentar

Postingan populer dari blog ini

TUGAS 1

ETS PBO

RESUME KULIAH TAMU