Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.03 KB | None | 0 0
  1. package userview;
  2.  
  3.  
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.LinkedList;
  10. import javax.swing.Timer;
  11.  
  12. /**
  13. *
  14. * @author kamranali
  15. */
  16. public class Userview extends javax.swing.JFrame {
  17.  
  18. javax.swing.DefaultComboBoxModel<String> model;
  19.  
  20. /**
  21. * Creates new form userview
  22. */
  23. static int rowCount = 0;
  24. int row_count = 0;//For Row Count
  25. String for_item_check = "";
  26.  
  27. public Userview() {
  28.  
  29. ArrayList<String> l = new ArrayList<String>();
  30. String[] str = (String[]) l.toArray(new String[l.size()]);
  31. for (String temp : str) {
  32. System.out.println(temp);
  33. }
  34. initComponents();
  35. new items();
  36. showDate();
  37. showTime();
  38. }
  39.  
  40. void showDate() {
  41. Date d = new Date();
  42. SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
  43. date.setText(s.format(d));
  44. }
  45.  
  46. void showTime() {
  47. new Timer(0, new ActionListener() {
  48. @Override
  49. public void actionPerformed(ActionEvent e) {
  50. Date d = new Date();
  51. SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
  52. time.setText(s.format(d));
  53. }
  54. }).start();
  55. }
  56.  
  57. /**
  58. * This method is called from within the constructor to initialize the form.
  59. * WARNING: Do NOT modify this code. The content of this method is always
  60. * regenerated by the Form Editor.
  61. */
  62. @SuppressWarnings("unchecked")
  63. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  64. private void initComponents() {
  65.  
  66. jLabel3 = new javax.swing.JLabel();
  67. jPanel2 = new javax.swing.JPanel();
  68. jButton4 = new javax.swing.JButton();
  69. jLabel5 = new javax.swing.JLabel();
  70. time = new javax.swing.JLabel();
  71. date = new javax.swing.JLabel();
  72. jTabbedPane1 = new javax.swing.JTabbedPane();
  73. jPanel1 = new javax.swing.JPanel();
  74. jLabel1 = new javax.swing.JLabel();
  75. jTextField1 = new javax.swing.JTextField();
  76. jLabel2 = new javax.swing.JLabel();
  77. jScrollPane3 = new javax.swing.JScrollPane();
  78. item_table = new javax.swing.JTable();
  79. jButton1 = new javax.swing.JButton();
  80. calculatedPrice = new javax.swing.JTextField();
  81. itemChoice1 = new java.awt.Choice();
  82. itemChoice = new java.awt.List();
  83. jPanel3 = new javax.swing.JPanel();
  84. addItem = new javax.swing.JButton();
  85. itemName = new javax.swing.JTextField();
  86. itemPrice = new javax.swing.JTextField();
  87. itemAdded = new java.awt.List();
  88. priceAdded = new java.awt.List();
  89. jLabel4 = new javax.swing.JLabel();
  90. jLabel6 = new javax.swing.JLabel();
  91. jPanel4 = new javax.swing.JPanel();
  92. jScrollPane1 = new javax.swing.JScrollPane();
  93. jTable1 = new javax.swing.JTable();
  94.  
  95. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  96.  
  97. jButton4.setText("logoff");
  98. jButton4.addActionListener(new java.awt.event.ActionListener() {
  99. public void actionPerformed(java.awt.event.ActionEvent evt) {
  100. jButton4ActionPerformed(evt);
  101. }
  102. });
  103.  
  104. jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  105. jLabel5.setText("Fast Food Restuarant Billing System");
  106.  
  107. time.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  108. time.setForeground(new java.awt.Color(51, 0, 255));
  109. time.setText("Time");
  110.  
  111. date.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  112. date.setForeground(new java.awt.Color(51, 0, 255));
  113. date.setText("Date");
  114.  
  115. javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  116. jPanel2.setLayout(jPanel2Layout);
  117. jPanel2Layout.setHorizontalGroup(
  118. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  119. .addGroup(jPanel2Layout.createSequentialGroup()
  120. .addGap(46, 46, 46)
  121. .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
  122. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  123. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  124. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  125. .addComponent(jButton4)
  126. .addGap(19, 19, 19))
  127. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  128. .addComponent(time)
  129. .addGap(33, 33, 33)
  130. .addComponent(date)
  131. .addContainerGap())))
  132. );
  133. jPanel2Layout.setVerticalGroup(
  134. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  135. .addGroup(jPanel2Layout.createSequentialGroup()
  136. .addContainerGap()
  137. .addComponent(jButton4)
  138. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  139. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  140. .addComponent(time)
  141. .addComponent(date))
  142. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  143. .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  144. );
  145.  
  146. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
  147.  
  148. jLabel1.setText("Customer Name");
  149.  
  150. jTextField1.addActionListener(new java.awt.event.ActionListener() {
  151. public void actionPerformed(java.awt.event.ActionEvent evt) {
  152. jTextField1ActionPerformed(evt);
  153. }
  154. });
  155.  
  156. jLabel2.setText("Items");
  157.  
  158. item_table.setModel(new javax.swing.table.DefaultTableModel(
  159. new Object [][] {
  160. {null, null, null},
  161. {null, null, null},
  162. {null, null, null},
  163. {null, null, null},
  164. {null, null, null},
  165. {null, null, null},
  166. {null, null, null},
  167. {null, null, null},
  168. {null, null, null},
  169. {null, null, null},
  170. {null, null, null},
  171. {null, null, null}
  172. },
  173. new String [] {
  174. "Item", "Quantity", "Price"
  175. }
  176. ) {
  177. Class[] types = new Class [] {
  178. java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class
  179. };
  180.  
  181. public Class getColumnClass(int columnIndex) {
  182. return types [columnIndex];
  183. }
  184. });
  185. jScrollPane3.setViewportView(item_table);
  186.  
  187. jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  188. jButton1.setText("Calculate :");
  189. jButton1.addActionListener(new java.awt.event.ActionListener() {
  190. public void actionPerformed(java.awt.event.ActionEvent evt) {
  191. jButton1ActionPerformed(evt);
  192. }
  193. });
  194.  
  195. calculatedPrice.addActionListener(new java.awt.event.ActionListener() {
  196. public void actionPerformed(java.awt.event.ActionEvent evt) {
  197. calculatedPriceActionPerformed(evt);
  198. }
  199. });
  200.  
  201. itemChoice1.addMouseListener(new java.awt.event.MouseAdapter() {
  202. public void mouseClicked(java.awt.event.MouseEvent evt) {
  203. itemChoice1MouseClicked(evt);
  204. }
  205. });
  206.  
  207. itemChoice.addMouseListener(new java.awt.event.MouseAdapter() {
  208. public void mouseClicked(java.awt.event.MouseEvent evt) {
  209. itemChoiceMouseClicked(evt);
  210. }
  211. });
  212. itemChoice.addActionListener(new java.awt.event.ActionListener() {
  213. public void actionPerformed(java.awt.event.ActionEvent evt) {
  214. itemChoiceActionPerformed(evt);
  215. }
  216. });
  217.  
  218. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  219. jPanel1.setLayout(jPanel1Layout);
  220. jPanel1Layout.setHorizontalGroup(
  221. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  222. .addGroup(jPanel1Layout.createSequentialGroup()
  223. .addContainerGap()
  224. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  225. .addGroup(jPanel1Layout.createSequentialGroup()
  226. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  227. .addComponent(jLabel1)
  228. .addComponent(jLabel2))
  229. .addGap(18, 18, 18)
  230. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  231. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
  232. .addComponent(itemChoice1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  233. .addComponent(itemChoice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  234. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  235. .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
  236. .addContainerGap(30, Short.MAX_VALUE))
  237. .addGroup(jPanel1Layout.createSequentialGroup()
  238. .addGap(244, 244, 244)
  239. .addComponent(jButton1)
  240. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  241. .addComponent(calculatedPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
  242. .addGap(62, 62, 62))
  243. );
  244. jPanel1Layout.setVerticalGroup(
  245. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  246. .addGroup(jPanel1Layout.createSequentialGroup()
  247. .addContainerGap()
  248. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  249. .addComponent(jLabel1)
  250. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  251. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  252. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  253. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
  254. .addComponent(itemChoice1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  255. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  256. .addComponent(itemChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
  257. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  258. .addGroup(jPanel1Layout.createSequentialGroup()
  259. .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
  260. .addGap(18, 18, 18)
  261. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  262. .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
  263. .addComponent(calculatedPrice))
  264. .addContainerGap())
  265. );
  266.  
  267. jTabbedPane1.addTab("Bill", jPanel1);
  268.  
  269. jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
  270.  
  271. addItem.setText("Add Item");
  272. addItem.addActionListener(new java.awt.event.ActionListener() {
  273. public void actionPerformed(java.awt.event.ActionEvent evt) {
  274. addItemActionPerformed(evt);
  275. }
  276. });
  277.  
  278. itemName.addActionListener(new java.awt.event.ActionListener() {
  279. public void actionPerformed(java.awt.event.ActionEvent evt) {
  280. itemNameActionPerformed(evt);
  281. }
  282. });
  283.  
  284. itemAdded.addMouseListener(new java.awt.event.MouseAdapter() {
  285. public void mouseClicked(java.awt.event.MouseEvent evt) {
  286. itemAddedMouseClicked(evt);
  287. }
  288. });
  289. itemAdded.addActionListener(new java.awt.event.ActionListener() {
  290. public void actionPerformed(java.awt.event.ActionEvent evt) {
  291. itemAddedActionPerformed(evt);
  292. }
  293. });
  294.  
  295. priceAdded.addMouseListener(new java.awt.event.MouseAdapter() {
  296. public void mouseClicked(java.awt.event.MouseEvent evt) {
  297. priceAddedMouseClicked(evt);
  298. }
  299. });
  300.  
  301. jLabel4.setText("Item");
  302.  
  303. jLabel6.setText("Price");
  304.  
  305. javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  306. jPanel3.setLayout(jPanel3Layout);
  307. jPanel3Layout.setHorizontalGroup(
  308. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  309. .addGroup(jPanel3Layout.createSequentialGroup()
  310. .addComponent(itemAdded, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
  311. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  312. .addComponent(priceAdded, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE)
  313. .addGap(0, 71, Short.MAX_VALUE))
  314. .addGroup(jPanel3Layout.createSequentialGroup()
  315. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  316. .addGroup(jPanel3Layout.createSequentialGroup()
  317. .addGap(179, 179, 179)
  318. .addComponent(addItem, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
  319. .addGap(82, 82, 82)
  320. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  321. .addComponent(itemName)
  322. .addComponent(itemPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
  323. .addGroup(jPanel3Layout.createSequentialGroup()
  324. .addGap(110, 110, 110)
  325. .addComponent(jLabel4)
  326. .addGap(246, 246, 246)
  327. .addComponent(jLabel6)))
  328. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  329. );
  330. jPanel3Layout.setVerticalGroup(
  331. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  332. .addGroup(jPanel3Layout.createSequentialGroup()
  333. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  334. .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
  335. .addComponent(jLabel6))
  336. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  337. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  338. .addComponent(itemAdded, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
  339. .addComponent(priceAdded, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  340. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  341. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  342. .addGroup(jPanel3Layout.createSequentialGroup()
  343. .addComponent(itemName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  344. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  345. .addComponent(itemPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  346. .addComponent(addItem, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
  347. .addGap(0, 28, Short.MAX_VALUE))
  348. );
  349.  
  350. jTabbedPane1.addTab("Items", jPanel3);
  351.  
  352. jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
  353.  
  354. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  355. new Object [][] {
  356. {null, null, null},
  357. {null, null, null},
  358. {null, null, null},
  359. {null, null, null}
  360. },
  361. new String [] {
  362. "Date", "Total Items", "Total Price"
  363. }
  364. ));
  365. jScrollPane1.setViewportView(jTable1);
  366.  
  367. javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
  368. jPanel4.setLayout(jPanel4Layout);
  369. jPanel4Layout.setHorizontalGroup(
  370. jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  371. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 693, Short.MAX_VALUE)
  372. );
  373. jPanel4Layout.setVerticalGroup(
  374. jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  375. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
  376. );
  377.  
  378. jTabbedPane1.addTab("Sales", jPanel4);
  379.  
  380. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  381. getContentPane().setLayout(layout);
  382. layout.setHorizontalGroup(
  383. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  384. .addGroup(layout.createSequentialGroup()
  385. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  386. .addComponent(jLabel3)
  387. .addGap(160, 160, 160))
  388. .addGroup(layout.createSequentialGroup()
  389. .addContainerGap()
  390. .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  391. .addComponent(jTabbedPane1)
  392. );
  393. layout.setVerticalGroup(
  394. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  395. .addGroup(layout.createSequentialGroup()
  396. .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  397. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  398. .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)
  399. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  400. .addComponent(jLabel3)
  401. .addContainerGap())
  402. );
  403.  
  404. pack();
  405. }// </editor-fold>//GEN-END:initComponents
  406.  
  407. private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
  408. // TODO add your handling code here:
  409.  
  410. this.setVisible(false);
  411. loginview k = new loginview();
  412.  
  413. k.setVisible(true);
  414.  
  415. }//GEN-LAST:event_jButton4ActionPerformed
  416.  
  417. private void calculatedPriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculatedPriceActionPerformed
  418. // TODO add your handling code here:
  419.  
  420.  
  421. }//GEN-LAST:event_calculatedPriceActionPerformed
  422.  
  423. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  424.  
  425. int total = 0;
  426. int quantity = 0;
  427. int price = 0;
  428. String t ;
  429. //System.out.println(item_table.getValueAt(0, 2));
  430. for (int i = 0; i < row_count; i++) {
  431. //System.out.println(item_table.getValueAt(0, 2));
  432. // try{
  433. // quantity = item_table.getValueAt(i, 1);
  434.  
  435. quantity=Integer.parseInt(String.valueOf(item_table.getValueAt(i, 1)));
  436. price=Integer.parseInt(String.valueOf(item_table.getValueAt(i, 2)));
  437. // price = (int) item_table.getValueAt(i, 2);
  438.  
  439. total = total + (quantity * price);
  440. //t = Integer.toString(total);
  441. //System.out.println(total);
  442.  
  443. //// }catch(ClassCastException e){
  444. // System.out.println("Exception");
  445. // }
  446. }
  447. // calculatedPrice.setText(String.valueOf(total));
  448. //calculatedPrice.setText(t);
  449. //System.out.println(t);
  450. //calculatedPrice.setText(Integer.toString(total));
  451.  
  452. calculatedPrice.setText(Integer.toString(total));
  453.  
  454.  
  455.  
  456. }//GEN-LAST:event_jButton1ActionPerformed
  457.  
  458. private void addItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addItemActionPerformed
  459.  
  460. items.price.add(itemPrice.getText());//For Adding Items Price to Static Price List
  461. items.items.add(itemName.getText());//For Adding Items to Static items List
  462. itemChoice.addItem(itemName.getText()); //For Adding Item to Combo Box
  463. itemAdded.addItem(itemName.getText());//For Adding Item to Recently Added Items List
  464. priceAdded.addItem(itemPrice.getText());//For Adding Item to Recently Added Price Menu
  465. }//GEN-LAST:event_addItemActionPerformed
  466.  
  467. private void itemAddedMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemAddedMouseClicked
  468. // TODO add your handling code here:
  469. priceAdded.select(itemAdded.getSelectedIndex());
  470.  
  471. }//GEN-LAST:event_itemAddedMouseClicked
  472.  
  473. private void priceAddedMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_priceAddedMouseClicked
  474. // TODO add your handling code here:
  475. itemAdded.select(priceAdded.getSelectedIndex());
  476. }//GEN-LAST:event_priceAddedMouseClicked
  477.  
  478. private void itemChoice1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemChoice1MouseClicked
  479. // TODO add your handling code here:
  480.  
  481. // int index = itemChoice1.getSelectedIndex();
  482. // String itemName = items.items.get(index);
  483. // String itemPrice = items.price.get(index);
  484. // item_table.setValueAt(itemName, rowCount, 0);
  485. // item_table.setValueAt(itemPrice, rowCount, 2);
  486. // rowCount++;
  487.  
  488. }//GEN-LAST:event_itemChoice1MouseClicked
  489.  
  490. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
  491. // TODO add your handling code here:
  492. }//GEN-LAST:event_jTextField1ActionPerformed
  493.  
  494. private void itemChoiceMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemChoiceMouseClicked
  495. // TODO add your handling code here:
  496.  
  497. // int index = itemChoice1.getSelectedIndex();
  498. // String itemName = items.items.get(index);
  499. // String itemPrice = items.price.get(index);
  500. // item_table.setValueAt(itemName, rowCount, 0);
  501. // item_table.setValueAt(itemPrice, rowCount, 2);
  502. // rowCount++;
  503.  
  504.  
  505. }//GEN-LAST:event_itemChoiceMouseClicked
  506.  
  507. private void itemAddedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemAddedActionPerformed
  508. // TODO add your handling code here:
  509. }//GEN-LAST:event_itemAddedActionPerformed
  510.  
  511. private void itemChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemChoiceActionPerformed
  512.  
  513. int index = itemChoice.getSelectedIndex();
  514. /* String itemName = items.items.get(index);
  515. String itemPrice = items.price.get(index);
  516. item_table.setValueAt(itemName, rowCount, 0);
  517. item_table.setValueAt(itemPrice, rowCount, 2);
  518. rowCount++;
  519. row_count++;*/
  520. String current_item = (String)itemChoice.getSelectedItem();
  521. item_table.setValueAt(current_item,row_count,0);
  522.  
  523. if(row_count==0)
  524. {
  525. item_table.setValueAt(current_item, row_count,0);
  526. }
  527. else
  528. {
  529. item_table.setValueAt(current_item,row_count,0);
  530. }
  531. item_table.setValueAt(items.price.get(index), row_count, 2);
  532. // switch(current_item)
  533. // {
  534. // case "Burger":
  535. // item_table.setValueAt(60,row_count,2);
  536. // break;
  537. // case "Shawarma":
  538. // item_table.setValueAt(90,row_count,2);
  539. // break;
  540. // case "Pizza":
  541. // item_table.setValueAt(1000,row_count,2);
  542. // break;
  543. // case "Pratha Roll":
  544. // item_table.setValueAt(120,row_count,2);
  545. // break;
  546. // case "Biryani":
  547. // item_table.setValueAt(120,row_count,2);
  548. // break;
  549. // case "Milk Shake":
  550. // item_table.setValueAt(60,row_count,2);
  551. // break;
  552. // default :
  553. // break;
  554. // }
  555. //item_table.setValueAt(current_item,row_count,0);
  556. row_count++;
  557. }//GEN-LAST:event_itemChoiceActionPerformed
  558.  
  559. private void itemNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemNameActionPerformed
  560. // TODO add your handling code here:
  561. }//GEN-LAST:event_itemNameActionPerformed
  562.  
  563. /**
  564. * @param args the command line arguments
  565. */
  566. public static void main(String args[]) {
  567. /* Set the Nimbus look and feel */
  568. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  569. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  570. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  571. */
  572. try {
  573. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  574. if ("Nimbus".equals(info.getName())) {
  575. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  576. break;
  577. }
  578. }
  579. } catch (ClassNotFoundException ex) {
  580. java.util.logging.Logger.getLogger(userview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  581. } catch (InstantiationException ex) {
  582. java.util.logging.Logger.getLogger(userview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  583. } catch (IllegalAccessException ex) {
  584. java.util.logging.Logger.getLogger(userview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  585. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  586. java.util.logging.Logger.getLogger(userview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  587. }
  588. //</editor-fold>
  589.  
  590. /* Create and display the form */
  591. java.awt.EventQueue.invokeLater(new Runnable() {
  592. public void run() {
  593. new Userview().setVisible(true);
  594. }
  595. });
  596. }
  597.  
  598. // Variables declaration - do not modify//GEN-BEGIN:variables
  599. private javax.swing.JButton addItem;
  600. private javax.swing.JTextField calculatedPrice;
  601. private javax.swing.JLabel date;
  602. public static java.awt.List itemAdded;
  603. public static java.awt.List itemChoice;
  604. public static java.awt.Choice itemChoice1;
  605. private javax.swing.JTextField itemName;
  606. private javax.swing.JTextField itemPrice;
  607. public static javax.swing.JTable item_table;
  608. private javax.swing.JButton jButton1;
  609. private javax.swing.JButton jButton4;
  610. private javax.swing.JLabel jLabel1;
  611. private javax.swing.JLabel jLabel2;
  612. private javax.swing.JLabel jLabel3;
  613. private javax.swing.JLabel jLabel4;
  614. private javax.swing.JLabel jLabel5;
  615. private javax.swing.JLabel jLabel6;
  616. private javax.swing.JPanel jPanel1;
  617. private javax.swing.JPanel jPanel2;
  618. private javax.swing.JPanel jPanel3;
  619. private javax.swing.JPanel jPanel4;
  620. private javax.swing.JScrollPane jScrollPane1;
  621. private javax.swing.JScrollPane jScrollPane3;
  622. private javax.swing.JTabbedPane jTabbedPane1;
  623. private javax.swing.JTable jTable1;
  624. private javax.swing.JTextField jTextField1;
  625. public static java.awt.List priceAdded;
  626. private javax.swing.JLabel time;
  627. // End of variables declaration//GEN-END:variables
  628. }
  629. items class
  630.  
  631. package userview;
  632.  
  633. import java.util.ArrayList;
  634. import java.util.LinkedList;
  635.  
  636. /**
  637. *
  638. * @author kamranali
  639. */
  640. public class items {
  641. static ArrayList<String> items = new ArrayList<String>();
  642. static ArrayList<String> price = new ArrayList<String>();
  643. // int rowCount = 7;
  644. static int index = 0;
  645.  
  646.  
  647. public items()
  648. {
  649.  
  650. items.add("Burger");
  651. price.add("60");
  652. Userview.itemChoice.addItem("Burger");
  653. Userview.itemAdded.add("Burger");
  654. Userview.priceAdded.add("60");
  655. items.add("Shawarma");
  656. price.add("90");
  657. Userview.itemChoice.addItem("Shawarma");
  658. Userview.itemAdded.add("Shawarma");
  659. Userview.priceAdded.add("90");
  660. items.add("Pizza");
  661. price.add("1000");
  662. Userview.itemChoice.addItem("Pizza");
  663. Userview.itemAdded.add("Pizza");
  664. Userview.priceAdded.add("1000");
  665. items.add("Pratha Roll");
  666. price.add("120");
  667. Userview.itemChoice.addItem("Pratha Roll");
  668. Userview.itemAdded.add("Pratha Roll");
  669. Userview.priceAdded.add("120");
  670. items.add("Biryani");
  671. price.add("120");
  672. Userview.itemChoice.addItem("Biryani");
  673. Userview.itemAdded.add("Biryani");
  674. Userview.priceAdded.add("120");
  675. items.add("Milk Shake");
  676. price.add("60");
  677. Userview.itemChoice.addItem("Milk Shake");
  678. Userview.itemAdded.add("Milk Shake");
  679. Userview.priceAdded.add("60");
  680. Userview.itemChoice.addItem(items.get(index));
  681. index++;
  682.  
  683. }}
  684.  
  685.  
  686. /*
  687. * To change this license header, choose License Headers in Project Properties.
  688. * To change this template file, choose Tools | Templates
  689. * and open the template in the editor.
  690. */
  691. package userview;
  692.  
  693. /**
  694. *
  695. * @author kamranali
  696. */
  697.  
  698. import java.awt.event.KeyEvent;
  699. import javax.swing.JOptionPane;
  700.  
  701. public class loginview extends javax.swing.JFrame {
  702.  
  703. /**
  704. * Creates new form loginview
  705. */
  706. public loginview() {
  707. initComponents();
  708. }
  709.  
  710. /**
  711. * This method is called from within the constructor to initialize the form.
  712. * WARNING: Do NOT modify this code. The content of this method is always
  713. * regenerated by the Form Editor.
  714. */
  715. @SuppressWarnings("unchecked")
  716. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  717. private void initComponents() {
  718.  
  719. jPanel1 = new javax.swing.JPanel();
  720. jLabel2 = new javax.swing.JLabel();
  721. login_btn = new javax.swing.JButton();
  722. pass = new javax.swing.JPasswordField();
  723. jLabel1 = new javax.swing.JLabel();
  724. user = new javax.swing.JTextField();
  725. jLabel3 = new javax.swing.JLabel();
  726.  
  727. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  728.  
  729. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Login", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 24), new java.awt.Color(0, 0, 255))); // NOI18N
  730.  
  731. jLabel2.setText("Password");
  732.  
  733. login_btn.setText("Login");
  734. login_btn.setMnemonic(KeyEvent.VK_ENTER);
  735. login_btn.addActionListener(new java.awt.event.ActionListener() {
  736. public void actionPerformed(java.awt.event.ActionEvent evt) {
  737. login_btnActionPerformed(evt);
  738. }
  739. });
  740.  
  741. jLabel1.setText("Username");
  742.  
  743. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  744. jPanel1.setLayout(jPanel1Layout);
  745. jPanel1Layout.setHorizontalGroup(
  746. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  747. .addGroup(jPanel1Layout.createSequentialGroup()
  748. .addContainerGap()
  749. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  750. .addGroup(jPanel1Layout.createSequentialGroup()
  751. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  752. .addGroup(jPanel1Layout.createSequentialGroup()
  753. .addComponent(jLabel1)
  754. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  755. .addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
  756. .addGroup(jPanel1Layout.createSequentialGroup()
  757. .addComponent(jLabel2)
  758. .addGap(45, 45, 45)
  759. .addComponent(pass, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
  760. .addContainerGap())
  761. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  762. .addComponent(login_btn)
  763. .addGap(57, 57, 57))))
  764. );
  765. jPanel1Layout.setVerticalGroup(
  766. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  767. .addGroup(jPanel1Layout.createSequentialGroup()
  768. .addContainerGap()
  769. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  770. .addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  771. .addComponent(jLabel1))
  772. .addGap(31, 31, 31)
  773. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  774. .addComponent(pass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  775. .addComponent(jLabel2))
  776. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
  777. .addComponent(login_btn))
  778. );
  779.  
  780. jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project1/windows-10-user-account-login-icon.png"))); // NOI18N
  781.  
  782. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  783. getContentPane().setLayout(layout);
  784. layout.setHorizontalGroup(
  785. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  786. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  787. .addGap(39, 39, 39)
  788. .addComponent(jLabel3)
  789. .addGap(38, 38, 38)
  790. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  791. .addContainerGap(50, Short.MAX_VALUE))
  792. );
  793. layout.setVerticalGroup(
  794. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  795. .addGroup(layout.createSequentialGroup()
  796. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  797. .addGroup(layout.createSequentialGroup()
  798. .addGap(35, 35, 35)
  799. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  800. .addGroup(layout.createSequentialGroup()
  801. .addGap(59, 59, 59)
  802. .addComponent(jLabel3)))
  803. .addContainerGap(53, Short.MAX_VALUE))
  804. );
  805.  
  806. pack();
  807. }// </editor-fold>//GEN-END:initComponents
  808.  
  809.  
  810. private void login_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_login_btnActionPerformed
  811. // TODO add your handling code here:
  812.  
  813. singleton auth = new singleton();
  814.  
  815. if(auth.adminAuth.get(0).equalsIgnoreCase(user.getText())){
  816.  
  817. if(auth.adminAuth.get(1).equalsIgnoreCase(pass.getText())){
  818.  
  819. Userview view = new Userview();
  820.  
  821. view.setVisible(true);
  822.  
  823. this.setVisible(false);
  824.  
  825. }else{
  826.  
  827. JOptionPane.showMessageDialog(null," Inavalid Password ");
  828.  
  829. }
  830.  
  831.  
  832. }else{
  833.  
  834. JOptionPane.showMessageDialog(null," Invalid User ");
  835. }
  836.  
  837.  
  838.  
  839. }//GEN-LAST:event_login_btnActionPerformed
  840.  
  841. /**
  842. * @param args the command line arguments
  843. */
  844. public static void main(String args[]) {
  845. /* Set the Nimbus look and feel */
  846. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  847. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  848. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  849. */
  850. try {
  851. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  852. if ("Nimbus".equals(info.getName())) {
  853. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  854. break;
  855. }
  856. }
  857. } catch (ClassNotFoundException ex) {
  858. java.util.logging.Logger.getLogger(loginview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  859. } catch (InstantiationException ex) {
  860. java.util.logging.Logger.getLogger(loginview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  861. } catch (IllegalAccessException ex) {
  862. java.util.logging.Logger.getLogger(loginview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  863. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  864. java.util.logging.Logger.getLogger(loginview.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  865. }
  866. //</editor-fold>
  867.  
  868. /* Create and display the form */
  869. java.awt.EventQueue.invokeLater(new Runnable() {
  870. public void run() {
  871. new loginview().setVisible(true);
  872. }
  873. });
  874. }
  875.  
  876. // Variables declaration - do not modify//GEN-BEGIN:variables
  877. private javax.swing.JLabel jLabel1;
  878. private javax.swing.JLabel jLabel2;
  879. private javax.swing.JLabel jLabel3;
  880. private javax.swing.JPanel jPanel1;
  881. private javax.swing.JButton login_btn;
  882. private javax.swing.JPasswordField pass;
  883. private javax.swing.JTextField user;
  884. // End of variables declaration//GEN-END:variables
  885. }
  886. //singleton class
  887.  
  888. package userview;
  889.  
  890. /**
  891. *
  892. * @author kamranali
  893. */
  894.  
  895. import java.util.ArrayList;
  896.  
  897. public class singleton {
  898.  
  899. ArrayList<String> adminAuth = new ArrayList<String>();
  900.  
  901.  
  902. singleton(){
  903. adminAuth.add("admin");
  904. adminAuth.add("admin");
  905.  
  906. }
  907. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement