Advertisement
Guest User

Source Code Cash Register Abdi Jordan

a guest
Dec 11th, 2019
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.15 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.collections.*;
  3. import javafx.scene.Scene;
  4. import javafx.scene.control.*;
  5. import javafx.scene.layout.*;
  6. import javafx.event.ActionEvent;
  7. import javafx.event.EventHandler;
  8. import javafx.scene.control.Label;
  9. import javafx.scene.layout.VBox;
  10. import javafx.scene.text.Font;
  11. import javafx.scene.text.Text;
  12. import javafx.scene.text.TextAlignment;
  13. import javafx.stage.Stage;
  14. import javafx.scene.Group;
  15. import javafx.geometry.Insets;
  16. import javafx.geometry.Pos;
  17. import javax.swing.*;
  18. import java.lang.Integer;
  19. import java.lang.Double;
  20. import java.lang.String;
  21.  
  22. import java.util.ArrayList;
  23. import java.io.PrintStream;
  24. import java.util.Scanner;
  25. import java.io.IOException;
  26. import java.io.File;
  27.  
  28. public class CashRegister extends Application
  29. {
  30. private int count = 0;
  31. private Label myLabel = new Label("0");
  32. private int lokasi = 0;
  33. private int discount = 0;
  34. private ArrayList<barang> product = new ArrayList<barang>();
  35. private ArrayList<barang> Keranjang = new ArrayList<barang>();
  36. private ArrayList<Integer> JumlahPembelian = new ArrayList<Integer>();
  37. private int Sum;
  38. private int Penghasilan = 0;
  39. private int lokasi2 = 0;
  40. private int lokasi3 = 0;
  41. @Override
  42. public void start(Stage stage)
  43. {
  44. inisialisasi();
  45. stage.setTitle("Cash Register");
  46.  
  47. Label labelNo = new Label("No.");
  48. Label labelNo2 = new Label("No.");
  49. Label labelNama = new Label("Nama");
  50. Label labelJumlah = new Label("Jumlah");
  51. Label labelJumlah2 = new Label("Jumlah");
  52. Label labelHarga = new Label("Harga");
  53. Label labelTotal = new Label("Total");
  54. Label labelDiscount = new Label("Diskon");
  55. Label labelDiscountOutput = new Label(Integer.toString(discount)+"%");
  56. Label labelTotalOutput = new Label();
  57.  
  58. Label productNo[] = new Label[4];
  59. Label productNama[] = new Label[4];
  60. Label productJumlah[] = new Label[4];
  61. Label productHarga[] = new Label[4];
  62. for(int i=0;i<4;i++){
  63. productNo[i] = new Label();
  64. productNama[i] = new Label();
  65. productJumlah[i] = new Label();
  66. productHarga[i] = new Label();
  67. }
  68.  
  69. TextField inputNo = new TextField();
  70. TextField inputJumlah = new TextField();
  71.  
  72. Button buttonEnter = new Button("Enter");
  73. /*
  74. Button button1 = new Button("1");
  75. Button button2 = new Button("2");
  76. Button button3 = new Button("3");
  77. Button button4 = new Button("4");
  78. Button button5 = new Button("5");
  79. Button button6 = new Button("6");
  80. Button button7 = new Button("7");
  81. Button button8 = new Button("8");
  82. Button button9 = new Button("9");
  83. Button button0 = new Button("0");
  84. Button button00 = new Button("00");
  85. Button buttonDot = new Button("1");*/
  86. //Button button7 = new Button("Receipt\nOn/Off"); //Receipt On/Off
  87. Button buttonCancel = new Button("Cancel"); //Error/Cancel
  88. Button buttonSettings = new Button("Settings"); //PLU
  89. //Button button10 = new Button("X/DATE-\nTIME"); //Multi or Date/Time
  90. Button buttonClear = new Button("Clear"); //Clear
  91. Button buttonDiscount = new Button("%-"); //Discount
  92. Button buttonStok = new Button("Open Stok"); //Coupon
  93. Button buttonUp = new Button("^"); //Button Up
  94. Button buttonDown = new Button("v"); //Button Down
  95. Button buttonOpenDrawer = new Button("Open Drawer"); //Open Drawer
  96. Button buttonSubTotal = new Button("Sub Total"); //Sub Total
  97. Button buttonPrint = new Button("Print"); //Print
  98. for(int i=0;i+lokasi<Keranjang.size();i++){
  99. productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
  100. productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
  101. productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
  102. productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
  103. }
  104. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  105. public void handle(ActionEvent e)
  106. {
  107. if(e.getSource()==buttonSettings){
  108. stage.close();
  109. settings();
  110. }
  111. else if(e.getSource()==buttonEnter){
  112. int pNo = Integer.parseInt(inputNo.getText());
  113. if(pNo<product.size()){
  114. int pHarga = Integer.parseInt(inputJumlah.getText());
  115. addkeranjang(pNo,pHarga);
  116. if(Keranjang.size()>4){
  117. lokasi++;
  118. }
  119. for(int i=0;i+lokasi<Keranjang.size();i++){
  120. productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
  121. productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
  122. productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
  123. productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
  124. }
  125. }
  126. }
  127. else if(e.getSource()==buttonCancel){
  128. while(Keranjang.size()>0){
  129. Keranjang.remove(0);
  130. JumlahPembelian.remove(0);
  131. }
  132. lokasi=0;
  133. for(int i=0;i<4;i++){
  134. productNo[i].setText(" ");
  135. productNama[i].setText(" ");
  136. productJumlah[i].setText(" ");
  137. productHarga[i].setText(" ");
  138. }
  139.  
  140. }
  141. else if(e.getSource()==buttonClear){
  142. if(Keranjang.size()>0){
  143. Keranjang.remove(Keranjang.size()-1);
  144. JumlahPembelian.remove(JumlahPembelian.size()-1);
  145. if(Keranjang.size()>4){
  146. lokasi--;
  147. }
  148. for(int i=0;i+lokasi<Keranjang.size();i++){
  149. productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
  150. productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
  151. productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
  152. productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
  153. }
  154. for(int i=Keranjang.size();i<4;i++){
  155. productNo[i].setText(" ");
  156. productNama[i].setText(" ");
  157. productJumlah[i].setText(" ");
  158. productHarga[i].setText(" ");
  159. }
  160. }
  161. }
  162. else if(e.getSource()==buttonDiscount){
  163. stage.close();
  164. addDiscount();
  165. }
  166. else if(e.getSource()==buttonStok){
  167. stage.close();
  168. Stok();
  169. }
  170. else if(e.getSource()==buttonUp){
  171. if(lokasi>0){
  172. lokasi--;
  173. for(int i=0;i+lokasi<Keranjang.size();i++){
  174. productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
  175. productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
  176. productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
  177. productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
  178. }
  179. }
  180. }
  181. else if(e.getSource()==buttonDown){
  182. if((lokasi+4)<product.size()){
  183. lokasi++;
  184. for(int i=0;i+lokasi<Keranjang.size();i++){
  185. productNo[i].setText(Integer.toString(Keranjang.get(i+lokasi).getno_barang()));
  186. productNama[i].setText(Keranjang.get(i+lokasi).getnama_barang());
  187. productJumlah[i].setText(Integer.toString(JumlahPembelian.get(i+lokasi)));
  188. productHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi).getharga_barang()));
  189. }
  190. }
  191. }
  192. else if(e.getSource()==buttonSubTotal){
  193. Sum=0;
  194. for(int i=0;i<Keranjang.size();i++){
  195. Sum+=JumlahPembelian.get(i)*Keranjang.get(i).getharga_barang();
  196. }
  197. Sum=Sum*(100-discount)/100;
  198. labelTotal.setText(Integer.toString(Sum));
  199. }
  200. else if(e.getSource()==buttonPrint){
  201. Sum=0;
  202. for(int i=0;i<Keranjang.size();i++){
  203. Sum+=JumlahPembelian.get(i)*Keranjang.get(i).getharga_barang();
  204. }
  205. Sum=Sum*(100-discount)/100;
  206. Penghasilan += Sum;
  207. stage.close();
  208. Transaksi();
  209. while(Keranjang.size()>0){
  210. Keranjang.remove(0);
  211. JumlahPembelian.remove(0);
  212. }
  213. lokasi = 0 ;
  214. for(int i=0;i<4;i++){
  215. productNo[i].setText(" ");
  216. productNama[i].setText(" ");
  217. productJumlah[i].setText(" ");
  218. productHarga[i].setText(" ");
  219. }
  220. }
  221. else if(e.getSource()==buttonOpenDrawer){
  222. stage.close();
  223. Penghasilan();
  224. }
  225. }
  226. };
  227.  
  228. buttonSettings.setOnAction(event);
  229. buttonCancel.setOnAction(event);
  230. buttonEnter.setOnAction(event);
  231. buttonClear.setOnAction(event);
  232. buttonDiscount.setOnAction(event);
  233. buttonStok.setOnAction(event);
  234. buttonUp.setOnAction(event);
  235. buttonDown.setOnAction(event);
  236. buttonSubTotal.setOnAction(event);
  237. buttonPrint.setOnAction(event);
  238. buttonOpenDrawer.setOnAction(event);
  239.  
  240. GridPane grid = new GridPane();
  241. grid.setPadding(new Insets(10, 10, 10, 10));
  242. grid.setMinSize(300, 300);
  243. grid.setVgap(3);
  244. grid.setHgap(3);
  245.  
  246. grid.add(labelNo, 1, 0);
  247. grid.add(labelNama, 2, 0);
  248. grid.add(labelJumlah, 3, 0);
  249. grid.add(labelHarga, 4, 0);
  250.  
  251.  
  252. for(int i=0;i<4;i++){
  253. grid.add(productNo[i],1,i+1);
  254. grid.add(productNama[i],2,i+1);
  255. grid.add(productJumlah[i],3,i+1);
  256. grid.add(productHarga[i],4,i+1);
  257. }
  258.  
  259. grid.add(labelTotal, 3, 5);
  260. grid.add(labelTotalOutput,4,5);
  261. grid.add(labelDiscount,3,7);
  262. grid.add(labelDiscountOutput,4,7);
  263. grid.add(labelNo2,1,6);
  264. grid.add(inputNo,2,6);
  265. grid.add(labelJumlah2,3,6);
  266. grid.add(inputJumlah,4,6);
  267. grid.add(buttonEnter,5,6);
  268. buttonEnter.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  269. grid.add(buttonUp,0,1);
  270. buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  271. grid.add(buttonDown,0,4);
  272. buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  273. grid.add(buttonSettings,5,0);
  274. buttonSettings.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  275. grid.add(buttonClear,6,6);
  276. buttonClear.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  277. grid.add(buttonOpenDrawer,2,7);
  278. buttonOpenDrawer.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  279. grid.add(buttonDiscount,5,7);
  280. buttonDiscount.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  281. grid.add(buttonSubTotal,4,8);
  282. buttonSubTotal.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  283. grid.add(buttonCancel,2,9);
  284. buttonCancel.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  285. grid.add(buttonPrint,4,9);
  286. buttonPrint.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  287. grid.add(buttonStok,2,8);
  288. buttonStok.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  289.  
  290. Scene scene = new Scene(grid);
  291. stage.setScene(scene);
  292.  
  293. stage.show();
  294. }
  295.  
  296. private void buttonClick(ActionEvent event)
  297. {
  298. count = count + 1;
  299. myLabel.setText(Integer.toString(count));
  300. }
  301.  
  302. private void settings(){
  303. Stage stage = new Stage();
  304.  
  305.  
  306.  
  307. Button buttonNew = new Button("Tambah Produk");
  308. Button buttonRemove = new Button("Hapus Produk");
  309. Button buttonEdit = new Button("Edit Data Produk");
  310. Button buttonBack = new Button("Kembali ke Cash Register");
  311. Button buttonLoad = new Button("Mengambil Produk");
  312. Button buttonStore = new Button("Menyiman Data Produk");
  313.  
  314.  
  315. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  316. public void handle(ActionEvent e)
  317. {
  318.  
  319. if(e.getSource()==buttonBack){
  320. stage.close();
  321. start(new Stage());
  322. }else if(e.getSource()==buttonNew){
  323. stage.close();
  324. newProduct();
  325. }else if(e.getSource()==buttonRemove){
  326. stage.close();
  327. RemoveProduct();
  328. }else if(e.getSource()==buttonEdit){
  329. stage.close();
  330. editProduct();
  331. }else if(e.getSource()==buttonLoad){
  332. Load();
  333. }else if(e.getSource()==buttonStore){
  334. Store();
  335. }
  336. }
  337. };
  338. buttonBack.setOnAction(event);
  339. buttonNew.setOnAction(event);
  340. buttonRemove.setOnAction(event);
  341. buttonEdit.setOnAction(event);
  342. buttonLoad.setOnAction(event);
  343. buttonStore.setOnAction(event);
  344.  
  345. GridPane grid = new GridPane();
  346. grid.setPadding(new Insets(10, 10, 10, 10));
  347. grid.setMinSize(300, 300);
  348. grid.setVgap(3);
  349. grid.setHgap(3);
  350.  
  351. grid.add(buttonNew,2,0);
  352. buttonNew.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  353. grid.add(buttonRemove,2,1);
  354. buttonRemove.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  355. grid.add(buttonEdit,2,2);
  356. buttonEdit.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  357. grid.add(buttonLoad,2,3);
  358. buttonLoad.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  359. grid.add(buttonStore,2,4);
  360. buttonStore.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  361. grid.add(buttonBack,2,5);
  362. buttonBack.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  363.  
  364. Scene scene = new Scene(grid);
  365. stage.setScene(scene);
  366.  
  367. stage.show();
  368. }
  369. private void Stok(){
  370. Stage stage = new Stage();
  371. stage.setTitle("Data_Produk");
  372.  
  373. Label labelNo = new Label("No.");
  374. Label labelNama = new Label("Nama");
  375. Label labelHarga = new Label("Harga");
  376. Label labelTotal = new Label("Total");
  377. Button buttonUp = new Button("^"); //Button Up
  378. Button buttonDown = new Button("v");
  379. Label productNo[] = new Label[7];
  380. Label productNama[] = new Label[7];
  381.  
  382. Label productHarga[] = new Label[7];
  383. for(int i=0;i<7;i++){
  384. productNo[i] = new Label();
  385. productNama[i] = new Label();
  386. productHarga[i] = new Label();
  387. }
  388. lokasi2=0;
  389. for(int i=0;i+lokasi2<product.size()&&i<7;i++){
  390. productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
  391. productNama[i].setText(product.get(i+lokasi2).getnama_barang());
  392.  
  393. productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
  394. }
  395. Button buttonBack = new Button("Kembali");
  396.  
  397. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  398. public void handle(ActionEvent e)
  399. {
  400. if(e.getSource()==buttonBack){
  401. stage.close();
  402. start(new Stage());
  403. }else if(e.getSource()==buttonUp){
  404. if(lokasi2>0){
  405. lokasi2--;
  406. for(int i=0;i+lokasi2<product.size();i++){
  407. productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
  408. productNama[i].setText(product.get(i+lokasi2).getnama_barang());
  409. productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
  410. }
  411. }
  412. }
  413. else if(e.getSource()==buttonDown){
  414. if(lokasi2<product.size()-7){
  415. lokasi2++;
  416. for(int i=0;i+lokasi2<product.size();i++){
  417. productNo[i].setText(Integer.toString(product.get(i+lokasi2).getno_barang()));
  418. productNama[i].setText(product.get(i+lokasi2).getnama_barang());
  419. productHarga[i].setText(Integer.toString(product.get(i+lokasi2).getharga_barang()));
  420. }
  421. }
  422. }
  423. }
  424. };
  425.  
  426. buttonBack.setOnAction(event);
  427. buttonUp.setOnAction(event);
  428. buttonDown.setOnAction(event);
  429.  
  430. GridPane grid = new GridPane();
  431. grid.setPadding(new Insets(10, 10, 10, 10));
  432. grid.setMinSize(300, 300);
  433. grid.setVgap(3);
  434. grid.setHgap(3);
  435.  
  436. grid.add(buttonUp,0,1);
  437. buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  438. grid.add(buttonDown,0,4);
  439. buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  440. grid.add(buttonBack,0,9);
  441. grid.add(labelNo, 1, 0);
  442. grid.add(labelNama, 3, 0);
  443. grid.add(labelHarga, 5, 0);
  444.  
  445.  
  446. for(int i=0;i<7;i++){
  447. grid.add(productNo[i],1,i+1);
  448. grid.add(productNama[i],3,i+1);
  449. grid.add(productHarga[i],5,i+1);
  450. }
  451.  
  452. Scene scene = new Scene(grid);
  453. stage.setScene(scene);
  454.  
  455. stage.show();
  456. }
  457. private void Transaksi(){
  458. Stage stage = new Stage();
  459. stage.setTitle("Transaksi");
  460.  
  461. Label labelDiscountOutput = new Label(Integer.toString(discount)+"%");
  462. Label labelDiscount = new Label("Diskon");
  463. Label labelNo = new Label("No.");
  464. Label labelNama = new Label("Nama");
  465. Label labelHarga = new Label("Harga");
  466. Label labelTotal = new Label("Total");
  467. Label labelTotal2 = new Label();
  468. Label labelJumlah = new Label("Jumlah");
  469. Label labelJumlahHarga = new Label("Total");
  470. Label KeranjangNo[] = new Label[7];
  471. Label KeranjangNama[] = new Label[7];
  472. Label KeranjangHarga[] = new Label[7];
  473. Label KeranjangJumlah[] = new Label[7];
  474. Label KeranjangJumlahHarga[] = new Label [7];
  475. for(int i=0;i<7;i++){
  476. KeranjangNo[i] = new Label();
  477. KeranjangJumlah[i] = new Label();
  478. KeranjangNama[i] = new Label();
  479. KeranjangHarga[i] = new Label();
  480. KeranjangJumlahHarga[i] = new Label();
  481. }
  482. lokasi3=0;
  483. for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
  484. KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
  485. KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
  486. KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
  487. KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
  488. KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
  489. }
  490.  
  491. Button buttonUp = new Button("^"); //Button Up
  492. Button buttonDown = new Button("v");
  493. Button buttonBack = new Button("Kembali");
  494.  
  495. labelTotal2.setText(Integer.toString(Sum));
  496.  
  497. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  498. public void handle(ActionEvent e)
  499. {
  500. if(e.getSource()==buttonBack){
  501. stage.close();
  502. start(new Stage());
  503. }else if(e.getSource()==buttonUp){
  504. if(lokasi3>0){
  505. lokasi3--;
  506. for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
  507. KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
  508. KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
  509. KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
  510. KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
  511. KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
  512. }
  513. }
  514. }
  515. else if(e.getSource()==buttonDown){
  516. if(lokasi3<product.size()-7){
  517. lokasi3++;
  518. for(int i=0;i+lokasi3<Keranjang.size()&&i<7;i++){
  519. KeranjangNo[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getno_barang()));
  520. KeranjangNama[i].setText(Keranjang.get(i+lokasi3).getnama_barang());
  521. KeranjangHarga[i].setText(Integer.toString(Keranjang.get(i+lokasi3).getharga_barang()));
  522. KeranjangJumlah[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3))));
  523. KeranjangJumlahHarga[i].setText((Integer.toString(JumlahPembelian.get(i+lokasi3)*Keranjang.get(i+lokasi3).getharga_barang())));
  524. }
  525. }
  526. }
  527. }
  528. };
  529.  
  530. buttonBack.setOnAction(event);
  531. buttonUp.setOnAction(event);
  532. buttonDown.setOnAction(event);
  533.  
  534. GridPane grid = new GridPane();
  535. grid.setPadding(new Insets(10, 10, 10, 10));
  536. grid.setMinSize(300, 300);
  537. grid.setVgap(3);
  538. grid.setHgap(3);
  539.  
  540. grid.add(buttonUp,0,1);
  541. buttonUp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  542. grid.add(buttonDown,0,4);
  543. buttonDown.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  544. grid.add(buttonBack,0,9);
  545. grid.add(labelTotal,4,9);
  546. grid.add(labelTotal2,5,9);
  547. grid.add(labelDiscount,2,9);
  548. grid.add(labelDiscountOutput,3,9);
  549. grid.add(labelNo, 1, 0);
  550. grid.add(labelNama, 2, 0);
  551. grid.add(labelHarga, 3, 0);
  552. grid.add(labelJumlah, 4, 0);
  553. grid.add(labelJumlahHarga, 5, 0);
  554.  
  555. for(int i=0;i<7;i++){
  556. grid.add(KeranjangNo[i],1,i+1);
  557. grid.add(KeranjangNama[i],2,i+1);
  558. grid.add(KeranjangHarga[i],3,i+1);
  559. grid.add(KeranjangJumlah[i],4,i+1);
  560. grid.add(KeranjangJumlahHarga[i],5,i+1);
  561. }
  562.  
  563. Scene scene = new Scene(grid);
  564. stage.setScene(scene);
  565.  
  566. stage.show();
  567. }
  568. //------------------------------------------------------------------------------------------
  569. private void newProduct(){
  570. Stage stage = new Stage();
  571. stage.setTitle("Tambah Produk");
  572.  
  573. Label labelNama = new Label("Nama Produk: ");
  574. Label labelHarga = new Label("Harga Produk: ");
  575.  
  576. TextField inputNama = new TextField();
  577. TextField inputHarga = new TextField();
  578.  
  579. Button buttonBack = new Button("Kembali");
  580. Button buttonSave = new Button("Simpan");
  581.  
  582. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  583. public void handle(ActionEvent e)
  584. {
  585. if(e.getSource()==buttonBack){
  586. stage.close();
  587. settings();
  588. }
  589. if(e.getSource()==buttonSave){
  590. int pNo = product.size()+1;
  591. String pNama = inputNama.getText();
  592. int pHarga = Integer.parseInt(inputHarga.getText());
  593.  
  594. addslot(pHarga,pNama);
  595.  
  596. stage.close();
  597. settings();
  598. }
  599. }
  600. };
  601.  
  602. buttonBack.setOnAction(event);
  603. buttonSave.setOnAction(event);
  604.  
  605. GridPane grid = new GridPane();
  606. grid.setPadding(new Insets(10, 10, 10, 10));
  607. grid.setMinSize(300, 300);
  608. grid.setVgap(3);
  609. grid.setHgap(3);
  610.  
  611. grid.add(labelNama,0,1);
  612. grid.add(labelHarga,0,2);
  613. grid.add(inputNama,1,1);
  614. grid.add(inputHarga,1,2);
  615. grid.add(buttonBack,0,3);
  616. grid.add(buttonSave,1,3);
  617.  
  618. Scene scene = new Scene(grid);
  619. stage.setScene(scene);
  620.  
  621. stage.show();
  622. }
  623.  
  624. private void RemoveProduct(){
  625. Stage stage = new Stage();
  626. stage.setTitle("Menghapus Data Produk");
  627.  
  628. Label labelNo = new Label("No. Produk: ");
  629. Label labelNama = new Label("Nama Produk: ");
  630.  
  631. TextField inputNo = new TextField();
  632. TextField inputNama = new TextField();
  633.  
  634. Button buttonBack = new Button("Kembali");
  635. Button buttonDelete = new Button("Hapus");
  636.  
  637. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  638. public void handle(ActionEvent e)
  639. {
  640. if(e.getSource()==buttonBack){
  641. stage.close();
  642. settings();
  643. }
  644. if(e.getSource()==buttonDelete){
  645. if(Integer.parseInt(inputNo.getText()) > 0&& Integer.parseInt(inputNo.getText())<=product.size()){
  646.  
  647. barang Item = new barang();
  648.  
  649. product.remove(Integer.parseInt(inputNo.getText())-1);
  650. for(int i = Integer.parseInt(inputNo.getText())-1;i < product.size();i++){
  651. Item = product.get(i);
  652. Item.setno_barang(i+1);
  653. product.remove(i);
  654. product.add(i,Item);
  655. }
  656. stage.close();
  657. settings();
  658. }else{
  659. String pNama = inputNama.getText();
  660. for(int i=0;i<product.size();i++){
  661. if((pNama.equals(product.get(i).getnama_barang()))){
  662. barang Item = new barang();
  663. product.remove(Integer.parseInt(inputNo.getText())-1);
  664. for(int j = i;j < product.size();j++){
  665. Item = product.get(j);
  666. Item.setno_barang(j+1);
  667. product.remove(j);
  668. product.add(j,Item);
  669. }
  670. }
  671. }
  672. }
  673.  
  674. }
  675. }
  676. };
  677.  
  678. buttonBack.setOnAction(event);
  679. buttonDelete.setOnAction(event);
  680.  
  681. GridPane grid = new GridPane();
  682. grid.setPadding(new Insets(10, 10, 10, 10));
  683. grid.setMinSize(300, 300);
  684. grid.setVgap(3);
  685. grid.setHgap(3);
  686.  
  687. grid.add(labelNo,0,0);
  688. grid.add(labelNama,0,1);
  689. grid.add(inputNo,1,0);
  690. grid.add(inputNama,1,1);
  691. grid.add(buttonBack,0,3);
  692. grid.add(buttonDelete,1,3);
  693.  
  694. Scene scene = new Scene(grid);
  695. stage.setScene(scene);
  696.  
  697. stage.show();
  698. }
  699.  
  700. private void editProduct(){
  701. Stage stage = new Stage();
  702. stage.setTitle("Ubah Data Produk");
  703.  
  704. Label labelNo = new Label("No. Produk: ");
  705. Label labelNama = new Label("Nama Produk: ");
  706. Label labelHarga = new Label("Harga Produk: ");
  707.  
  708. TextField inputNo = new TextField();
  709. TextField inputNama = new TextField();
  710. TextField inputHarga = new TextField();
  711.  
  712. Button buttonBack = new Button("Kembali");
  713. Button buttonSave = new Button("Simpan");
  714.  
  715. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  716. public void handle(ActionEvent e)
  717. {
  718. if(e.getSource()==buttonBack){
  719. stage.close();
  720. settings();
  721. }
  722. if(e.getSource()==buttonSave){
  723. if(Integer.parseInt(inputNo.getText()) > 0&& Integer.parseInt(inputNo.getText())<=product.size()){
  724. String pNama = inputNama.getText();
  725. int pHarga = Integer.parseInt(inputHarga.getText());
  726. barang Item = new barang();
  727. Item.edit(Integer.parseInt(inputNo.getText()),pHarga,pNama);
  728. product.remove(Integer.parseInt(inputNo.getText())-1);
  729. product.add(Integer.parseInt(inputNo.getText())-1,Item);
  730. stage.close();
  731. settings();
  732. }
  733. }
  734. }
  735. };
  736.  
  737. buttonBack.setOnAction(event);
  738. buttonSave.setOnAction(event);
  739.  
  740. GridPane grid = new GridPane();
  741. grid.setPadding(new Insets(10, 10, 10, 10));
  742. grid.setMinSize(300, 300);
  743. grid.setVgap(3);
  744. grid.setHgap(3);
  745.  
  746. grid.add(labelNo,0,0);
  747. grid.add(labelNama,0,1);
  748. grid.add(labelHarga,0,2);
  749. grid.add(inputNo,1,0);
  750. grid.add(inputNama,1,1);
  751. grid.add(inputHarga,1,2);
  752. grid.add(buttonBack,0,3);
  753. grid.add(buttonSave,1,3);
  754.  
  755. Scene scene = new Scene(grid);
  756. stage.setScene(scene);
  757.  
  758. stage.show();
  759. }
  760.  
  761. private void addDiscount() {
  762. Stage stage = new Stage();
  763. stage.setTitle("Diskon");
  764.  
  765. Label labelDiscount = new Label("Diskon:");
  766. TextField inputDiscount = new TextField();
  767.  
  768. Button confirm = new Button("Confirm");
  769. Button cancel = new Button("Cancel");
  770.  
  771. GridPane grid = new GridPane();
  772. grid.setPadding(new Insets(10, 10, 10, 10));
  773. grid.setMinSize(300, 300);
  774. grid.setVgap(3);
  775. grid.setHgap(3);
  776.  
  777. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  778. public void handle(ActionEvent e)
  779. {
  780. if(e.getSource()==cancel){
  781. stage.close();
  782. start(new Stage());
  783. }
  784. else if(e.getSource()==confirm){
  785. int dc = Integer.parseInt(inputDiscount.getText());
  786. if(dc>100)
  787. dc = 100;
  788. discount = dc;
  789. stage.close();
  790. start(new Stage());
  791. }
  792. }
  793. };
  794.  
  795. confirm.setOnAction(event);
  796. cancel.setOnAction(event);
  797.  
  798. grid.add(labelDiscount,0,0);
  799. grid.add(inputDiscount,1,0);
  800. grid.add(cancel,0,1);
  801. grid.add(confirm,1,1);
  802.  
  803. Scene scene = new Scene(grid);
  804. stage.setScene(scene);
  805.  
  806. stage.show();
  807. }
  808. private void Penghasilan() {
  809. Stage stage = new Stage();
  810. stage.setTitle("Penghasilan");
  811.  
  812. Label pengusaha = new Label("Penghasilan:");
  813. Label hasilusaha = new Label();
  814. hasilusaha.setText(Integer.toString(Penghasilan));
  815. Button usaha = new Button("OK");
  816.  
  817. GridPane grid = new GridPane();
  818. grid.setPadding(new Insets(10, 10, 10, 10));
  819. grid.setMinSize(300, 300);
  820. grid.setVgap(3);
  821. grid.setHgap(3);
  822.  
  823. EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
  824. public void handle(ActionEvent e)
  825. {
  826. if(e.getSource()==usaha){
  827. stage.close();
  828. start(new Stage());
  829. }
  830. }
  831. };
  832.  
  833. usaha.setOnAction(event);
  834.  
  835. grid.add(pengusaha,0,0);
  836. grid.add(hasilusaha,2,0);
  837. grid.add(usaha,0,1);
  838.  
  839. Scene scene = new Scene(grid);
  840. stage.setScene(scene);
  841.  
  842. stage.show();
  843. }
  844. // menyimpan data ke dalam bentuk file
  845. void Store(){
  846. try
  847. { PrintStream writer = new PrintStream( new File("Data_produk.txt"));
  848. int Limit = product.size();
  849. for(int i = 0; i < Limit; i++)
  850. {
  851. writer.println(product.get(i).getAll());
  852. }
  853. writer.close();
  854. }
  855. catch(IOException e)
  856. {
  857. System.out.println("An error occured while trying to write to the file");
  858. }
  859. }
  860. // mengambil data dari file ke dalam program
  861. void Load(){
  862. try
  863. { Scanner Data = new Scanner( new File("Data_produk.txt") );
  864. while( Data.hasNextInt() )
  865. { Data.nextInt();
  866. addslot(Data.nextInt(),Data.next());
  867. }
  868. }
  869. catch(IOException e)
  870. {
  871. System.out.println("An error occured while trying to reading from the file");
  872. }
  873. }
  874. // to add item into the product
  875. void addslot(int harga_barang, String nama_barang){
  876. int i;
  877. for(i=0;i<product.size();i++){
  878. if((nama_barang.equals(product.get(i).getnama_barang()))){
  879. i=-1;
  880. break;
  881. }
  882. }
  883. if(i==product.size()){
  884. barang Item = new barang();
  885. Item.edit(product.size()+1,harga_barang,nama_barang);
  886. product.add(Item);
  887. }
  888. }
  889. void addkeranjang(int no_barang, int jumlah_barang){
  890. barang Item = new barang();
  891.  
  892. Item.edit(Keranjang.size()+1,product.get(no_barang-1).getharga_barang(),product.get(no_barang-1).getnama_barang());
  893. Keranjang.add(Item);
  894. JumlahPembelian.add(jumlah_barang);
  895. }
  896. void inisialisasi(){
  897. addslot(100,"jagung");
  898. addslot(700,"jamur");
  899. addslot(600,"kedelai");
  900. addslot(500,"tulang");
  901. addslot(200,"tomat");
  902. addslot(1040,"kaki");
  903. addslot(419,"ampela");
  904. addslot(200,"botol");
  905. }
  906. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement