You are on page 1of 31

import static java.lang.Class.

forName;

import java.sql.Connection;

import java.sql.DriverManager;

import static java.util.Collections.emptyList;

import javax.swing.DefaultListModel;

import javax.swing.JOptionPane;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author love

*/

public class ifpossible extends javax.swing.JFrame {

private Object AgeRB;

/**

* Creates new form impossible//

*/
public ifpossible() {

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() {

buttonGroup1 = new javax.swing.ButtonGroup();

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

LowerL = new javax.swing.JLabel();

UpperL = new javax.swing.JLabel();

jLabel5 = new javax.swing.JLabel();

jLabel6 = new javax.swing.JLabel();

jLabel7 = new javax.swing.JLabel();

jLabel8 = new javax.swing.JLabel();

jLabel9 = new javax.swing.JLabel();

jLabel10 = new javax.swing.JLabel();


QtyL = new javax.swing.JLabel();

jLabel12 = new javax.swing.JLabel();

jLabel13 = new javax.swing.JLabel();

jLabel14 = new javax.swing.JLabel();

confirm = new javax.swing.JButton();

SubmitB = new javax.swing.JButton();

SearchB = new javax.swing.JButton();

exitB = new javax.swing.JButton();

PriceRB = new javax.swing.JRadioButton();

AgeRB = new javax.swing.JRadioButton();

NameRB = new javax.swing.JRadioButton();

ConfirmB = new javax.swing.JCheckBox();

LowerTF = new javax.swing.JTextField();

UpperTF = new javax.swing.JTextField();

Bookcode = new javax.swing.JTextField();

Name = new javax.swing.JTextField();

Price = new javax.swing.JTextField();

Description = new javax.swing.JTextField();

a = new javax.swing.JTextField();

ordQtyTF = new javax.swing.JTextField();

jScrollPane1 = new javax.swing.JScrollPane();

orderT = new javax.swing.JTable();

jScrollPane2 = new javax.swing.JScrollPane();

BookList = new javax.swing.JList<>();

Total = new javax.swing.JTextField();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("BOOKS E-SHOPPING");

jLabel2.setText("Search Criteria");

LowerL.setText("Enter lower amount");

UpperL.setText("Enter upper amount");

jLabel5.setText("Select books below to see in details");

jLabel6.setText("BOOK DETAILS");

jLabel7.setText("Name");

jLabel8.setText("Description");

jLabel9.setText("Price");

jLabel10.setText("Book Code");

QtyL.setText("Qty in stock");
jLabel12.setText("BOOKS ORDERED");

jLabel13.setText("Total Amount Payable");

jLabel14.setText("Age Group");

confirm.setText("Confirm order");

confirm.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

confirmActionPerformed(evt);

});

SubmitB.setText("SUBMIT");

SubmitB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

SubmitBActionPerformed(evt);

});

SearchB.setText("search in database");

SearchB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

SearchBActionPerformed(evt);

}
});

exitB.setText("EXIt");

exitB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

exitBActionPerformed(evt);

});

PriceRB.setText("Price");

PriceRB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

PriceRBActionPerformed(evt);

});

AgeRB.setText("Age");

AgeRB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

AgeRBActionPerformed(evt);

});

NameRB.setText("Name");

NameRB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

NameRBActionPerformed(evt);

});

ConfirmB.setText("Click if you want to buy this book");

ConfirmB.addItemListener(new java.awt.event.ItemListener() {

public void itemStateChanged(java.awt.event.ItemEvent evt) {

ConfirmBItemStateChanged(evt);

});

ConfirmB.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

ConfirmBActionPerformed(evt);

});

LowerTF.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

UpperTF.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

Bookcode.setText("\n");

Bookcode.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

Name.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));


Price.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

Description.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

a.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

ordQtyTF.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

orderT.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null, null},

{null, null, null, null, null},

{null, null, null, null, null},

{null, null, null, null, null}

},

new String [] {

"Bookcode", "Name", "Price", "Qty order", "Amount"

){

Class[] types = new Class [] {

java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class,


java.lang.Float.class

};

public Class getColumnClass(int columnIndex) {


return types [columnIndex];

});

jScrollPane1.setViewportView(orderT);

BookList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {

public void valueChanged(javax.swing.event.ListSelectionEvent evt) {

BookListValueChanged(evt);

});

jScrollPane2.setViewportView(BookList);

Total.setText("jTextField1");

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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel7)

.addComponent(jLabel10)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(117, 117, 117)


.addComponent(jLabel6))

.addComponent(jLabel8)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(10, 10, 10)

.addComponent(jLabel9)))

.addGap(378, 378, 378))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addGap(0, 0, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(Price, javax.swing.GroupLayout.PREFERRED_SIZE, 56,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Bookcode, javax.swing.GroupLayout.PREFERRED_SIZE, 55,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(109, 109, 109)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(QtyL)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(ordQtyTF, javax.swing.GroupLayout.PREFERRED_SIZE, 44,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel14)

.addGap(18, 18, 18)


.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 63,
javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

.addComponent(Description, javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(Name, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)))

.addGap(158, 158, 158))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(23, 23, 23)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(390, 390, 390))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addComponent(confirm)

.addGap(143, 143, 143)))

.addComponent(ConfirmB))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel13)

.addGap(60, 60, 60))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 421,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(72, 72, 72)

.addComponent(SubmitB)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86,
Short.MAX_VALUE)))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(exitB)

.addComponent(Total, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(277, 277, 277))))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(611, 611, 611)

.addComponent(UpperL)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(UpperTF, javax.swing.GroupLayout.PREFERRED_SIZE, 38,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(411, 411, 411)

.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(280, 280, 280)

.addComponent(jLabel12))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(194, 194, 194)

.addComponent(jLabel2))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(143, 143, 143)

.addComponent(LowerL)

.addGap(43, 43, 43)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(PriceRB)

.addComponent(LowerTF, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(46, 46, 46)

.addComponent(AgeRB)))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addGap(133, 133, 133)

.addComponent(jLabel5)

.addGap(145, 145, 145)))


.addGap(50, 50, 50)

.addComponent(NameRB)

.addGap(76, 76, 76)

.addComponent(SearchB))))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel1)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(23, 23, 23)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel2)

.addGap(3, 3, 3)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(PriceRB)

.addComponent(AgeRB)

.addComponent(NameRB)))

.addComponent(SearchB))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(LowerTF, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(LowerL))

.addGap(41, 41, 41)

.addComponent(jLabel5))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(UpperTF, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(UpperL))

.addGap(47, 47, 47)

.addComponent(jLabel6)))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(27, 27, 27)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel10)

.addComponent(Bookcode, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel14)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel7)

.addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(12, 12, 12)

.addComponent(jLabel8))

.addGroup(jPanel1Layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(Description, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel9)

.addComponent(Price, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(15, 15, 15)


.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(QtyL)

.addComponent(ordQtyTF, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGap(28, 28, 28)

.addComponent(ConfirmB)

.addGap(71, 71, 71))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(confirm)

.addGap(50, 50, 50))))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(90, 90, 90)))

.addComponent(jLabel12)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(36, 36, 36)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel13)

.addComponent(Total, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(62, 62, 62)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(SubmitB)

.addComponent(exitB))

.addGap(145, 145, 145))))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(0, 20, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void NameRBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if (NameRB.isSelected())

{LowerL.setText("Enter Name");

UpperL.setEnabled(false);

UpperTF.setEnabled(false);

else

{ LowerL.setText("Enter lower limit");

UpperL.setEnabled(true);

UpperTF.setEnabled(true);

}
}

private void confirmActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

int qtyA = Integer.parseInt(ordQtyTF.getText());

int qtyO = Integer.parseInt(qtyTF.getText());

if (qtyO>qtyA)

JOptionPane.showMessageDialog(rootPane,"Only"'+qtyA"+items of"+bookcode.getTexy()+"are in
stock!\n SORRY,Cannot take your order");

else{

float amt=qtyO*Float.parseFloat(Price.getText());

float total=Float.parseFloat(Total.getText());

DefaultTableMOdel model=DefaultTableModel)orderT.getModel();

int tc=Integer.parseInt(Bookcode.getText());

String qry="UPDATE books SET qtyinstock=qtyinstock-"+qtyO+"WHERE Bookcode="+tc+";";

try {

Class.forName("java.sqlDriver");

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/STORE","root","root");

Statement stmt = conc.createstatement();

stmt.excecuteUpdate(qry);

// now adding to ordertable

model.addRow(new
object[]{Bookcode.getText(),Name.getText(),Price.getText(),ordQtyTF.getText(),amt};

total=total+amt;

Total.setText(""+total));
}

catch(Exception e){

JOptionPane.showMessageDialog(null,"Error in connectivity");

ordQtyTF.setText("");

ordQtyTF.setEnabled(false);

ConfirmB.setSelected(false);

private void SearchBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

emptyList();//method to empty the list

String filter="";

if(NameRB.isSelected())

filter="WHERE name=""+lowerTF.getText()+"";

else if (PriceRB.isSelected()){
float priceL=Float.parseFloat(LowerTF.getText());

float priceF=Float.parseFloat(UpperTF.getText());

filter="WHERE price>="+priceL+"and price<="+priceF;

else if(AgeRB.isSelected()){

int age=Integer.parseInt(LowerTF.getText());

filter="WHERE agegrouplowerlimit<="+age"and age groupupperlimit>="+age;

int count=0;

String query="SELECT name from books"+filter+";";

DefaultListModelmodel=(DefaultListModel)Booklist.getModel();

try {

class.forName("java.sql.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost/STORE","root","root");

Statement stmt=con.create.statement();

ResultSet rs=stmt.executeQuery(query);

while(rs.nect()){

model.add(count,rs.getString(""));

count++;

rs.close();

stmt.close();

con.close();

catch (Exception e){


JOptionPane.showMessageDialog(null,"Errot in connectivity");

ordQtyTF.setEnabled(false);

void emptyList()

DefaultListModel model=(DefaultListModel)Booklist.getModel();

while(model.getsize()>0);

model.remove(0);

}
private void AgeRBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if(AgeRB.isSelected()) {

LowerL.setText("Enter Age");

} else {

UpperL.setEnabled(false);

UpperTF.setEnabled(false);

else

{LowerL.setText("Enter lower limit");

UpperL.setEnabled(true);

UpperTF.setEnabled(true);

private static class Statement {

public Statement() {

private static class ResultSet {


public ResultSet() {

private static class LowerL {

public LowerL() {

private void exitBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

JOptionPane.showMessageDialog(rootPane,"Thank you for using the E-business Application");

System.exit(0);

private void BookListValueChanged(javax.swing.event.ListSelectionEvent evt) {

// TODO add your handling code here:

String selval=(String)BookList.getSelectedValue();

String query= "SELECT*FROM books WHERE='"+selval+'";";

try{

Class.forName("java.sql.Driver");
Connection conc=DriveManager.getConnection("jdbc:mysql://localhost/STORE","root","root");

Statement stmt =conc.createStatement();

ResultSet rs=stmt.executeQuery(query);

rs.next();

Bookcode.setText(""+rs.getInt(1));

Name.setText(rs.getString(2));

Description.setText(rs.getString(3));

QtyL.setText(""+rs.getInt(4));

AgeGroup.setText(""+rs.getInt(5)+"to"+rs.getInt(6));

Price.setText(""+rs.getFloat(8));

rs.close();

stmt.close();

con.close();

catch(exception e)

JOptionPane.showMessageDialog(null,"Error in connectivity");

}
}

private void ConfirmBItemStateChanged(java.awt.event.ItemEvent evt) {

// TODO add your handling code here:

private void ConfirmBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if(buyCB.isSelected())

ordQtyTF.setEnabled(true);

private void PriceRBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

if(PriceRB.isSelected())

UpperL.setEnabled(true))

UpperTF.setEnabled(true);

private void SubmitBActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

DefaultTableModelmodel=(DefaultTableModel)orderT.getModel();

int count =model.getCount();


String total=Total.getText();

JOptionPane.showMessageDialog(rootPane"You have ordered for"+count+"items\n and your bill


amount is Rs."+total);

/**

* @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(ifpossible.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {


java.util.logging.Logger.getLogger(ifpossible.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(ifpossible.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(ifpossible.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new ifpossible().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JRadioButton AgeRB;

private javax.swing.JList<String> BookList;

private javax.swing.JTextField Bookcode;

private javax.swing.JCheckBox ConfirmB;

private javax.swing.JTextField Description;

private javax.swing.JLabel LowerL;

private javax.swing.JTextField LowerTF;


private javax.swing.JTextField Name;

private javax.swing.JRadioButton NameRB;

private javax.swing.JTextField Price;

private javax.swing.JRadioButton PriceRB;

private javax.swing.JLabel QtyL;

private javax.swing.JButton SearchB;

private javax.swing.JButton SubmitB;

private javax.swing.JTextField Total;

private javax.swing.JLabel UpperL;

private javax.swing.JTextField UpperTF;

private javax.swing.JTextField a;

private javax.swing.ButtonGroup buttonGroup1;

private javax.swing.JButton confirm;

private javax.swing.JButton exitB;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel10;

private javax.swing.JLabel jLabel12;

private javax.swing.JLabel jLabel13;

private javax.swing.JLabel jLabel14;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JLabel jLabel7;

private javax.swing.JLabel jLabel8;

private javax.swing.JLabel jLabel9;


private javax.swing.JPanel jPanel1;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JTextField ordQtyTF;

private javax.swing.JTable orderT;

// End of variables declaration

private static class connection {

public connection() {

You might also like