Advertisement
yusufmukharom

Untitled

Nov 27th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.58 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.     //String[] fortunes = {"Test javaFx","WOI","OIOIOI"};
  38.     ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  39.         "1 Bobby",
  40.         "2 Arjuna",
  41.         "3 Komet",
  42.         "4 Sadako",
  43.         "5 Pony"
  44.     );
  45.     final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  46.     ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  47.         "BK001",
  48.         "BK002",
  49.         "BK003",
  50.         "PU001",
  51.         "PU002",
  52.         "PU003"
  53.     );
  54.     final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
  55.    
  56.     private int TotalHarga;
  57.     private int harga;
  58.        
  59.     @Override
  60.     public void start(Stage stage) throws Exception
  61.     {
  62.        Scene scene = new Scene(new Group(), 500, 250);
  63.        stage.setTitle("Pembelian");
  64.        
  65.        //fortune.setFont(Font.font("SanSerif", 18));
  66.        textKasir.setFont(Font.font("SanSerif",18));
  67.        KodeBarang.setFont(Font.font("SanSerif",18));
  68.        textHarga.setFont(Font.font("SanSerif",18));
  69.        textJumlah.setFont(Font.font("SanSerif",18));
  70.        textTotalBayar.setFont(Font.font("SanSerif",18));
  71.        
  72.        GridPane grid = new GridPane();
  73.         grid.setVgap(10);
  74.         grid.setHgap(10);
  75.         grid.setPadding(new Insets(10, 10, 10, 10));
  76.         grid.add(new Label("Kasir: "), 0, 0);
  77.         grid.add(comboBoxKasir, 1,0);
  78.         grid.add(new Label("Kode Barang: "), 0, 1);
  79.         grid.add(comboBoxBarang, 1,1);
  80.        
  81.         EventHandler<ActionEvent> event =
  82.                   new EventHandler<ActionEvent>() {
  83.             public void handle(ActionEvent e)
  84.             {
  85.                 if(comboBoxBarang.getValue() == "BK001")
  86.                 {
  87.                     NamaBarang.setText("Buku Sidu");
  88.                     HargaBarang.setText("Rp5000");
  89.                     harga = 5000;
  90.                 }
  91.                 else if(comboBoxBarang.getValue() == "BK002")
  92.                 {
  93.                     NamaBarang.setText("Buku Gelatik");
  94.                     HargaBarang.setText("Rp3000");
  95.                     harga = 3000;
  96.                 }
  97.                 else if(comboBoxBarang.getValue() == "BK003")
  98.                 {
  99.                     NamaBarang.setText("Buku Apollo");
  100.                     HargaBarang.setText("Rp2500");
  101.                     harga = 2500;
  102.                 }
  103.                 else if(comboBoxBarang.getValue() == "PU001")
  104.                 {
  105.                     NamaBarang.setText("Pulpen Pilot");
  106.                     HargaBarang.setText("Rp2500");
  107.                     harga = 2500;
  108.                 }
  109.                 else if(comboBoxBarang.getValue() == "PU002")
  110.                 {
  111.                     NamaBarang.setText("Pulpen Cruzer");
  112.                     HargaBarang.setText("Rp6000");
  113.                     harga = 6000;
  114.                 }
  115.                 else if(comboBoxBarang.getValue() == "PU003")
  116.                 {
  117.                     NamaBarang.setText("Pulpen Pesawat");
  118.                     HargaBarang.setText("Rp4000");
  119.                     harga = 4000;
  120.                 }
  121.                      
  122.             }
  123.         };
  124.        
  125.         comboBoxBarang.setOnAction(event);
  126.        
  127.         grid.add(new Label("Nama Barang: "), 0, 2);
  128.         grid.add(NamaBarang, 1,2);
  129.         grid.add(new Label("Harga: "), 0, 3);
  130.         grid.add(HargaBarang, 1,3);
  131.         grid.add(new Label("Jumlah: "), 0, 4);
  132.        
  133.         grid.add(textFieldJumlah, 1,4);
  134.        
  135.         EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  136.             public void handle(ActionEvent e)
  137.             {
  138.                  TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  139.                  TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  140.             }
  141.         };
  142.        
  143.         textFieldJumlah.setOnAction(eventJumlah);
  144.        
  145.         grid.add(new Label("Total Bayar: "), 0, 5);
  146.         grid.add(TotalHargaText, 1,5);
  147.        
  148.        Text title=new Text("Hello Fortune Teller");
  149.        title.setFont(Font.font("SanSerif",36));
  150.        Button button = new Button("Cetak");
  151.        grid.add(button, 1,6);
  152.        
  153.        button.setOnAction(this::buttonClick);
  154.        
  155.        Group root = (Group)scene.getRoot();
  156.        root.getChildren().add(grid);
  157.        stage.setScene(scene);
  158.        stage.show();
  159.        
  160.        
  161.     }
  162.  
  163.     private void buttonClick(ActionEvent event)
  164.     {
  165.        Cetak c = new Cetak(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  166.        c.showCetak();
  167.     }
  168.    
  169.    
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement