Guest User

Untitled

a guest
Nov 27th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. /**
  2. * Aplikasi Point Of Sales menggunakan JavaFX
  3. *
  4. * @author Adam Abelard Garibaldi
  5. * @version 1.0
  6. */
  7. import javafx.application.Application;
  8. import javafx.application.Platform;
  9. import javafx.event.ActionEvent;
  10. import javafx.event.EventHandler;
  11. import javafx.geometry.Insets;
  12. import javafx.geometry.Pos;
  13. import javafx.scene.Scene;
  14. import javafx.scene.control.*;
  15. import javafx.scene.layout.*;
  16. import javafx.scene.text.Font;
  17. import javafx.scene.text.Text;
  18. import javafx.stage.Stage;
  19. import javafx.scene.layout.StackPane;
  20. import javafx.collections.*;
  21. import javafx.scene.paint.*;
  22. import javafx.scene.text.*;
  23. import javafx.scene.Group;
  24. import java.util.Random;
  25.  
  26.  
  27. public class Pembelian extends Application
  28. {
  29. Text textKasir = new Text("Kasir :");
  30. Text KodeBarang = new Text("");
  31. Text textHarga = new Text("");
  32. Text textJumlah = new Text("");
  33. Text textTotalBayar = new Text("");
  34. Text NamaBarang = new Text("");
  35. Text HargaBarang = new Text("");
  36. Text TotalHargaText = new Text("");
  37. TextField textFieldJumlah = new TextField ();
  38. //String[] fortunes = {"Test javaFx","WOI","OIOIOI"};
  39. ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  40. "Adam",
  41. "Aaron",
  42. "Syubban"
  43. );
  44. final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  45. ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  46. "BK001",
  47. "P001",
  48. "PE001"
  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() == "BK001")
  82. {
  83. NamaBarang.setText("Buku Tulis");
  84. HargaBarang.setText("Rp5000");
  85. harga = 5000;
  86. }
  87. else if(comboBoxBarang.getValue() == "P001")
  88. {
  89. NamaBarang.setText("Pulpen");
  90. HargaBarang.setText("Rp2000");
  91. harga = 2000;
  92. }
  93. else if(comboBoxBarang.getValue() == "PE001")
  94. {
  95. NamaBarang.setText("Pensil");
  96. HargaBarang.setText("Rp1000");
  97. harga = 1000;
  98. }
  99.  
  100. }
  101. };
  102.  
  103. comboBoxBarang.setOnAction(event);
  104.  
  105. grid.add(new Label("Nama Barang: "), 0, 2);
  106. grid.add(NamaBarang, 1,2);
  107. grid.add(new Label("Harga: "), 0, 3);
  108. grid.add(HargaBarang, 1,3);
  109. grid.add(new Label("Jumlah: "), 0, 4);
  110.  
  111. grid.add(textFieldJumlah, 1,4);
  112.  
  113. EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  114. public void handle(ActionEvent e)
  115. {
  116. TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  117. TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  118. }
  119. };
  120.  
  121. textFieldJumlah.setOnAction(eventJumlah);
  122.  
  123. grid.add(new Label("Total Bayar: "), 0, 5);
  124. grid.add(TotalHargaText, 1,5);
  125.  
  126. Text title=new Text("Hello Fortune Teller");
  127. title.setFont(Font.font("SanSerif",36));
  128. Button button = new Button("Cetak");
  129. grid.add(button, 1,6);
  130.  
  131. button.setOnAction(this::buttonClick);
  132.  
  133. Group root = (Group)scene.getRoot();
  134. root.getChildren().add(grid);
  135. stage.setScene(scene);
  136. stage.show();
  137.  
  138.  
  139. }
  140.  
  141. private void buttonClick(ActionEvent event)
  142. {
  143. Print c = new Print(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  144. c.showPrint();
  145. }
  146.  
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment