Advertisement
forelyx

Untitled

Dec 11th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.28 KB | None | 0 0
  1. package FinalProject;
  2.  
  3. import static java.awt.event.KeyEvent.VK_BACK_SPACE;
  4. import java.util.Vector;
  5. import static javafx.beans.binding.Bindings.select;
  6. import javax.swing.table.DefaultTableModel;
  7. import java.sql.Connection;
  8. import java.util.Date;
  9.  
  10. public class Kasir extends javax.swing.JFrame {
  11.  
  12. /**
  13. * Creates new form Kasir
  14. */
  15. public Kasir() {
  16. initComponents();
  17. }
  18.  
  19. /**
  20. * This method is called from within the constructor to initialize the form.
  21. * WARNING: Do NOT modify this code. The content of this method is always
  22. * regenerated by the Form Editor.
  23. */
  24. @SuppressWarnings("unchecked")
  25. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  26. private void initComponents() {
  27.  
  28. jPanel1 = new javax.swing.JPanel();
  29. jLabel1 = new javax.swing.JLabel();
  30. jLabel2 = new javax.swing.JLabel();
  31. jLabel3 = new javax.swing.JLabel();
  32. jLabel4 = new javax.swing.JLabel();
  33. Nama = new javax.swing.JTextField();
  34. Harga = new javax.swing.JTextField();
  35. Qty = new javax.swing.JTextField();
  36. jButton1 = new javax.swing.JButton();
  37. jButton2 = new javax.swing.JButton();
  38. jScrollPane1 = new javax.swing.JScrollPane();
  39. jTable1 = new javax.swing.JTable();
  40. jLabel5 = new javax.swing.JLabel();
  41. jLabel6 = new javax.swing.JLabel();
  42. Totalharga = new javax.swing.JLabel();
  43. Kembalian = new javax.swing.JLabel();
  44. Baya = new javax.swing.JTextField();
  45. jButton3 = new javax.swing.JButton();
  46. Pesan = new javax.swing.JLabel();
  47. Jumlah = new javax.swing.JLabel();
  48. jButton4 = new javax.swing.JButton();
  49.  
  50. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  51. setTitle("Kasir");
  52. setAutoRequestFocus(false);
  53. setBackground(new java.awt.Color(204, 204, 255));
  54. setResizable(false);
  55.  
  56. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  57.  
  58. jLabel1.setFont(new java.awt.Font("Trajan Pro 3", 1, 18)); // NOI18N
  59. jLabel1.setForeground(new java.awt.Color(51, 0, 51));
  60. jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  61. jLabel1.setText("Cash Register");
  62.  
  63. jLabel2.setFont(new java.awt.Font("Sylfaen", 1, 18)); // NOI18N
  64. jLabel2.setForeground(new java.awt.Color(51, 0, 51));
  65. jLabel2.setText("Item :");
  66.  
  67. jLabel3.setFont(new java.awt.Font("Sylfaen", 1, 18)); // NOI18N
  68. jLabel3.setForeground(new java.awt.Color(51, 0, 51));
  69. jLabel3.setText("Quantity :");
  70.  
  71. jLabel4.setFont(new java.awt.Font("Sylfaen", 1, 18)); // NOI18N
  72. jLabel4.setForeground(new java.awt.Color(51, 0, 51));
  73. jLabel4.setText("Price :");
  74.  
  75. Nama.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  76. Nama.addActionListener(new java.awt.event.ActionListener() {
  77. public void actionPerformed(java.awt.event.ActionEvent evt) {
  78. NamaActionPerformed(evt);
  79. }
  80. });
  81.  
  82. Harga.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  83. Harga.addActionListener(new java.awt.event.ActionListener() {
  84. public void actionPerformed(java.awt.event.ActionEvent evt) {
  85. HargaActionPerformed(evt);
  86. }
  87. });
  88. Harga.addKeyListener(new java.awt.event.KeyAdapter() {
  89. public void keyPressed(java.awt.event.KeyEvent evt) {
  90. HargaKeyPressed(evt);
  91. }
  92. public void keyTyped(java.awt.event.KeyEvent evt) {
  93. HargaKeyTyped(evt);
  94. }
  95. });
  96.  
  97. Qty.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  98. Qty.addActionListener(new java.awt.event.ActionListener() {
  99. public void actionPerformed(java.awt.event.ActionEvent evt) {
  100. QtyActionPerformed(evt);
  101. }
  102. });
  103. Qty.addKeyListener(new java.awt.event.KeyAdapter() {
  104. public void keyPressed(java.awt.event.KeyEvent evt) {
  105. QtyKeyPressed(evt);
  106. }
  107. public void keyTyped(java.awt.event.KeyEvent evt) {
  108. QtyKeyTyped(evt);
  109. }
  110. });
  111.  
  112. jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  113. jButton1.setText("INSERT");
  114. jButton1.addActionListener(new java.awt.event.ActionListener() {
  115. public void actionPerformed(java.awt.event.ActionEvent evt) {
  116. jButton1ActionPerformed(evt);
  117. }
  118. });
  119.  
  120. jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  121. jButton2.setText("DELETE");
  122. jButton2.addActionListener(new java.awt.event.ActionListener() {
  123. public void actionPerformed(java.awt.event.ActionEvent evt) {
  124. jButton2ActionPerformed(evt);
  125. }
  126. });
  127.  
  128. jTable1.setBackground(new java.awt.Color(153, 255, 255));
  129. jTable1.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 0, 153), java.awt.Color.gray));
  130. jTable1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  131. jTable1.setForeground(new java.awt.Color(153, 153, 153));
  132. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  133. new Object [][] {
  134.  
  135. },
  136. new String [] {
  137. "Item", "Price", "Quantity", "Total"
  138. }
  139. ) {
  140. boolean[] canEdit = new boolean [] {
  141. false, false, false, false
  142. };
  143.  
  144. public boolean isCellEditable(int rowIndex, int columnIndex) {
  145. return canEdit [columnIndex];
  146. }
  147. });
  148. jTable1.setAutoscrolls(false);
  149. jTable1.setColumnSelectionAllowed(true);
  150. jTable1.setGridColor(new java.awt.Color(255, 255, 255));
  151. jTable1.setOpaque(false);
  152. jTable1.setRowHeight(20);
  153. jTable1.addInputMethodListener(new java.awt.event.InputMethodListener() {
  154. public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
  155. }
  156. public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
  157. jTable1InputMethodTextChanged(evt);
  158. }
  159. });
  160. jScrollPane1.setViewportView(jTable1);
  161. jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  162.  
  163. jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
  164. jLabel5.setForeground(new java.awt.Color(51, 0, 51));
  165. jLabel5.setText("Change :");
  166.  
  167. jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
  168. jLabel6.setForeground(new java.awt.Color(51, 0, 51));
  169. jLabel6.setText("Total :");
  170.  
  171. Totalharga.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
  172. Totalharga.setForeground(new java.awt.Color(51, 0, 51));
  173. Totalharga.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  174. Totalharga.setText("Rp.0");
  175.  
  176. Kembalian.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
  177. Kembalian.setForeground(new java.awt.Color(51, 0, 51));
  178. Kembalian.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  179. Kembalian.setText("Rp.0");
  180.  
  181. Baya.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  182. Baya.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
  183. Baya.addActionListener(new java.awt.event.ActionListener() {
  184. public void actionPerformed(java.awt.event.ActionEvent evt) {
  185. BayaActionPerformed(evt);
  186. }
  187. });
  188. Baya.addKeyListener(new java.awt.event.KeyAdapter() {
  189. public void keyPressed(java.awt.event.KeyEvent evt) {
  190. BayaKeyPressed(evt);
  191. }
  192. public void keyTyped(java.awt.event.KeyEvent evt) {
  193. BayaKeyTyped(evt);
  194. }
  195. });
  196.  
  197. jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  198. jButton3.setText("PAY");
  199. jButton3.addActionListener(new java.awt.event.ActionListener() {
  200. public void actionPerformed(java.awt.event.ActionEvent evt) {
  201. jButton3ActionPerformed(evt);
  202. }
  203. });
  204.  
  205. Pesan.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  206. Pesan.setForeground(new java.awt.Color(204, 0, 0));
  207. Pesan.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  208.  
  209. jButton4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  210. jButton4.setText("PRINT");
  211. jButton4.addActionListener(new java.awt.event.ActionListener() {
  212. public void actionPerformed(java.awt.event.ActionEvent evt) {
  213. jButton4ActionPerformed(evt);
  214. }
  215. });
  216.  
  217. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  218. jPanel1.setLayout(jPanel1Layout);
  219. jPanel1Layout.setHorizontalGroup(
  220. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  221. .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  222. .addGroup(jPanel1Layout.createSequentialGroup()
  223. .addGap(60, 60, 60)
  224. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  225. .addGroup(jPanel1Layout.createSequentialGroup()
  226. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  227. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
  228. .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
  229. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
  230. .addGap(27, 27, 27)
  231. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  232. .addComponent(Harga, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
  233. .addComponent(Qty, javax.swing.GroupLayout.Alignment.TRAILING)
  234. .addComponent(Nama))
  235. .addGap(16, 16, 16)
  236. .addComponent(Jumlah))
  237. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  238. .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 596, javax.swing.GroupLayout.PREFERRED_SIZE)
  239. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  240. .addGroup(jPanel1Layout.createSequentialGroup()
  241. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
  242. .addGap(27, 27, 27)
  243. .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  244. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
  245. .addGroup(jPanel1Layout.createSequentialGroup()
  246. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  247. .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
  248. .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
  249. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  250. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  251. .addComponent(Totalharga, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
  252. .addComponent(Kembalian, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
  253. .addGroup(jPanel1Layout.createSequentialGroup()
  254. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
  255. .addGap(24, 24, 24)
  256. .addComponent(Baya, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
  257. .addComponent(Pesan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  258. .addContainerGap(45, Short.MAX_VALUE))
  259. );
  260. jPanel1Layout.setVerticalGroup(
  261. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  262. .addGroup(jPanel1Layout.createSequentialGroup()
  263. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
  264. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  265. .addGroup(jPanel1Layout.createSequentialGroup()
  266. .addGap(4, 4, 4)
  267. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  268. .addComponent(Nama, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
  269. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
  270. .addGroup(jPanel1Layout.createSequentialGroup()
  271. .addGap(18, 18, 18)
  272. .addComponent(Jumlah)))
  273. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  274. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  275. .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
  276. .addComponent(Harga, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
  277. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  278. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  279. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
  280. .addComponent(Qty, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
  281. .addGap(42, 42, 42)
  282. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  283. .addComponent(jButton1)
  284. .addComponent(jButton2))
  285. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
  286. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
  287. .addGap(18, 18, 18)
  288. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  289. .addComponent(jButton3)
  290. .addComponent(Baya, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
  291. .addGap(23, 23, 23)
  292. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  293. .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  294. .addComponent(Totalharga))
  295. .addGap(26, 26, 26)
  296. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  297. .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  298. .addComponent(Kembalian))
  299. .addGap(15, 15, 15)
  300. .addComponent(Pesan, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
  301. .addGap(25, 25, 25)
  302. .addComponent(jButton4)
  303. .addContainerGap())
  304. );
  305.  
  306. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  307. getContentPane().setLayout(layout);
  308. layout.setHorizontalGroup(
  309. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  310. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  311. );
  312. layout.setVerticalGroup(
  313. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  314. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  315. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  316. .addGap(0, 0, Short.MAX_VALUE))
  317. );
  318.  
  319. setBounds(0, 0, 733, 784);
  320. }// </editor-fold>
  321.  
  322. private void NamaActionPerformed(java.awt.event.ActionEvent evt) {
  323. // TODO add your handling code here:
  324. }
  325.  
  326. private void HargaActionPerformed(java.awt.event.ActionEvent evt) {
  327. // TODO add your handling code here:
  328. }
  329.  
  330. private void QtyActionPerformed(java.awt.event.ActionEvent evt) {
  331. // TODO add your handling code here:
  332. }
  333.  
  334. private void BayaActionPerformed(java.awt.event.ActionEvent evt) {
  335. // TODO add your handling code here:
  336. }
  337.  
  338. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  339. // TODO add your handling code here:
  340. int g = Integer.parseInt(Totalharga.getText().substring(3));
  341. int f = Integer.parseInt(Baya.getText());
  342. int h = f - g;
  343. Kembalian.setText("Rp."+h);
  344. }
  345.  
  346. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  347. // TODO add your handling code here:
  348. Pesan.setText("");
  349. DefaultTableModel a = (DefaultTableModel) jTable1.getModel();
  350. if(Nama.getText().trim().equals("")){
  351. Pesan.setText("Sorry, the item name column must be filled");
  352. }else{
  353. int c = Integer.parseInt(Harga.getText());
  354. int b = Integer.parseInt(Qty.getText());
  355. int d = b * c;
  356. Jumlah.setText(""+d);
  357. Jumlah.setVisible(false);
  358. int t = 0;
  359. Vector z = new Vector();
  360. z.add(Nama.getText());
  361. z.add("Rp.".concat(Harga.getText()));
  362. z.add(Qty.getText());
  363. z.add("Rp.".concat(Jumlah.getText()));
  364. a.addRow(z);
  365. for(int e = 0; e <a.getRowCount(); e++){
  366. t += Integer.parseInt(a.getValueAt(e, 3).toString().substring(3));
  367. }
  368. Totalharga.setText("Rp."+t);
  369. Nama.setText("");
  370. Harga.setText("");
  371. Qty.setText("");
  372. }
  373. }
  374.  
  375. private void HargaKeyPressed(java.awt.event.KeyEvent evt) {
  376. // TODO add your handling code here:
  377.  
  378. }
  379.  
  380. private void QtyKeyPressed(java.awt.event.KeyEvent evt) {
  381. // TODO add your handling code here:
  382.  
  383. }
  384.  
  385. private void BayaKeyPressed(java.awt.event.KeyEvent evt) {
  386. // TODO add your handling code here:
  387.  
  388. }
  389.  
  390. private void HargaKeyTyped(java.awt.event.KeyEvent evt) {
  391. // TODO add your handling code here:
  392. Pesan.setText("");
  393. char a = evt.getKeyChar();
  394. int b = evt.getKeyCode() ;
  395. if(!Character.isDigit(a)){
  396. evt.consume();
  397. Pesan.setText("Sorry, you can only input using numbers");
  398. } else if (b == VK_BACK_SPACE) {
  399. evt.consume();
  400. Pesan.setText("Sorry, you can only input using numbers");
  401. }
  402. }
  403.  
  404. private void QtyKeyTyped(java.awt.event.KeyEvent evt) {
  405. // TODO add your handling code here:
  406. Pesan.setText("");
  407. char a = evt.getKeyChar();
  408. int b = evt.getKeyCode() ;
  409. if(!Character.isDigit(a)){
  410. evt.consume();
  411. Pesan.setText("Sorry, you can only input using numbers");
  412. } else if (b == VK_BACK_SPACE) {
  413. evt.consume();
  414. Pesan.setText("Sorry, you can only input using numbers");
  415. }
  416. }
  417.  
  418. private void BayaKeyTyped(java.awt.event.KeyEvent evt) {
  419. // TODO add your handling code here:
  420. Pesan.setText("");
  421. char a = evt.getKeyChar();
  422. int b = evt.getKeyCode() ;
  423. if(!Character.isDigit(a)){
  424. evt.consume();
  425. Pesan.setText("Sorry, you can only input using numbers");
  426. } else if (b == VK_BACK_SPACE) {
  427. evt.consume();
  428. Pesan.setText("Sorry, you can only input using numbers");
  429. }
  430. }
  431.  
  432. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  433. // TODO add your handling code here:
  434. DefaultTableModel a = (DefaultTableModel) jTable1.getModel();
  435. int select = jTable1.getSelectedRow();
  436. a.removeRow(select);
  437. Nama.setText("");
  438. Harga.setText("");
  439. Qty.setText("");
  440. int t= 0;
  441. for(int e = 0; e <a.getRowCount(); e++){
  442. t += Integer.parseInt(a.getValueAt(e, 3).toString().substring(3));
  443. }
  444. Totalharga.setText("Rp."+t);
  445. int g = Integer.parseInt(Totalharga.getText().substring(3));
  446. int f = Integer.parseInt(Baya.getText());
  447. int h = f - g;
  448. Kembalian.setText("Rp."+h);
  449. }
  450.  
  451. private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
  452. try{
  453. jTable1.print();
  454. }
  455. catch (Exception e) {
  456.  
  457. }
  458. }
  459.  
  460. private void jTable1InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
  461. // TODO add your handling code here:
  462. }
  463.  
  464. /**
  465. * @param args the command line arguments
  466. */
  467. public static void main(String args[]) {
  468. /* Set the Nimbus look and feel */
  469. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  470. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  471. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  472. */
  473. try {
  474. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  475. if ("Nimbus".equals(info.getName())) {
  476. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  477. break;
  478. }
  479. }
  480. } catch (ClassNotFoundException ex) {
  481. java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  482. } catch (InstantiationException ex) {
  483. java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  484. } catch (IllegalAccessException ex) {
  485. java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  486. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  487. java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  488. }
  489. //</editor-fold>
  490.  
  491. /* Create and display the form */
  492. java.awt.EventQueue.invokeLater(new Runnable() {
  493. public void run() {
  494. new Kasir().setVisible(true);
  495. }
  496. });
  497. }
  498.  
  499. // Variables declaration - do not modify
  500. private javax.swing.JTextField Baya;
  501. private javax.swing.JTextField Harga;
  502. private javax.swing.JLabel Jumlah;
  503. private javax.swing.JLabel Kembalian;
  504. private javax.swing.JTextField Nama;
  505. private javax.swing.JLabel Pesan;
  506. private javax.swing.JTextField Qty;
  507. private javax.swing.JLabel Totalharga;
  508. private javax.swing.JButton jButton1;
  509. private javax.swing.JButton jButton2;
  510. private javax.swing.JButton jButton3;
  511. private javax.swing.JButton jButton4;
  512. private javax.swing.JLabel jLabel1;
  513. private javax.swing.JLabel jLabel2;
  514. private javax.swing.JLabel jLabel3;
  515. private javax.swing.JLabel jLabel4;
  516. private javax.swing.JLabel jLabel5;
  517. private javax.swing.JLabel jLabel6;
  518. private javax.swing.JPanel jPanel1;
  519. private javax.swing.JScrollPane jScrollPane1;
  520. private javax.swing.JTable jTable1;
  521. // End of variables declaration
  522.  
  523. void isVisible(boolean b) {
  524. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  525. }
  526. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement