Sei sulla pagina 1di 23

Chapter 4 Software Implementation

Chapter 4 Software Implementation

54

Chapter 4 Software Implementation

4.1. Software Implementation: This Thesis report we discusses about several types of E-Commerce architecture like Clint server architecture, Two Tier architecture, Three tier architecture and Distributed Enterprise Architecture and implements 3-tier architecture using JAVA and a dummy customer using MS Access database. In this paper we trying to implement a small reusable component that maintains customers in 3-tier architecture. It shows how to add, update and Delete customer details. This component has 3 tiers. Tier 1 Graphical Interface, tier 2 and tier 3 are combined together with the name _tier. We have compiled all the 3 tiers in the same project for ease of work. I am including all the source code along with the MS Access database. 4.2. Source Code:
/* * _tireView.java */ package _tire;

import org.jdesktop.application.Action; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; import org.jdesktop.application.TaskMonitor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFrame; import java.awt.event.ActionEvent;

55

Chapter 4 Software Implementation import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFrame; import java.awt.*; import java.sql.*; import javax.swing.*; import java.awt.event.*;

/** * The application's main frame. */ public class _tireView extends FrameView {

public _tireView(SingleFrameApplication app) { super(app);

initComponents();

// status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { public void actionPerformed(ActionEvent e) {

56

Chapter 4 Software Implementation statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false);

// connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) {

57

Chapter 4 Software Implementation if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String)(evt.getNewValue()); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer)(evt.getNewValue()); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } }); }

58

Chapter 4 Software Implementation @Action public void showAboutBox() { if (aboutBox == null) { JFrame mainFrame = _tireApp.getApplication().getMainFrame(); aboutBox = new _tireAboutBox(mainFrame); aboutBox.setLocationRelativeTo(mainFrame); } _tireApp.getApplication().show(aboutBox); }

/** 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">//GENBEGIN:initComponents private void initComponents() {

mainPanel = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField7 = new javax.swing.JTextField(); jTextField8 = new javax.swing.JTextField(); 59

Chapter 4 Software Implementation jTextField6 = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu helpMenu = new javax.swing.JMenu(); javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem(); statusPanel = new javax.swing.JPanel(); javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator(); statusMessageLabel = new javax.swing.JLabel(); statusAnimationLabel = new javax.swing.JLabel(); progressBar = new javax.swing.JProgressBar();

mainPanel.setName("mainPanel"); // NOI18N

60

Chapter 4 Software Implementation org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(_tire._tireApp.class).getCont ext().getResourceMap(_tireView.class); jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N jTextField1.setName("jTextField1"); // NOI18N

jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N jTextField2.setName("jTextField2"); // NOI18N

jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N jTextField3.setName("jTextField3"); // NOI18N

jTextField4.setText(resourceMap.getString("jTextField4.text")); // NOI18N jTextField4.setName("jTextField4"); // NOI18N

jTextField7.setText(resourceMap.getString("jTextField7.text")); // NOI18N jTextField7.setName("jTextField7"); // NOI18N

jTextField8.setText(resourceMap.getString("jTextField8.text")); // NOI18N jTextField8.setName("jTextField8"); // NOI18N

jTextField6.setText(resourceMap.getString("jTextField6.text")); // NOI18N jTextField6.setName("jTextField6"); // NOI18N

61

Chapter 4 Software Implementation

jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N

jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N

jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N

jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N jLabel4.setName("jLabel4"); // NOI18N

jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N jLabel5.setName("jLabel5"); // NOI18N

jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N jButton1.setName("jButton1"); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N jButton2.setName("jButton2"); // NOI18N

62

Chapter 4 Software Implementation jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N jButton3.setName("jButton3"); // NOI18N jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });

jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N jLabel6.setName("jLabel6"); // NOI18N

jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N jLabel7.setName("jLabel7"); // NOI18N

javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING)

63

Chapter 4 Software Implementation .addGroup(mainPanelLayout.createSequentialGroup() .addGap(39, 39, 39) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4) .addComponent(jLabel5)) .addGap(37, 37, 37) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.TRAILING) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE) .addComponent(jTextField8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE) .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE) .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)) .addGap(28, 28, 28)

64

Chapter 4 Software Implementation

.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.TRAILING) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(jLabel6) .addGap(28, 28, 28)) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(jLabel7) .addGap(17, 17, 17)))) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addComponent(jButton2) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())

65

Chapter 4 Software Implementation .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addComponent(jButton3) .addGap(40, 40, 40)))) ); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGroup(mainPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

66

Chapter 4 Software Implementation .addComponent(jLabel6)) .addGap(18, 18, 18) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)

67

Chapter 4 Software Implementation .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7))) .addComponent(jButton2)) .addGap(29, 29, 29) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jButton3) .addComponent(jButton1)) .addContainerGap(53, Short.MAX_VALUE)) );

menuBar.setName("menuBar"); // NOI18N

fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N fileMenu.setName("fileMenu"); // NOI18N

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(_tire._tireApp.class).getCont ext().getActionMap(_tireView.class, this); exitMenuItem.setAction(actionMap.get("quit")); // NOI18N exitMenuItem.setName("exitMenuItem"); // NOI18N fileMenu.add(exitMenuItem);

menuBar.add(fileMenu);

68

Chapter 4 Software Implementation helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N helpMenu.setName("helpMenu"); // NOI18N

aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N aboutMenuItem.setName("aboutMenuItem"); // NOI18N helpMenu.add(aboutMenuItem);

menuBar.add(helpMenu);

statusPanel.setName("statusPanel"); // NOI18N

statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

statusMessageLabel.setName("statusMessageLabel"); // NOI18N

statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LE FT); statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

progressBar.setName("progressBar"); // NOI18N

javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel); statusPanel.setLayout(statusPanelLayout); statusPanelLayout.setHorizontalGroup(

69

Chapter 4 Software Implementation

statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE) .addGroup(statusPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(statusMessageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 302, Short.MAX_VALUE) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(statusAnimationLabel) .addContainerGap()) ); statusPanelLayout.setVerticalGroup( statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.L EADING) .addGroup(statusPanelLayout.createSequentialGroup() .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

70

Chapter 4 Software Implementation

.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.A lignment.BASELINE) .addComponent(statusMessageLabel) .addComponent(statusAnimationLabel) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(3, 3, 3)) );

setComponent(mainPanel); setMenuBar(menuBar); setStatusBar(statusPanel); }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed jButton1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String a1=jTextField1.getText(); String a2=jTextField2.getText(); String a3=jTextField3.getText(); String a4=jTextField4.getText(); String a5=jTextField8.getText();

try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 71

Chapter 4 Software Implementation Connection connect =DriverManager.getConnection("jdbc:odbc:POSSS"); Statement st=connect.createStatement(); int i=st.executeUpdate("insert into ADD(ItemId,Title,TotalEntry,Categore,EntryDate) values("+a1+",'"+a2+"',"+a3+",'"+a4+"','"+a5+"')"); JOptionPane.showMessageDialog(null,"Inserted Successfully"); } catch(Exception ex){ JOptionPane.showMessageDialog(null,"Error","Warning",JOptionPane.OK_OPTI ON); } } }); // TODO add your handling code here: }//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed jButton2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String a1=jTextField1.getText(); String a2=jTextField2.getText(); String a3=jTextField3.getText(); String a4=jTextField4.getText(); String a5=jTextField8.getText(); String a6=jTextField6.getText(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

72

Chapter 4 Software Implementation Connection connect =DriverManager.getConnection("jdbc:odbc:POSSS"); Statement st=connect.createStatement(); int i=st.executeUpdate("UPDATE ADD SET ItemId="+a1+",Title='"+a2+"',TotalEntry="+a3+",Categore='"+a4+"',Entry Date='"+a5+"' where ItemId="+a6+""); JOptionPane.showMessageDialog(null,"Update Successfully"); } catch(Exception ex){ JOptionPane.showMessageDialog(null,"Error"/*,"Warning",JOptionPane.OK_O PTION*/); } } }); // TODO add your handling code here:

}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed jButton3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String a1=jTextField7.getText(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect =DriverManager.getConnection("jdbc:odbc:POSSS"); Statement st=connect.createStatement(); int i=st.executeUpdate("DELETE FROM ADD where ItemId="+a1+""); JOptionPane.showMessageDialog(null,"Delete Successfully"); } catch(Exception ex){

73

Chapter 4 Software Implementation JOptionPane.showMessageDialog(null,"Error"/*,"Warning",JOptionPane.OK_O PTION*/); } } }); // TODO add your handling code here:

}//GEN-LAST:event_jButton3ActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField8; private javax.swing.JPanel mainPanel; private javax.swing.JMenuBar menuBar; 74

Chapter 4 Software Implementation private javax.swing.JProgressBar progressBar; private javax.swing.JLabel statusAnimationLabel; private javax.swing.JLabel statusMessageLabel; private javax.swing.JPanel statusPanel; // End of variables declaration//GEN-END:variables

private final Timer messageTimer; private final Timer busyIconTimer; private final Icon idleIcon; private final Icon[] busyIcons = new Icon[15]; private int busyIconIndex = 0;

private JDialog aboutBox; }

4.3. User Interface:

75

Chapter 4 Software Implementation

4.4. Database view:

76

Potrebbero piacerti anche