Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 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. import javafx.scene.image.Image;
  20. import javafx.scene.image.ImageView;
  21. import java.io.FileInputStream;
  22.  
  23. public class Pembelian extends Application
  24. {
  25. Text textDaftar = new Text("Daftar Penjualan");
  26. Text textKasir = new Text("User :");
  27. Text KodeBarang = new Text("");
  28. Text textHarga = new Text("");
  29. Text textJumlah = new Text("");
  30. Text textTotalBayar = new Text("");
  31. Text NamaBarang = new Text("");
  32. Text HargaBarang = new Text("");
  33. Text TotalHargaText = new Text("");
  34. TextField textFieldJumlah = new TextField ();
  35. ObservableList<String> optionsKasir = FXCollections.observableArrayList(
  36. "Natih",
  37. "Caca",
  38. "Catrine"
  39. );
  40. final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
  41. ObservableList<String> optionsBarang = FXCollections.observableArrayList(
  42. "101",
  43. "102",
  44. "103"
  45. );
  46. final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
  47.  
  48. private int TotalHarga;
  49. private int harga;
  50.  
  51. @Override
  52. public void start(Stage stage) throws Exception
  53. {
  54. Scene scene = new Scene(new Group(), 500, 250);
  55. stage.setTitle("PEMBELIAN BARANG TOKO CANAT");
  56. textDaftar.setFont(Font.font("SanSerif",18));
  57.  
  58. textKasir.setFont(Font.font("SanSerif",18));
  59. KodeBarang.setFont(Font.font("SanSerif",18));
  60. textHarga.setFont(Font.font("SanSerif",18));
  61. textJumlah.setFont(Font.font("SanSerif",18));
  62. textTotalBayar.setFont(Font.font("SanSerif",18));
  63.  
  64. GridPane grid = new GridPane();
  65. grid.setVgap(10);
  66. grid.setHgap(10);
  67. grid.setPadding(new Insets(10, 10, 10, 10));
  68.  
  69.  
  70. grid.add(new Label("Daftar Barang Jual: "), 0, 0);
  71. Button buttong = new Button("Click here!");
  72. grid.add(buttong, 1,0);
  73.  
  74. buttong.setOnAction(this::buttonClicks);
  75.  
  76. grid.add(new Label("User: "), 0, 1);
  77.  
  78. grid.add(comboBoxKasir, 1,1);
  79. grid.add(new Label("ID Barang: "), 0, 2);
  80. grid.add(comboBoxBarang, 1,2);
  81.  
  82. EventHandler<ActionEvent> event =
  83. new EventHandler<ActionEvent>() {
  84. public void handle(ActionEvent e)
  85. {
  86. if(comboBoxBarang.getValue() == "101")
  87. {
  88. NamaBarang.setText("Pulpen Kokoro");
  89. HargaBarang.setText("Rp2000");
  90. harga = 2000;
  91. }
  92. else if(comboBoxBarang.getValue() == "102")
  93. {
  94. NamaBarang.setText("Pulpen Pilot");
  95. HargaBarang.setText("Rp2000");
  96. harga = 2000;
  97. }
  98. else if(comboBoxBarang.getValue() == "103")
  99. {
  100. NamaBarang.setText("Buku Sidu");
  101. HargaBarang.setText("Rp3000");
  102. harga = 3000;
  103. }
  104.  
  105. }
  106. };
  107.  
  108.  
  109. comboBoxBarang.setOnAction(event);
  110.  
  111. grid.add(new Label("Keterangan Barang: "), 0, 3);
  112. grid.add(NamaBarang, 1,3);
  113. grid.add(new Label("Harga Barang: "), 0, 4);
  114. grid.add(HargaBarang, 1,4);
  115. grid.add(new Label("Jumlah Barang: "), 0, 5);
  116.  
  117. grid.add(textFieldJumlah, 1,5);
  118.  
  119. EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>() {
  120. public void handle(ActionEvent e)
  121. {
  122. TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * harga;
  123. TotalHargaText.setText("Rp"+Integer.toString(TotalHarga));
  124. }
  125. };
  126.  
  127. textFieldJumlah.setOnAction(eventJumlah);
  128.  
  129. grid.add(new Label("Total Bayar: "), 0, 6);
  130. grid.add(TotalHargaText, 1,6);
  131.  
  132. Text title=new Text("Hello Canat Teller");
  133. title.setFont(Font.font("SanSerif",36));
  134. Button buttons = new Button("Print Nota");
  135. grid.add(buttons, 1,7);
  136. buttons.setOnAction(this::buttonClick);
  137.  
  138. Group root = (Group)scene.getRoot();
  139. root.getChildren().add(grid);
  140. stage.setScene(scene);
  141. stage.show();
  142.  
  143. buttong.setOnAction(new EventHandler<ActionEvent>() {
  144. @Override public void handle(ActionEvent ee){
  145. PENJUALAN p = new PENJUALAN();
  146. p.setVisible(true);
  147. }
  148. });
  149.  
  150. }
  151.  
  152. public static void main(String[] args) {
  153. Application.launch(args);
  154. }
  155.  
  156. private void buttonClicks(ActionEvent ee)
  157. {
  158. PENJUALAN p = new PENJUALAN();
  159. //p.Tampilan();
  160. }
  161. private void buttonClick(ActionEvent event)
  162. {
  163. Cetak c = new Cetak(NamaBarang, textFieldJumlah.getText(), TotalHargaText);
  164. c.showCetak();
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement