Advertisement
reyhanzo

Untitled

Nov 27th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.96 KB | None | 0 0
  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.     ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  38.         "Nyno",
  39.         "Fadly",
  40.         "Nadhif",
  41.         "Rey"
  42.     );
  43.     final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  44.     ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  45.         "PP001",
  46.         "GC001",
  47.         "FG001",
  48.         "GM001"
  49.     );
  50.     final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
  51.    
  52.     private int TotalHarga;
  53.     private int harga;
  54.        
  55.     @Override
  56.     public void start(Stage stage) throws Exception
  57.     {
  58.        Scene scene = new Scene(new Group(), 500, 250);
  59.        stage.setTitle("Pembelian");
  60.        
  61.        //fortune.setFont(Font.font("SanSerif", 18));
  62.        textKasir.setFont(Font.font("SanSerif",18));
  63.        KodeBarang.setFont(Font.font("SanSerif",18));
  64.        textHarga.setFont(Font.font("SanSerif",18));
  65.        textJumlah.setFont(Font.font("SanSerif",18));
  66.        textTotalBayar.setFont(Font.font("SanSerif",18));
  67.        
  68.        GridPane grid = new GridPane();
  69.         grid.setVgap(10);
  70.         grid.setHgap(10);
  71.         grid.setPadding(new Insets(10, 10, 10, 10));
  72.         grid.add(new Label("Kasir: "), 0, 0);
  73.         grid.add(comboBoxKasir, 1,0);
  74.         grid.add(new Label("Kode Barang: "), 0, 1);
  75.         grid.add(comboBoxBarang, 1,1);
  76.        
  77.         EventHandler<ActionEvent> event =
  78.                   new EventHandler<ActionEvent>() {
  79.             public void handle(ActionEvent e)
  80.             {
  81.                 if(comboBoxBarang.getValue() == "PP001")
  82.                 {
  83.                     NamaBarang.setText("Pisang Goreng");
  84.                     HargaBarang.setText("Rp5000");
  85.                     harga = 5000;
  86.                 }
  87.                 else if(comboBoxBarang.getValue() == "GC001")
  88.                 {
  89.                     NamaBarang.setText("Gorengan Cimol");
  90.                     HargaBarang.setText("Rp3000");
  91.                     harga = 3000;
  92.                 }
  93.                 else if(comboBoxBarang.getValue() == "FG001")
  94.                 {
  95.                     NamaBarang.setText("Mainan Figur");
  96.                     HargaBarang.setText("Rp100000");
  97.                     harga = 100000;
  98.                 }
  99.                 else if(comboBoxBarang.getValue() == "GM001")
  100.                 {
  101.                     NamaBarang.setText("Gundam");
  102.                     HargaBarang.setText("Rp40000");
  103.                     harga = 40000;
  104.                 }    
  105.             }
  106.         };
  107.        
  108.         comboBoxBarang.setOnAction(event);
  109.        
  110.         grid.add(new Label("Nama Barang: "), 0, 2);
  111.         grid.add(NamaBarang, 1,2);
  112.         grid.add(new Label("Harga: "), 0, 3);
  113.         grid.add(HargaBarang, 1,3);
  114.         grid.add(new Label("Jumlah: "), 0, 4);
  115.        
  116.         grid.add(textFieldJumlah, 1,4);
  117.        
  118.         EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  119.             public void handle(ActionEvent e)
  120.             {
  121.                  TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  122.                  TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  123.             }
  124.         };
  125.        
  126.         textFieldJumlah.setOnAction(eventJumlah);
  127.        
  128.         grid.add(new Label("Total Bayar: "), 0, 5);
  129.         grid.add(TotalHargaText, 1,5);
  130.        
  131.        Text title=new Text("Hello Fortune Teller");
  132.        title.setFont(Font.font("SanSerif",36));
  133.        Button button = new Button("Cetak");
  134.        grid.add(button, 1,6);
  135.        
  136.        button.setOnAction(this::buttonClick);
  137.        
  138.        Group root = (Group)scene.getRoot();
  139.        root.getChildren().add(grid);
  140.        stage.setScene(scene);
  141.        stage.show();
  142.        
  143.        
  144.     }
  145.  
  146.     private void buttonClick(ActionEvent event)
  147.     {
  148.        Cetak c = new Cetak(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  149.        c.showCetak();
  150.     }
  151.    
  152.    
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement