Advertisement
Guest User

Flloring

a guest
Oct 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.82 KB | None | 0 0
  1. package com.mitzen;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.ResultSetMetaData;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.text.DecimalFormat;
  10. import java.util.HashSet;
  11. import java.util.Set;
  12. import java.util.Vector;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import javax.swing.JOptionPane;
  16. import javax.swing.table.DefaultTableModel;
  17.  
  18. /**
  19. *
  20. * @author MitzenTA1
  21. */
  22. public class Flooring extends javax.swing.JFrame {
  23. //class level
  24. private DefaultTableModel stuModel;
  25. /**
  26. * Creates new form Flooring
  27. */
  28. public Flooring() {
  29. stuModel = new DefaultTableModel();
  30. initComponents();
  31.  
  32. }
  33.  
  34. /**
  35. * This method is called from within the constructor to initialize the form.
  36. * WARNING: Do NOT modify this code. The content of this method is always
  37. * regenerated by the Form Editor.
  38. */
  39. @SuppressWarnings("unchecked")
  40. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  41. private void initComponents() {
  42.  
  43. btnFlooring = new javax.swing.ButtonGroup();
  44. jPanel1 = new javax.swing.JPanel();
  45. jTabbedPane1 = new javax.swing.JTabbedPane();
  46. jPanel2 = new javax.swing.JPanel();
  47. jRadioButtonWood = new javax.swing.JRadioButton();
  48. jRadioButtonCarpet = new javax.swing.JRadioButton();
  49. jLabelCustomerName = new javax.swing.JLabel();
  50. txtCustomerAddress = new javax.swing.JTextField();
  51. jLabel7 = new javax.swing.JLabel();
  52. txtCustomerName = new javax.swing.JTextField();
  53. jLabelFloorPrice = new javax.swing.JLabel();
  54. btnAddDatabase = new javax.swing.JButton();
  55. txtFloorPrice = new javax.swing.JTextField();
  56. jPanel3 = new javax.swing.JPanel();
  57. jButtonDisplay = new javax.swing.JButton();
  58. jScrollPane1 = new javax.swing.JScrollPane();
  59. jTableCustomer = new javax.swing.JTable();
  60. jButtonExit = new javax.swing.JButton();
  61. jPanel4 = new javax.swing.JPanel();
  62. jLabel1 = new javax.swing.JLabel();
  63. txtLength = new javax.swing.JTextField();
  64. jButtonArea = new javax.swing.JButton();
  65. txtWidth = new javax.swing.JTextField();
  66. jLabel2 = new javax.swing.JLabel();
  67. jLabel3 = new javax.swing.JLabel();
  68. jLabel4 = new javax.swing.JLabel();
  69. txtTotalArea = new javax.swing.JTextField();
  70. txtTotalCost = new javax.swing.JTextField();
  71.  
  72. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  73.  
  74. btnFlooring.add(jRadioButtonWood);
  75. jRadioButtonWood.setText("Wood Flooring $20");
  76. jRadioButtonWood.addActionListener(new java.awt.event.ActionListener() {
  77. public void actionPerformed(java.awt.event.ActionEvent evt) {
  78. jRadioButtonWoodActionPerformed(evt);
  79. }
  80. });
  81.  
  82. btnFlooring.add(jRadioButtonCarpet);
  83. jRadioButtonCarpet.setText("Carpet Flooring $10");
  84. jRadioButtonCarpet.addActionListener(new java.awt.event.ActionListener() {
  85. public void actionPerformed(java.awt.event.ActionEvent evt) {
  86. jRadioButtonCarpetActionPerformed(evt);
  87. }
  88. });
  89.  
  90. jLabelCustomerName.setText("Customer Name");
  91. jLabelCustomerName.setToolTipText("");
  92.  
  93. jLabel7.setText("Customer Address");
  94.  
  95. jLabelFloorPrice.setText("Floor Type Price");
  96.  
  97. btnAddDatabase.setText("Add to Database");
  98. btnAddDatabase.addActionListener(new java.awt.event.ActionListener() {
  99. public void actionPerformed(java.awt.event.ActionEvent evt) {
  100. btnAddDatabaseActionPerformed(evt);
  101. }
  102. });
  103.  
  104. txtFloorPrice.setEditable(false);
  105. txtFloorPrice.addActionListener(new java.awt.event.ActionListener() {
  106. public void actionPerformed(java.awt.event.ActionEvent evt) {
  107. txtFloorPriceActionPerformed(evt);
  108. }
  109. });
  110.  
  111. javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  112. jPanel2.setLayout(jPanel2Layout);
  113. jPanel2Layout.setHorizontalGroup(
  114. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  115. .addGroup(jPanel2Layout.createSequentialGroup()
  116. .addGap(18, 18, 18)
  117. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  119. .addGap(30, 30, 30)
  120. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  121. .addComponent(jLabelCustomerName)
  122. .addComponent(jLabel7)
  123. .addComponent(btnAddDatabase))
  124. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  125. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  126. .addComponent(txtCustomerName)
  127. .addComponent(txtCustomerAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
  128. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  129. .addGroup(jPanel2Layout.createSequentialGroup()
  130. .addComponent(jRadioButtonWood)
  131. .addGap(133, 133, 133)
  132. .addComponent(jLabelFloorPrice)
  133. .addContainerGap(161, Short.MAX_VALUE))
  134. .addGroup(jPanel2Layout.createSequentialGroup()
  135. .addComponent(jRadioButtonCarpet)
  136. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  137. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  138. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  139. .addComponent(txtFloorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
  140. .addGap(19, 19, 19))
  141. );
  142. jPanel2Layout.setVerticalGroup(
  143. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  144. .addGroup(jPanel2Layout.createSequentialGroup()
  145. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146. .addGroup(jPanel2Layout.createSequentialGroup()
  147. .addGap(30, 30, 30)
  148. .addComponent(jRadioButtonWood))
  149. .addGroup(jPanel2Layout.createSequentialGroup()
  150. .addGap(41, 41, 41)
  151. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  152. .addComponent(jLabelFloorPrice)
  153. .addComponent(txtFloorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
  154. .addGap(13, 13, 13)
  155. .addComponent(jRadioButtonCarpet)
  156. .addGap(66, 66, 66)
  157. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  158. .addComponent(jLabelCustomerName)
  159. .addComponent(txtCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  160. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  161. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  162. .addComponent(jLabel7)
  163. .addComponent(txtCustomerAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  164. .addGap(37, 37, 37)
  165. .addComponent(btnAddDatabase)
  166. .addContainerGap(198, Short.MAX_VALUE))
  167. );
  168.  
  169. jTabbedPane1.addTab("Add", jPanel2);
  170.  
  171. jButtonDisplay.setText("Display");
  172. jButtonDisplay.addInputMethodListener(new java.awt.event.InputMethodListener() {
  173. public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
  174. }
  175. public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
  176. jButtonDisplayCaretPositionChanged(evt);
  177. }
  178. });
  179. jButtonDisplay.addActionListener(new java.awt.event.ActionListener() {
  180. public void actionPerformed(java.awt.event.ActionEvent evt) {
  181. jButtonDisplayActionPerformed(evt);
  182. }
  183. });
  184.  
  185. jTableCustomer.setModel(stuModel);
  186. jScrollPane1.setViewportView(jTableCustomer);
  187.  
  188. jButtonExit.setText("Exit");
  189. jButtonExit.addActionListener(new java.awt.event.ActionListener() {
  190. public void actionPerformed(java.awt.event.ActionEvent evt) {
  191. jButtonExitActionPerformed(evt);
  192. }
  193. });
  194.  
  195. javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  196. jPanel3.setLayout(jPanel3Layout);
  197. jPanel3Layout.setHorizontalGroup(
  198. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  199. .addGroup(jPanel3Layout.createSequentialGroup()
  200. .addComponent(jButtonDisplay)
  201. .addGap(0, 0, Short.MAX_VALUE))
  202. .addGroup(jPanel3Layout.createSequentialGroup()
  203. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE)
  204. .addContainerGap())
  205. .addGroup(jPanel3Layout.createSequentialGroup()
  206. .addContainerGap()
  207. .addComponent(jButtonExit)
  208. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  209. );
  210. jPanel3Layout.setVerticalGroup(
  211. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  212. .addGroup(jPanel3Layout.createSequentialGroup()
  213. .addComponent(jButtonDisplay)
  214. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  215. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
  216. .addGap(33, 33, 33)
  217. .addComponent(jButtonExit)
  218. .addGap(0, 181, Short.MAX_VALUE))
  219. );
  220.  
  221. jTabbedPane1.addTab("Display", jPanel3);
  222.  
  223. jLabel1.setText("Length");
  224.  
  225. jButtonArea.setText("Area of Floor");
  226. jButtonArea.addActionListener(new java.awt.event.ActionListener() {
  227. public void actionPerformed(java.awt.event.ActionEvent evt) {
  228. jButtonAreaActionPerformed(evt);
  229. }
  230. });
  231.  
  232. jLabel2.setText("TotalArea");
  233.  
  234. jLabel3.setText("Width");
  235.  
  236. jLabel4.setText("TotalCost");
  237.  
  238. txtTotalArea.setEditable(false);
  239. txtTotalArea.addActionListener(new java.awt.event.ActionListener() {
  240. public void actionPerformed(java.awt.event.ActionEvent evt) {
  241. txtTotalAreaActionPerformed(evt);
  242. }
  243. });
  244.  
  245. txtTotalCost.setEditable(false);
  246. txtTotalCost.addActionListener(new java.awt.event.ActionListener() {
  247. public void actionPerformed(java.awt.event.ActionEvent evt) {
  248. txtTotalCostActionPerformed(evt);
  249. }
  250. });
  251.  
  252. javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
  253. jPanel4.setLayout(jPanel4Layout);
  254. jPanel4Layout.setHorizontalGroup(
  255. jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  256. .addGroup(jPanel4Layout.createSequentialGroup()
  257. .addGap(50, 50, 50)
  258. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  259. .addGroup(jPanel4Layout.createSequentialGroup()
  260. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  261. .addComponent(jLabel2)
  262. .addComponent(jLabel4)
  263. .addComponent(jLabel3)
  264. .addComponent(jLabel1))
  265. .addGap(92, 92, 92)
  266. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  267. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  268. .addComponent(txtWidth, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
  269. .addComponent(txtLength, javax.swing.GroupLayout.Alignment.LEADING))
  270. .addComponent(txtTotalCost, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
  271. .addComponent(txtTotalArea)))
  272. .addGroup(jPanel4Layout.createSequentialGroup()
  273. .addGap(216, 216, 216)
  274. .addComponent(jButtonArea)))
  275. .addContainerGap(172, Short.MAX_VALUE))
  276. );
  277. jPanel4Layout.setVerticalGroup(
  278. jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  279. .addGroup(jPanel4Layout.createSequentialGroup()
  280. .addGap(59, 59, 59)
  281. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  282. .addComponent(jLabel1)
  283. .addComponent(txtLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  284. .addGap(30, 30, 30)
  285. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  286. .addGroup(jPanel4Layout.createSequentialGroup()
  287. .addComponent(jLabel3)
  288. .addGap(46, 46, 46)
  289. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  290. .addComponent(jLabel2)
  291. .addComponent(txtTotalArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  292. .addGap(19, 19, 19)
  293. .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  294. .addComponent(jLabel4)
  295. .addComponent(txtTotalCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  296. .addGap(27, 27, 27)
  297. .addComponent(jButtonArea))
  298. .addComponent(txtWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  299. .addContainerGap(193, Short.MAX_VALUE))
  300. );
  301.  
  302. jTabbedPane1.addTab("Area", jPanel4);
  303.  
  304. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  305. jPanel1.setLayout(jPanel1Layout);
  306. jPanel1Layout.setHorizontalGroup(
  307. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  308. .addGroup(jPanel1Layout.createSequentialGroup()
  309. .addContainerGap()
  310. .addComponent(jTabbedPane1)
  311. .addContainerGap())
  312. );
  313. jPanel1Layout.setVerticalGroup(
  314. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  315. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  316. .addContainerGap(38, Short.MAX_VALUE)
  317. .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE)
  318. .addContainerGap())
  319. );
  320.  
  321. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  322. getContentPane().setLayout(layout);
  323. layout.setHorizontalGroup(
  324. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  325. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  326. );
  327. layout.setVerticalGroup(
  328. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  329. .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  330. );
  331.  
  332. pack();
  333. }// </editor-fold>
  334.  
  335. private void jButtonDisplayCaretPositionChanged(java.awt.event.InputMethodEvent evt) {
  336. // TODO add your handling code here:
  337. }
  338.  
  339. private void jButtonDisplayActionPerformed(java.awt.event.ActionEvent evt) {
  340. // for display button
  341.  
  342. String login = "4021";
  343. String password = "Nokia2610!";
  344. String databaseName = "CIS355A_4021";
  345. Connection conn = null;
  346. Statement stmnt;
  347. ResultSet results;
  348.  
  349. try {
  350. //connection
  351. conn = DriverManager.getConnection("jdbc:mysql://devry.edupe.net:4300/"
  352. + databaseName,login, password);
  353. System.out.println("Connection to SQL Established");
  354. //retrive
  355. stmnt = conn.createStatement();
  356. results = stmnt.executeQuery("Select * FROM Flooring");
  357.  
  358. //columan names
  359. ResultSetMetaData md = results.getMetaData();
  360. int num = md.getColumnCount();
  361.  
  362. Vector<String> colNames = new Vector<String>();
  363. for ( int i = 1; i <= num; i++ )
  364. colNames.add(md.getColumnName(i));
  365. //assign
  366. stuModel.setColumnIdentifiers(colNames);
  367.  
  368. while( results.next())
  369. {
  370. //adding table as object array
  371. stuModel.addRow(new Object[] {results.getString("CustomerName"),
  372. results.getString("CustomerAddress"),
  373. results.getDouble("FlooringType"),results.getDouble("FlooringArea"),results.getDouble("FlooringCost")});
  374. }
  375. }
  376.  
  377.  
  378. catch (SQLException ex) {
  379. JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(),"Error Message", JOptionPane.ERROR_MESSAGE);
  380. }
  381.  
  382. }
  383.  
  384. private void txtTotalAreaActionPerformed(java.awt.event.ActionEvent evt) {
  385. // TODO add your handling code here:
  386. }
  387.  
  388. private void txtTotalCostActionPerformed(java.awt.event.ActionEvent evt) {
  389. // TODO add your handling code here:
  390. }
  391.  
  392. private void jButtonAreaActionPerformed(java.awt.event.ActionEvent evt) {
  393. // adds cost and area
  394.  
  395. double area = 0.00;
  396. double length = 0.00;
  397. double width = 0.00;
  398. double floorPrice;
  399. double totalCost = 0.00;
  400. length = Double.parseDouble(this.txtLength.getText());
  401. width = Double.parseDouble(this.txtWidth.getText());
  402. floorPrice = Double.parseDouble(txtFloorPrice.getText());
  403. area = length * width;
  404. totalCost = area * floorPrice;
  405. DecimalFormat fm = new DecimalFormat("0.00");
  406. txtTotalCost.setText(fm.format(totalCost));
  407. txtTotalArea.setText(fm.format(area));
  408. }
  409.  
  410. private void btnAddDatabaseActionPerformed(java.awt.event.ActionEvent evt) {
  411. //add to database
  412.  
  413. {
  414.  
  415.  
  416. Customers cust = new Customers();
  417. String name = txtCustomerName.getText();
  418. cust.setCustomerName(name);
  419. String address = txtCustomerAddress.getText();
  420. cust.setCustomerAddress(address);
  421. double floorType = Double.parseDouble (txtFloorPrice.getText());
  422. cust.setFlooringType(floorType);
  423. double flooringArea = Double.parseDouble (txtTotalArea.getText());
  424. cust.setFlooringArea(flooringArea);
  425. double flooringCost = Double.parseDouble(txtTotalCost.getText());
  426. cust.setFlooringCost(flooringCost);
  427.  
  428.  
  429.  
  430. CustomerDB dataIO = new CustomerDB();
  431.  
  432. try
  433. {
  434. dataIO.add(cust);
  435. JOptionPane.showMessageDialog(this, cust.getCustomerName() + " was added to the database");
  436. // output telling what was added
  437.  
  438. }
  439. catch(SQLException | ClassNotFoundException ex)
  440. {
  441.  
  442. JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(),
  443. "Database Error", JOptionPane.ERROR_MESSAGE);
  444. }
  445. }
  446.  
  447.  
  448.  
  449.  
  450. }
  451.  
  452. private void jRadioButtonCarpetActionPerformed(java.awt.event.ActionEvent evt) {
  453. //carpet button
  454. updatePrice();
  455. }
  456.  
  457. private void jRadioButtonWoodActionPerformed(java.awt.event.ActionEvent evt) {
  458. // wood button
  459. updatePrice();
  460. }
  461.  
  462. private void txtFloorPriceActionPerformed(java.awt.event.ActionEvent evt) {
  463. // TODO add your handling code here:
  464. }
  465.  
  466. private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt) {
  467. // Exits
  468. System.exit(0);
  469. }
  470.  
  471. /**
  472. * @param args the command line arguments
  473. */
  474. public static void main(String args[]) {
  475. /* Set the Nimbus look and feel */
  476. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  477. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  478. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  479. */
  480. try {
  481. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  482. if ("Nimbus".equals(info.getName())) {
  483. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  484. break;
  485. }
  486. }
  487. } catch (ClassNotFoundException ex) {
  488. java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  489. } catch (InstantiationException ex) {
  490. java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  491. } catch (IllegalAccessException ex) {
  492. java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  493. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  494. java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  495. }
  496. //</editor-fold>
  497.  
  498. /* Create and display the form */
  499. java.awt.EventQueue.invokeLater(() -> {
  500. new Flooring().setVisible(true);
  501. });
  502. }
  503.  
  504. // Variables declaration - do not modify
  505. private javax.swing.JButton btnAddDatabase;
  506. private javax.swing.ButtonGroup btnFlooring;
  507. private javax.swing.JButton jButtonArea;
  508. private javax.swing.JButton jButtonDisplay;
  509. private javax.swing.JButton jButtonExit;
  510. private javax.swing.JLabel jLabel1;
  511. private javax.swing.JLabel jLabel2;
  512. private javax.swing.JLabel jLabel3;
  513. private javax.swing.JLabel jLabel4;
  514. private javax.swing.JLabel jLabel7;
  515. private javax.swing.JLabel jLabelCustomerName;
  516. private javax.swing.JLabel jLabelFloorPrice;
  517. private javax.swing.JPanel jPanel1;
  518. private javax.swing.JPanel jPanel2;
  519. private javax.swing.JPanel jPanel3;
  520. private javax.swing.JPanel jPanel4;
  521. private javax.swing.JRadioButton jRadioButtonCarpet;
  522. private javax.swing.JRadioButton jRadioButtonWood;
  523. private javax.swing.JScrollPane jScrollPane1;
  524. private javax.swing.JTabbedPane jTabbedPane1;
  525. private javax.swing.JTable jTableCustomer;
  526. private javax.swing.JTextField txtCustomerAddress;
  527. private javax.swing.JTextField txtCustomerName;
  528. private javax.swing.JTextField txtFloorPrice;
  529. private javax.swing.JTextField txtLength;
  530. private javax.swing.JTextField txtTotalArea;
  531. private javax.swing.JTextField txtTotalCost;
  532. private javax.swing.JTextField txtWidth;
  533. // End of variables declaration
  534.  
  535. private void updatePrice() {
  536. //update the price of the floor type
  537. double floorPrice;
  538.  
  539. if( !jRadioButtonWood.isSelected() && !jRadioButtonCarpet.isSelected())
  540. {
  541. JOptionPane.showMessageDialog(this, "Error, must select either Wood or Carpet");
  542. return;
  543. }
  544. if(jRadioButtonWood.isSelected())
  545.  
  546. floorPrice = 20.00;
  547.  
  548.  
  549. else
  550. floorPrice = 10.00;
  551. DecimalFormat fm = new DecimalFormat("0.00");
  552. txtFloorPrice.setText(fm.format(floorPrice));
  553.  
  554.  
  555.  
  556.  
  557. }
  558. }
  559. package com.mitzen;
  560.  
  561. /**
  562. *
  563. * @author tim
  564. */
  565. public class Customers {
  566.  
  567. private String customerName;
  568. private String customerAddress;
  569. private double flooringType;
  570. private double flooringArea;
  571. private double flooringCost;
  572.  
  573. public Customers()
  574.  
  575. {
  576. customerName = "unknown";
  577. customerAddress = "unknown";
  578. flooringType = 0.00;
  579. flooringArea = 0.00;
  580. flooringCost = 0.00;
  581.  
  582.  
  583. }
  584.  
  585. public Customers(String customerName, String customerAddress, double flooringType, double flooringArea, double flooringCost) {
  586. this.customerName = customerName;
  587. this.customerAddress = customerAddress;
  588. this.flooringType = flooringType;
  589. this.flooringArea = flooringArea;
  590. this.flooringCost = flooringCost;
  591. }
  592.  
  593.  
  594.  
  595. public String getCustomerName() {
  596. return customerName;
  597. }
  598.  
  599. public void setCustomerName(String customerName) {
  600. this.customerName = customerName;
  601. }
  602.  
  603. public String getCustomerAddress() {
  604. return customerAddress;
  605. }
  606.  
  607. public void setCustomerAddress(String customerAddress) {
  608. this.customerAddress = customerAddress;
  609. }
  610.  
  611. public double getFlooringType() {
  612. return flooringType;
  613. }
  614.  
  615. public void setFlooringType(Double flooringType) {
  616. this.flooringType = flooringType;
  617. }
  618.  
  619. public double getFlooringArea() {
  620. return flooringArea;
  621. }
  622.  
  623. public void setFlooringArea(Double flooringArea) {
  624. this.flooringArea = flooringArea;
  625. }
  626.  
  627. public double getFlooringCost() {
  628. return flooringCost;
  629. }
  630.  
  631. public void setFlooringCost(Double flooringCost) {
  632. this.flooringCost = flooringCost;
  633. }
  634.  
  635. @Override
  636. public String toString() {
  637. return "Customers{" + "customerName=" + customerName + ", customerAddress=" + customerAddress + ", flooringType=" + flooringType + '}';
  638. }
  639.  
  640.  
  641. }
  642. package com.mitzen;
  643.  
  644. import java.sql.Connection;
  645. import java.sql.DriverManager;
  646. import java.sql.PreparedStatement;
  647. import java.sql.ResultSet;
  648. import java.sql.SQLException;
  649.  
  650. /**
  651. *
  652. * @author tim
  653. */
  654. public class CustomerDB {
  655. public void add(Customers cust) throws ClassNotFoundException, SQLException//writes a record to the database
  656. {
  657. PreparedStatement pstmt = null;//creates references
  658. ResultSet rs = null;
  659.  
  660.  
  661.  
  662. Class.forName("com.mysql.cj.jdbc.Driver");
  663. System.out.println("Connected to driver");
  664.  
  665.  
  666. //connection
  667. Connection conn = null;
  668. String login = "4021";
  669. String password = "Nokia2610!";
  670. String databaseName = "CIS355A_4021";
  671. conn = DriverManager.getConnection("jdbc:mysql://devry.edupe.net:4300/"
  672. + databaseName,login, password);
  673. System.out.println("Connection to SQL Established");
  674.  
  675. //write to the database
  676.  
  677. String strSql = "INSERT INTO Flooring Values(?,?,?,?,?)";
  678. pstmt = conn.prepareStatement(strSql);
  679. pstmt.setString(1, cust.getCustomerName());
  680. pstmt.setString(2, cust.getCustomerAddress());
  681. pstmt.setDouble(3, cust.getFlooringType());
  682. pstmt.setDouble(4, cust.getFlooringArea());
  683. pstmt.setDouble(5, cust.getFlooringCost());
  684.  
  685.  
  686. //excute
  687. pstmt.execute();
  688. System.out.println("Successfull");
  689.  
  690. //close the connection
  691.  
  692. conn.close();
  693.  
  694.  
  695.  
  696.  
  697.  
  698. }
  699. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement