Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import javafx.application.Application;
  2. import javafx.application.Platform;
  3. import javafx.event.ActionEvent;
  4. import javafx.event.EventHandler;
  5. import javafx.geometry.Insets;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.*;
  9. import javafx.scene.layout.*;
  10. import javafx.scene.text.Font;
  11. import javafx.scene.text.Text;
  12. import javafx.stage.Stage;
  13. import javafx.scene.layout.StackPane;
  14. import javafx.collections.*;
  15. import javafx.scene.paint.*;
  16. import javafx.scene.text.*;
  17. import javafx.scene.Group;
  18. import java.util.Random;
  19.  
  20. /**
  21.  * Write a description of JavaFX class FortuneTeller here.
  22.  *
  23.  * @author (your name)
  24.  * @version (a version number or a date)
  25.  */
  26. public class Pembelian extends Application
  27. {
  28.     Text textKasir = new Text("Kasir :");
  29.     Text KodeBarang = new Text("");
  30.     Text textHarga = new Text("");
  31.     Text textJumlah = new Text("");
  32.     Text textTotalBayar = new Text("");
  33.     Text NamaBarang = new Text("");
  34.     Text HargaBarang = new Text("");
  35.     Text TotalHargaText = new Text("");
  36.     TextField textFieldJumlah = new TextField ();
  37.     //String[] fortunes = {"Test javaFx","WOI","OIOIOI"};
  38.     ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  39.         "Berto",
  40.         "Iqbaal",
  41.         "Abdi"
  42.     );
  43.     final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  44.     ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  45.         "BK001",
  46.         "P001",
  47.         "PE001"
  48.     );
  49.     final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
  50.    
  51.     private int TotalHarga;
  52.     private int harga;
  53.        
  54.     @Override
  55.     public void start(Stage stage) throws Exception
  56.     {
  57.        Scene scene = new Scene(new Group(), 500, 250);
  58.        stage.setTitle("Pembelian");
  59.        
  60.        //fortune.setFont(Font.font("SanSerif", 18));
  61.        textKasir.setFont(Font.font("SanSerif",18));
  62.        KodeBarang.setFont(Font.font("SanSerif",18));
  63.        textHarga.setFont(Font.font("SanSerif",18));
  64.        textJumlah.setFont(Font.font("SanSerif",18));
  65.        textTotalBayar.setFont(Font.font("SanSerif",18));
  66.        
  67.        GridPane grid = new GridPane();
  68.         grid.setVgap(10);
  69.         grid.setHgap(10);
  70.         grid.setPadding(new Insets(10, 10, 10, 10));
  71.         grid.add(new Label("Kasir: "), 0, 0);
  72.         grid.add(comboBoxKasir, 1,0);
  73.         grid.add(new Label("Kode Barang: "), 0, 1);
  74.         grid.add(comboBoxBarang, 1,1);
  75.        
  76.         EventHandler<ActionEvent> event =
  77.                   new EventHandler<ActionEvent>() {
  78.             public void handle(ActionEvent e)
  79.             {
  80.                 if(comboBoxBarang.getValue() == "BK001")
  81.                 {
  82.                     NamaBarang.setText("Buku Tulis");
  83.                     HargaBarang.setText("Rp5000");
  84.                     harga = 5000;
  85.                 }
  86.                 else if(comboBoxBarang.getValue() == "P001")
  87.                 {
  88.                     NamaBarang.setText("Pulpen");
  89.                     HargaBarang.setText("Rp2000");
  90.                     harga = 2000;
  91.                 }
  92.                 else if(comboBoxBarang.getValue() == "PE001")
  93.                 {
  94.                     NamaBarang.setText("Pensil");
  95.                     HargaBarang.setText("Rp1000");
  96.                     harga = 1000;
  97.                 }
  98.                      
  99.             }
  100.         };
  101.        
  102.         comboBoxBarang.setOnAction(event);
  103.        
  104.         grid.add(new Label("Nama Barang: "), 0, 2);
  105.         grid.add(NamaBarang, 1,2);
  106.         grid.add(new Label("Harga: "), 0, 3);
  107.         grid.add(HargaBarang, 1,3);
  108.         grid.add(new Label("Jumlah: "), 0, 4);
  109.        
  110.         grid.add(textFieldJumlah, 1,4);
  111.        
  112.         EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  113.             public void handle(ActionEvent e)
  114.             {
  115.                  TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  116.                  TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  117.             }
  118.         };
  119.        
  120.         textFieldJumlah.setOnAction(eventJumlah);
  121.        
  122.         grid.add(new Label("Total Bayar: "), 0, 5);
  123.         grid.add(TotalHargaText, 1,5);
  124.        
  125.        Text title=new Text("Hello Fortune Teller");
  126.        title.setFont(Font.font("SanSerif",36));
  127.        Button button = new Button("Cetak");
  128.        grid.add(button, 1,6);
  129.        
  130.        button.setOnAction(this::buttonClick);
  131.        
  132.        Group root = (Group)scene.getRoot();
  133.        root.getChildren().add(grid);
  134.        stage.setScene(scene);
  135.        stage.show();
  136.        
  137.        
  138.     }
  139.  
  140.     private void buttonClick(ActionEvent event)
  141.     {
  142.        Cetak c = new Cetak(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  143.        c.showCetak();
  144.     }
  145.    
  146.    
  147. }