Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mitzen;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.DecimalFormat;
- import java.util.HashSet;
- import java.util.Set;
- import java.util.Vector;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import javax.swing.table.DefaultTableModel;
- /**
- *
- * @author MitzenTA1
- */
- public class Flooring extends javax.swing.JFrame {
- //class level
- private DefaultTableModel stuModel;
- /**
- * Creates new form Flooring
- */
- public Flooring() {
- stuModel = new DefaultTableModel();
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- btnFlooring = new javax.swing.ButtonGroup();
- jPanel1 = new javax.swing.JPanel();
- jTabbedPane1 = new javax.swing.JTabbedPane();
- jPanel2 = new javax.swing.JPanel();
- jRadioButtonWood = new javax.swing.JRadioButton();
- jRadioButtonCarpet = new javax.swing.JRadioButton();
- jLabelCustomerName = new javax.swing.JLabel();
- txtCustomerAddress = new javax.swing.JTextField();
- jLabel7 = new javax.swing.JLabel();
- txtCustomerName = new javax.swing.JTextField();
- jLabelFloorPrice = new javax.swing.JLabel();
- btnAddDatabase = new javax.swing.JButton();
- txtFloorPrice = new javax.swing.JTextField();
- jPanel3 = new javax.swing.JPanel();
- jButtonDisplay = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTableCustomer = new javax.swing.JTable();
- jButtonExit = new javax.swing.JButton();
- jPanel4 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- txtLength = new javax.swing.JTextField();
- jButtonArea = new javax.swing.JButton();
- txtWidth = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- txtTotalArea = new javax.swing.JTextField();
- txtTotalCost = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- btnFlooring.add(jRadioButtonWood);
- jRadioButtonWood.setText("Wood Flooring $20");
- jRadioButtonWood.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButtonWoodActionPerformed(evt);
- }
- });
- btnFlooring.add(jRadioButtonCarpet);
- jRadioButtonCarpet.setText("Carpet Flooring $10");
- jRadioButtonCarpet.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButtonCarpetActionPerformed(evt);
- }
- });
- jLabelCustomerName.setText("Customer Name");
- jLabelCustomerName.setToolTipText("");
- jLabel7.setText("Customer Address");
- jLabelFloorPrice.setText("Floor Type Price");
- btnAddDatabase.setText("Add to Database");
- btnAddDatabase.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnAddDatabaseActionPerformed(evt);
- }
- });
- txtFloorPrice.setEditable(false);
- txtFloorPrice.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtFloorPriceActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addGap(30, 30, 30)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabelCustomerName)
- .addComponent(jLabel7)
- .addComponent(btnAddDatabase))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtCustomerName)
- .addComponent(txtCustomerAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addComponent(jRadioButtonWood)
- .addGap(133, 133, 133)
- .addComponent(jLabelFloorPrice)
- .addContainerGap(161, Short.MAX_VALUE))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addComponent(jRadioButtonCarpet)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(txtFloorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(19, 19, 19))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(30, 30, 30)
- .addComponent(jRadioButtonWood))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(41, 41, 41)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabelFloorPrice)
- .addComponent(txtFloorPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGap(13, 13, 13)
- .addComponent(jRadioButtonCarpet)
- .addGap(66, 66, 66)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabelCustomerName)
- .addComponent(txtCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel7)
- .addComponent(txtCustomerAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(37, 37, 37)
- .addComponent(btnAddDatabase)
- .addContainerGap(198, Short.MAX_VALUE))
- );
- jTabbedPane1.addTab("Add", jPanel2);
- jButtonDisplay.setText("Display");
- jButtonDisplay.addInputMethodListener(new java.awt.event.InputMethodListener() {
- public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
- }
- public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
- jButtonDisplayCaretPositionChanged(evt);
- }
- });
- jButtonDisplay.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonDisplayActionPerformed(evt);
- }
- });
- jTableCustomer.setModel(stuModel);
- jScrollPane1.setViewportView(jTableCustomer);
- jButtonExit.setText("Exit");
- jButtonExit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonExitActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
- jPanel3.setLayout(jPanel3Layout);
- jPanel3Layout.setHorizontalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addComponent(jButtonDisplay)
- .addGap(0, 0, Short.MAX_VALUE))
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButtonExit)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- jPanel3Layout.setVerticalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addComponent(jButtonDisplay)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(33, 33, 33)
- .addComponent(jButtonExit)
- .addGap(0, 181, Short.MAX_VALUE))
- );
- jTabbedPane1.addTab("Display", jPanel3);
- jLabel1.setText("Length");
- jButtonArea.setText("Area of Floor");
- jButtonArea.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonAreaActionPerformed(evt);
- }
- });
- jLabel2.setText("TotalArea");
- jLabel3.setText("Width");
- jLabel4.setText("TotalCost");
- txtTotalArea.setEditable(false);
- txtTotalArea.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtTotalAreaActionPerformed(evt);
- }
- });
- txtTotalCost.setEditable(false);
- txtTotalCost.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtTotalCostActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
- jPanel4.setLayout(jPanel4Layout);
- jPanel4Layout.setHorizontalGroup(
- jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addGap(50, 50, 50)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel4)
- .addComponent(jLabel3)
- .addComponent(jLabel1))
- .addGap(92, 92, 92)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(txtWidth, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
- .addComponent(txtLength, javax.swing.GroupLayout.Alignment.LEADING))
- .addComponent(txtTotalCost, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
- .addComponent(txtTotalArea)))
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addGap(216, 216, 216)
- .addComponent(jButtonArea)))
- .addContainerGap(172, Short.MAX_VALUE))
- );
- jPanel4Layout.setVerticalGroup(
- jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addGap(59, 59, 59)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(txtLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(30, 30, 30)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addGap(46, 46, 46)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(txtTotalArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(19, 19, 19)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel4)
- .addComponent(txtTotalCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(27, 27, 27)
- .addComponent(jButtonArea))
- .addComponent(txtWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(193, Short.MAX_VALUE))
- );
- jTabbedPane1.addTab("Area", jPanel4);
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jTabbedPane1)
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap(38, Short.MAX_VALUE)
- .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void jButtonDisplayCaretPositionChanged(java.awt.event.InputMethodEvent evt) {
- // TODO add your handling code here:
- }
- private void jButtonDisplayActionPerformed(java.awt.event.ActionEvent evt) {
- // for display button
- String login = "4021";
- String password = "Nokia2610!";
- String databaseName = "CIS355A_4021";
- Connection conn = null;
- Statement stmnt;
- ResultSet results;
- try {
- //connection
- conn = DriverManager.getConnection("jdbc:mysql://devry.edupe.net:4300/"
- + databaseName,login, password);
- System.out.println("Connection to SQL Established");
- //retrive
- stmnt = conn.createStatement();
- results = stmnt.executeQuery("Select * FROM Flooring");
- //columan names
- ResultSetMetaData md = results.getMetaData();
- int num = md.getColumnCount();
- Vector<String> colNames = new Vector<String>();
- for ( int i = 1; i <= num; i++ )
- colNames.add(md.getColumnName(i));
- //assign
- stuModel.setColumnIdentifiers(colNames);
- while( results.next())
- {
- //adding table as object array
- stuModel.addRow(new Object[] {results.getString("CustomerName"),
- results.getString("CustomerAddress"),
- results.getDouble("FlooringType"),results.getDouble("FlooringArea"),results.getDouble("FlooringCost")});
- }
- }
- catch (SQLException ex) {
- JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(),"Error Message", JOptionPane.ERROR_MESSAGE);
- }
- }
- private void txtTotalAreaActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtTotalCostActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButtonAreaActionPerformed(java.awt.event.ActionEvent evt) {
- // adds cost and area
- double area = 0.00;
- double length = 0.00;
- double width = 0.00;
- double floorPrice;
- double totalCost = 0.00;
- length = Double.parseDouble(this.txtLength.getText());
- width = Double.parseDouble(this.txtWidth.getText());
- floorPrice = Double.parseDouble(txtFloorPrice.getText());
- area = length * width;
- totalCost = area * floorPrice;
- DecimalFormat fm = new DecimalFormat("0.00");
- txtTotalCost.setText(fm.format(totalCost));
- txtTotalArea.setText(fm.format(area));
- }
- private void btnAddDatabaseActionPerformed(java.awt.event.ActionEvent evt) {
- //add to database
- {
- Customers cust = new Customers();
- String name = txtCustomerName.getText();
- cust.setCustomerName(name);
- String address = txtCustomerAddress.getText();
- cust.setCustomerAddress(address);
- double floorType = Double.parseDouble (txtFloorPrice.getText());
- cust.setFlooringType(floorType);
- double flooringArea = Double.parseDouble (txtTotalArea.getText());
- cust.setFlooringArea(flooringArea);
- double flooringCost = Double.parseDouble(txtTotalCost.getText());
- cust.setFlooringCost(flooringCost);
- CustomerDB dataIO = new CustomerDB();
- try
- {
- dataIO.add(cust);
- JOptionPane.showMessageDialog(this, cust.getCustomerName() + " was added to the database");
- // output telling what was added
- }
- catch(SQLException | ClassNotFoundException ex)
- {
- JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(),
- "Database Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- private void jRadioButtonCarpetActionPerformed(java.awt.event.ActionEvent evt) {
- //carpet button
- updatePrice();
- }
- private void jRadioButtonWoodActionPerformed(java.awt.event.ActionEvent evt) {
- // wood button
- updatePrice();
- }
- private void txtFloorPriceActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt) {
- // Exits
- System.exit(0);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Flooring.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(() -> {
- new Flooring().setVisible(true);
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnAddDatabase;
- private javax.swing.ButtonGroup btnFlooring;
- private javax.swing.JButton jButtonArea;
- private javax.swing.JButton jButtonDisplay;
- private javax.swing.JButton jButtonExit;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabelCustomerName;
- private javax.swing.JLabel jLabelFloorPrice;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JPanel jPanel3;
- private javax.swing.JPanel jPanel4;
- private javax.swing.JRadioButton jRadioButtonCarpet;
- private javax.swing.JRadioButton jRadioButtonWood;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTabbedPane jTabbedPane1;
- private javax.swing.JTable jTableCustomer;
- private javax.swing.JTextField txtCustomerAddress;
- private javax.swing.JTextField txtCustomerName;
- private javax.swing.JTextField txtFloorPrice;
- private javax.swing.JTextField txtLength;
- private javax.swing.JTextField txtTotalArea;
- private javax.swing.JTextField txtTotalCost;
- private javax.swing.JTextField txtWidth;
- // End of variables declaration
- private void updatePrice() {
- //update the price of the floor type
- double floorPrice;
- if( !jRadioButtonWood.isSelected() && !jRadioButtonCarpet.isSelected())
- {
- JOptionPane.showMessageDialog(this, "Error, must select either Wood or Carpet");
- return;
- }
- if(jRadioButtonWood.isSelected())
- floorPrice = 20.00;
- else
- floorPrice = 10.00;
- DecimalFormat fm = new DecimalFormat("0.00");
- txtFloorPrice.setText(fm.format(floorPrice));
- }
- }
- package com.mitzen;
- /**
- *
- * @author tim
- */
- public class Customers {
- private String customerName;
- private String customerAddress;
- private double flooringType;
- private double flooringArea;
- private double flooringCost;
- public Customers()
- {
- customerName = "unknown";
- customerAddress = "unknown";
- flooringType = 0.00;
- flooringArea = 0.00;
- flooringCost = 0.00;
- }
- public Customers(String customerName, String customerAddress, double flooringType, double flooringArea, double flooringCost) {
- this.customerName = customerName;
- this.customerAddress = customerAddress;
- this.flooringType = flooringType;
- this.flooringArea = flooringArea;
- this.flooringCost = flooringCost;
- }
- public String getCustomerName() {
- return customerName;
- }
- public void setCustomerName(String customerName) {
- this.customerName = customerName;
- }
- public String getCustomerAddress() {
- return customerAddress;
- }
- public void setCustomerAddress(String customerAddress) {
- this.customerAddress = customerAddress;
- }
- public double getFlooringType() {
- return flooringType;
- }
- public void setFlooringType(Double flooringType) {
- this.flooringType = flooringType;
- }
- public double getFlooringArea() {
- return flooringArea;
- }
- public void setFlooringArea(Double flooringArea) {
- this.flooringArea = flooringArea;
- }
- public double getFlooringCost() {
- return flooringCost;
- }
- public void setFlooringCost(Double flooringCost) {
- this.flooringCost = flooringCost;
- }
- @Override
- public String toString() {
- return "Customers{" + "customerName=" + customerName + ", customerAddress=" + customerAddress + ", flooringType=" + flooringType + '}';
- }
- }
- package com.mitzen;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- /**
- *
- * @author tim
- */
- public class CustomerDB {
- public void add(Customers cust) throws ClassNotFoundException, SQLException//writes a record to the database
- {
- PreparedStatement pstmt = null;//creates references
- ResultSet rs = null;
- Class.forName("com.mysql.cj.jdbc.Driver");
- System.out.println("Connected to driver");
- //connection
- Connection conn = null;
- String login = "4021";
- String password = "Nokia2610!";
- String databaseName = "CIS355A_4021";
- conn = DriverManager.getConnection("jdbc:mysql://devry.edupe.net:4300/"
- + databaseName,login, password);
- System.out.println("Connection to SQL Established");
- //write to the database
- String strSql = "INSERT INTO Flooring Values(?,?,?,?,?)";
- pstmt = conn.prepareStatement(strSql);
- pstmt.setString(1, cust.getCustomerName());
- pstmt.setString(2, cust.getCustomerAddress());
- pstmt.setDouble(3, cust.getFlooringType());
- pstmt.setDouble(4, cust.getFlooringArea());
- pstmt.setDouble(5, cust.getFlooringCost());
- //excute
- pstmt.execute();
- System.out.println("Successfull");
- //close the connection
- conn.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement