Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 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. public class Detaildata extends Application
  21. {
  22.     Text textKasir = new Text("Petugas Kasir :");
  23.     Text KodeBarang = new Text("");
  24.     Text textHarga = new Text("");
  25.     Text textJumlah = new Text("");
  26.     Text textTotalBayar = new Text("");
  27.     Text NamaBarang = new Text("");
  28.     Text HargaBarang = new Text("");
  29.     Text TotalHargaText = new Text("");
  30.     TextField textFieldJumlah = new TextField ();
  31.     TextField textFieldKasir = new TextField ();
  32.     Text JumlahText = new Text("");
  33.    
  34.     ObservableList<String> optionBarang = FXCollections.observableArrayList( "A001", "B002", "C003");
  35.     final ComboBox comboBoxBarang = new ComboBox(optionBarang);
  36.    
  37.     private int TotalHarga;
  38.     private int Harga;
  39.     private int Jumlah;
  40.    
  41.     @Override
  42.     public void start(Stage stage) throws Exception
  43.     {
  44.         Scene scene = new Scene(new Group(), 500, 250);
  45.         stage.setTitle("Detail Pembelian");
  46.        
  47.         textKasir.setFont(Font.font("SanSerif",18));
  48.         KodeBarang.setFont(Font.font("SanSerif", 18));
  49.         textHarga.setFont(Font.font("SanSerif", 18));
  50.         textJumlah.setFont(Font.font("SanSerif", 18));
  51.         textTotalBayar.setFont(Font.font("SanSerif",18));
  52.        
  53.         GridPane grid = new GridPane();
  54.         grid.setVgap(10);
  55.         grid.setHgap(10);
  56.         grid.setPadding(new Insets(10, 10, 10, 10));
  57.         grid.add(new Label("Petugas Kasir : "), 0, 0);
  58.         grid.add(textFieldKasir, 1, 0);
  59.         grid.add(new Label("Kode Barang : " ), 0, 1);
  60.         grid.add(comboBoxBarang, 1, 1);
  61.        
  62.         EventHandler<ActionEvent> event = new EventHandler<ActionEvent>()
  63.         {
  64.             public void handle(ActionEvent e)
  65.             {
  66.                 if(comboBoxBarang.getValue() == "A001")
  67.                 {
  68.                     NamaBarang.setText("Sticker");
  69.                     HargaBarang.setText("Rp5000");
  70.                     Harga = 5000;
  71.                 }
  72.                 else if(comboBoxBarang.getValue() == "B002")
  73.                 {
  74.                     NamaBarang.setText("Enamel Pin");
  75.                     HargaBarang.setText("Rp25000");
  76.                     Harga = 25000;
  77.                 }
  78.                 else if(comboBoxBarang.getValue() == "C003")
  79.                 {
  80.                     NamaBarang.setText("Patch");
  81.                     HargaBarang.setText("Rp20000");
  82.                     Harga = 20000;
  83.                 }
  84.             }
  85.         };
  86.        
  87.         comboBoxBarang.setOnAction(event);
  88.        
  89.         grid.add(new Label("Nama Barang : "), 0, 2);
  90.         grid.add(NamaBarang, 1, 2);
  91.         grid.add(new Label("Harga : "), 0, 3);
  92.         grid.add(HargaBarang,1, 3);
  93.         grid.add(new Label("Jumlah Barang : "), 0, 4);
  94.         grid.add(textFieldJumlah, 1, 4);
  95.        
  96.         EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>()
  97.         {
  98.             public void handle(ActionEvent e)
  99.             {    
  100.                 TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * Harga;
  101.                 TotalHargaText.setText("Rp " + Integer.toString(TotalHarga));
  102.                 Jumlah = Integer.parseInt(textFieldJumlah.getText());
  103.                 JumlahText.setText(Integer.toString(Jumlah));
  104.             }
  105.         };
  106.        
  107.         textFieldJumlah.setOnAction(eventJumlah);
  108.         grid.add(new Label("Total Harga : "), 0, 5);
  109.         grid.add(TotalHargaText, 1, 5);
  110.         grid.add(new Label("Total Bayar : "), 0, 6);
  111.         grid.add(TotalHargaText, 1, 6);
  112.        
  113.         Button button = new Button("Cetak");
  114.         grid.add(button, 1, 6);
  115.        
  116.         button.setOnAction(this::buttonClick);
  117.        
  118.         Group root = (Group)scene.getRoot();
  119.         root.getChildren().add(grid);
  120.         stage.setScene(scene);
  121.         stage.show();
  122.     }
  123.        
  124.         private void buttonClick(ActionEvent event)
  125.         {
  126.             Cetak c = new Cetak(NamaBarang, JumlahText, TotalHargaText);
  127.             c.showCetak();
  128.         }
  129.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement