document.write('
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 imanuel
  24.  * @version 28/11/2019
  25.  */
  26. public class Pembelian extends Application
  27. {
  28.  
  29.     Text NamaBarang = new Text("");
  30.     Text HargaBarang = new Text("");
  31.     Text TotalHargaText = new Text("");
  32.     TextField textFieldJumlah = new TextField ();
  33.     //String[] fortunes = {"Test javaFx","WOI","OIOIOI"};
  34.     ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  35.         "Kasir1 :Ima",
  36.         "Kasir2 :Tupang",
  37.         "Kasir3 :Nuel"
  38.     );
  39.     final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  40.     ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  41.         "SA001",
  42.         "PH001",
  43.         "XI001"
  44.     );
  45.     final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
  46.    
  47.     private int TotalHarga;
  48.     private int harga;
  49.        
  50.     @Override
  51.     public void start(Stage stage) throws Exception
  52.     {
  53.        Scene scene = new Scene(new Group(), 500, 250);
  54.        stage.setTitle("Pembelian");
  55.  
  56.        
  57.        GridPane grid = new GridPane();
  58.         grid.setVgap(10);
  59.         grid.setHgap(10);
  60.         grid.setPadding(new Insets(10, 10, 10, 10));
  61.         grid.add(new Label("Kasir: "), 0, 0);
  62.         grid.add(comboBoxKasir, 1,0);
  63.         grid.add(new Label("Kode Barang: "), 0, 1);
  64.         grid.add(comboBoxBarang, 1,1);
  65.        
  66.         EventHandler<ActionEvent> event =
  67.                   new EventHandler<ActionEvent>() {
  68.             public void handle(ActionEvent e)
  69.             {
  70.                 if(comboBoxBarang.getValue() == "SA001")
  71.                 {
  72.                     NamaBarang.setText("TUPPERWARE PRO MAX");
  73.                     HargaBarang.setText("Rp5000");
  74.                     harga = 5000;
  75.                 }
  76.                 else if(comboBoxBarang.getValue() == "PH001")
  77.                 {
  78.                     NamaBarang.setText("TUPPERWARE J7");
  79.                     HargaBarang.setText("Rp12000");
  80.                     harga = 12000;
  81.                 }
  82.                 else if(comboBoxBarang.getValue() == "XI001")
  83.                 {
  84.                     NamaBarang.setText("TUPPERWARE RED ME");
  85.                     HargaBarang.setText("Rp7000");
  86.                     harga = 7000;
  87.                 }
  88.                      
  89.             }
  90.         };
  91.        
  92.         comboBoxBarang.setOnAction(event);
  93.        
  94.         grid.add(new Label("Nama Barang: "), 0, 2);
  95.         grid.add(NamaBarang, 1,2);
  96.         grid.add(new Label("Harga: "), 0, 3);
  97.         grid.add(HargaBarang, 1,3);
  98.         grid.add(new Label("Jumlah: "), 0, 4);
  99.        
  100.         grid.add(textFieldJumlah, 1,4);
  101.        
  102.         EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  103.             public void handle(ActionEvent e)
  104.             {
  105.                  TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  106.                  TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  107.             }
  108.         };
  109.        
  110.         textFieldJumlah.setOnAction(eventJumlah);
  111.        
  112.         grid.add(new Label("Total Bayar: "), 0, 5);
  113.         grid.add(TotalHargaText, 1,5);
  114.        
  115.        Text title=new Text("Hello Fortune Teller");
  116.        title.setFont(Font.font("SanSerif",36));
  117.        Button button = new Button("Cetak");
  118.        grid.add(button, 1,6);
  119.        
  120.        button.setOnAction(this::buttonClick);
  121.        
  122.        Group root = (Group)scene.getRoot();
  123.        root.getChildren().add(grid);
  124.        stage.setScene(scene);
  125.        stage.show();
  126.        
  127.        
  128.     }
  129.  
  130.     private void buttonClick(ActionEvent event)
  131.     {
  132.        Cetak c = new Cetak(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  133.        c.showCetak();
  134.     }
  135.    
  136.    
  137. }
');