Documente Academic
Documente Profesional
Documente Cultură
import javax.swing.JOptionPane;
// On clicking Exit
private void exitActionPerformed(java.awt.event.ActionEvent evt) { JOptionPane.showMessageDialog(rootPane, "<HTML>Thanks for using e-shopping Application"); System.exit(0); }
// code for e-shopping manager button
public void a(){ new es().setVisible(true); } public void b(){ new info().setVisible(true); } public void c(){ new About().setVisible(true); } public void d(){ new addNew().setVisible(true); }
import javax.swing.DefaultListModel; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel;
private void srchPriceRBActionPerformed(java.awt.event.ActionEvent evt) { if(srchPriceRB.isSelected()) { dispLabel1.setText("Enter Lower limit"); dispLabel2.setEnabled(true); upperTF.setEnabled(true); lowerTF.setEnabled(true); } }
//Code for search by Age filter criteria
private void srchAgeRBActionPerformed(java.awt.event.ActionEvent evt) { if (srchAgeRB.isSelected()) { dispLabel1.setText("Enter Age"); dispLabel2.setEnabled(false); upperTF.setEnabled(false); lowerTF.setEnabled(true); } else { dispLabel1.setText("Enter Lower Limit"); dispLabel2.setEnabled(true); upperTF.setEnabled(true); lowerTF.setEnabled(true); } }
6
searchPriceRB upperTF
searchAgeRB dispLabel2
searchNameRB
dispLabel1 tCodeLbl
lowerTF
toyList
tDesLbl
buyCB
orderTbl
totAmtLbl
submitBtn
exitBtn
private void srchNameRBActionPerformed(java.awt.event.ActionEvent evt) { if(srchNameRB.isSelected()) { dispLabel1.setText("Enter Name"); upperTF.setEnabled(false); dispLabel2.setEnabled(false); lowerTF.setEnabled(true); } else { dispLabel1.setText("Enter Lower limit"); dispLabel2.setEnabled(true); upperTF.setEnabled(false); lowerTF.setEnabled(true); } }
private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) { emptyList(); String filter=""; if (srchNameRB.isSelected()) { filter="WHERE name like '%"+lowerTF.getText()+"%' "; } else if(srchPriceRB.isSelected()) { float priceL=Float.parseFloat(lowerTF.getText()); float priceF=Float.parseFloat(upperTF.getText()); filter="WHERE price>="+priceL+" and price <="+priceF; } else if(srchAgeRB.isSelected()){ int age=Integer.parseInt(lowerTF.getText()); filter="WHERE agegroulowerlimit<= "+age+" and agegroupupperlimit >= "+age; } int count=0; String query="Select name from toys "+filter+" ;"; DefaultListModel model=(DefaultListModel)toyList.getModel(); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()){ model.add(count,rs.getString("name")); count++; } rs.close(); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity"); } ordQtyTF.setEnabled(false); }
//Code for check box for confirming to buy the item or not
11
private void toyListValueChanged(javax.swing.event.ListSelectionEvent evt) { String selval=(String)toyList.getSelectedValue(); String query="select * from toys where name like'%"+selval+"%';"; try{ Class.forName("java.sql.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()){ tCodeLbl.setText(""+rs.getInt(1)); tNameLbl.setText(rs.getString(2)); tDesLbl.setText(rs.getString(3)); tQtyLbl.setText(""+rs.getInt(4)); tageGrpLbl.setText(""+rs.getInt(5)+"to"+rs.getInt(6)); tPriceLbl.setText(""+rs.getFloat(8)); } rs.close(); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity"); } }
private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model=(DefaultTableModel)orderTbl.getModel(); int count=model.getRowCount(); String total=totAmtLbl.getText(); JOptionPane.showMessageDialog(rootPane, "You have ordered for "+count+" items \n and your bill amount is Rs."+total); }
12
13
private void confirmBtnActionPerformed(java.awt.event.ActionEvent evt) { int qtyA=Integer.parseInt(tQtyLbl.getText()); int qtyO=Integer.parseInt(ordQtyTF.getText()); if(qtyO>qtyA) { JOptionPane.showMessageDialog(rootPane, "Only "+qtyA+" items of "+tCodeLbl.getText()+" are in stock! \n SORRY, cannot take your order."); } else{ float amt=qtyO*Float.parseFloat(tPriceLbl.getText()); float total=Float.parseFloat(totAmtLbl.getText()); DefaultTableModel model=(DefaultTableModel)orderTbl.getModel(); int tc=Integer.parseInt(tCodeLbl.getText()); String qry="Update TOYS SET qtyinstock=qtyinstock-"+qtyO+" Where toycode ="+tc+" ;"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); stmt.executeUpdate(qry); model.addRow(new Object[] { tCodeLbl.getText(),tNameLbl.getText(),tPriceLbl.getText(),ordQtyTF.getText(),amt }); total=total+amt; totAmtLbl.setText(""+total); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity"); } ordQtyTF.setText(""); ordQtyTF.setEnabled(false); buyCB.setSelected(false); } }
14
import javax.swing.DefaultListModel; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import javax.swing.JOptionPane;
private void getdetailsActionPerformed(java.awt.event.ActionEvent evt) { emptyList(); int count=0; String query="Select name from toys ;"; DefaultListModel model=(DefaultListModel)tList.getModel(); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()){ model.add(count,rs.getString("name")); count++; } rs.close(); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience"); } }
15
getdetails
tCodeLBl
agl tNameLbl
agh
tDesLbl
tQtyLbl
16
private void tListValueChanged(javax.swing.event.ListSelectionEvent evt) { String selval=(String)tList.getSelectedValue(); String query="select * from toys where name like'%"+selval+"%';"; try{ Class.forName("java.sql.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()){ tCodeLbl.setText(""+rs.getInt(1)); tNameLbl.setText(rs.getString(2)); tDesLbl.append(rs.getString(3)); tQtyLbl.setText(""+rs.getInt(4)); agl.setText(""+rs.getInt(5)); agh.setText(""+rs.getInt(6)); tPriceLbl.setText(""+rs.getFloat(8)); tSexLbl.setText(""+rs.getString(7)); } rs.close(); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience."); } edit.setEnabled(true); deletercrd.setEnabled(true); }
//Code for Edit Button
private void editActionPerformed(java.awt.event.ActionEvent evt) { updtrcrd.setEnabled(true); tNameLbl.setEditable(true); tDesLbl.setEditable(true); tQtyLbl.setEditable(true); agh.setEditable(true); agl.setEditable(true); tPriceLbl.setEditable(true); tSexLbl.setEditable(true); }
17
18
private void deletercrdActionPerformed(java.awt.event.ActionEvent evt) { int res=JOptionPane.showConfirmDialog(null,"Want to remove the toy for sure ?"); if(res==JOptionPane.YES_OPTION){ try{ Class.forName("java.sql.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); String queryd="Delete from toys where toycode="+tCodeLbl.getText()+";"; stmt.executeUpdate(queryd); JOptionPane.showMessageDialog(null,"Record Deleted !"); getdetails.doClick(); tCodeLbl.setText(""); tNameLbl.setText(""); tDesLbl.append(""); tQtyLbl.setText(""); agh.setText(""); agl.setText(""); tPriceLbl.setText(""); tSexLbl.setText(""); edit.setEnabled(false); updtrcrd.setEnabled(false); deletercrd.setEnabled(false); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience."); } } }
19
20
private void updtrcrdActionPerformed(java.awt.event.ActionEvent evt) { String qury="Update toys set name= '"+tNameLbl.getText()+"',descp= '"+tDesLbl.getText()+"',qtyinstock= "+tQtyLbl.getText()+" ,agegroulowerlimit= "+agl.getText()+" ,agegroupupperlimit= "+agh.getText()+" ,forgender= '"+tSexLbl.getText()+"',price= "+tPriceLbl.getText()+"where toycode="+tCodeLbl.getText()+";"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); stmt.executeUpdate(qury); JOptionPane.showMessageDialog(null,"Successfully Updated"); tNameLbl.setEditable(false); tDesLbl.setEditable(false); tQtyLbl.setEditable(false); agh.setEditable(false); agl.setEditable(false); tPriceLbl.setEditable(false); tSexLbl.setEditable(false); updtrcrd.setEnabled(false); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience"); } }
21
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import javax.swing.JOptionPane;
//code for fetch button private void fetchActionPerformed(java.awt.event.ActionEvent evt) { String query="Select toycode from toys;"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()){ codet.setText(""+rs.getInt(1)); } rs.close(); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience"); } int a=Integer.parseInt(codet.getText()); int b=++a; codet.setText(""+b); }
22
codet
namet
fetch dest
prct
23
//code for Add new Button private void addnewActionPerformed(java.awt.event.ActionEvent evt) { String qury="Insert into toys values ( "+codet.getText()+" , '"+namet.getText()+"', '"+dest.getText()+"', "+qtyt.getText()+" , "+lowt.getText()+" , "+hight.getText()+" , '"+gent.getSelectedItem()+"', "+prct.getText()+" );"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","inspire11"); Statement stmt=con.createStatement(); stmt.executeUpdate(qury); JOptionPane.showMessageDialog(null,"Successfully Added"); fetch.doClick(); namet.setText(""); dest.setText(""); prct.setText(""); lowt.setText(""); hight.setText(""); namet.setText(""); qtyt.setText(""); stmt.close(); con.close(); } catch(Exception e){ JOptionPane.showMessageDialog(null,"Error in connectivity \n sorry for incovenience"); } }
24
25
Bibliography
Reference of the information used here 1. Informatics Practices for class XII Sumita Arora
26