Sei sulla pagina 1di 36

Session 2018-19

(Affiliated to C.B.S.E.)

A PROJECT REPORT ON
‘SPORTS SHOP MANAGEMENT SYSTEM’

For
AISSCE 2018-19 Examination
[As a part of the Informatics Practices Course (065)]

Submitted By- ANUJ GUPTA Guided By


Class-
Submitted By- ANUJXII GUPTA
G Ms. RICHIBySHARMA
Guided
Class- XII G Ms. RICHI SHARMA
CERTIFICATE

This is to certify that the Project entitled

Sports Shop Management System is a

bonafide work done by Master ANUJ GUPTA

of class XII Session 2018-19 in partial

fulfillment of CBSE’s AISSCE Examination

2019 and has been carried out under my

direct supervision and guidance. This report

or a similar report on the topic has not

been submitted for any other examination

and does not form a part of any other

course undergone by the candidate.


………………………………...
…………………………….
Signature of Teacher/Guide
Signature of Principal

Place: …………….
Date: …………….
ACKNOWLEDGEMENT

I undertook this Project work, as the part of


my class XII Informatics Practices course. I
have tried to apply my best of knowledge
and experience, gained during the study
and class work experience. However,
developing software system is generally a
quite complex and time-consuming
process. It requires a systematic study,
insight vision and professional approach
during the design and development.
Moreover, the developer always feels the
need, the help and good wishes of the
people near you, who have considerable
experience and idea.

I would like to extend my sincere thanks


and gratitude to my teacher Ms. Richi
Sharma and the staff from the computer
department for giving valuable time and
moral support to develop this software.
I would like to take the opportunity to
extend my sincere thanks to my friends for
the valuable suggestions during the project
work.

-ANUJ GUPTA class XII


CONTENTS

1. Introduction
2. Objective and Scope of the Project
3. Theoretical Background
4. Problem Definition and Analysis
5. System Design and Development
6. Bbliography
1. Introduction

This software project is developed to automate


the functionalities of a SPORTS shop. The
purpose of the software project is to develop the
Management Information System to automate
the record keeping of customer entry, order
entry and item entry with a view to enhance the
decision making of the functionaries.

A MIS mainly consists of a computerized


database, a collection of inter-related tables for
a particular subject or purpose, capable to
produce different reports relevant to the user.
An application program is tied with the database
for easy access and interface to the database.
Using Application program or front-end, we can
store, retrieve and manage all information in
proper way.
This software, being simple in design and
working, does not require much of training to
users, and can be used as a powerful tool for
automating a sports shop System.

During coding and design of the software


Project, Java NetBeans IDE, a powerful front-end
tool is used for getting Graphical User Interface
(GUI) based integrated platform and coding
simplicity. As a back-end a powerful, open
source RDBMS, My SQL is used as per
requirement of the CBSE curriculum of
Informatics Practices Course.

2. Objective & Scope of the Project

The objective of the software project is to develop a


computerized MIS to automate the functions of a
SPORTS shop. This software project is also aimed to
enhance the current record keeping system, which
will help managers to retrieve the up-to-date
information at right time in right shape.

The proposed software system is expected to do the


following functionality-
 To provide a user friendly, Graphical User
Interface (GUI) based integrated and centralized
environment for MIS activities.
 The proposed system should maintain all the
records and transactions, and should generate
the required reports and information when
required.
 To provide graphical and user-friendly interface to
interact with a centralized database based on
client-server architecture.
 To identify the critical operation procedure and
possibilities of simplification using modern IT tools
and practices.

In its current scope, the software enables user to


retrieve and update the information from centralized
database designed with MySQL . This software does
not require much training time of the users due to
limited functionality and simplicity.
Despite of the best effort of the developer, the
following limitations and functional boundaries are
visible, which limits the scope of this application
software.

1.This software can store records and produce


reports in pre-designed format in soft copy. There
is no facility yet to produce customized reports.
Only specified reports are covered.

2.There is no provision to calculate fine or penalty


etc. for defaulter members; however it can be
developed easily with the help of adding modules.

3.Some application area like deleting the record.

So far as future scope of the project is concerned,


firstly it is open to any modular expansion i.e. other
modules or functions can be designed and embedded
to handle the user need in future. Any part of the
software and reports can be modified independently
without much effort.
3. Theoretical Background

Introduction and Concepts:


A database is a collection of information related to a
particular subject or purpose, such as tracking
customer orders or maintaining a music collection.
Using any RDBMS application software like MS SQL
Server, MySQL, Oracle, Sybase etc, you can manage
all your information from a single database file. Within
the file, divide your data into separate storage
containers called tables. You may and retrieve the
data using queries.
A computer database works as an electronic filing
system, which has a large number of ways of cross-
referencing, and this allows the user many different
ways in which to re-organize and retrieve data. A
database can handle business inventory, accounting
and filing and use the information in its files to
prepare summaries, estimates and other reports. The
management of data in a database system is done by
means of a general-purpose software package called
a Database Management System (DBMS). Some
commercially available DBMS are MS SQL Server, MS
ACCESS, INGRES, ORACLE, and Sybase. A database
management system, therefore, is a combination of
hardware and software that can be used to set up and
monitor a database, and can manage the updating
and retrieval of database that has been stored in it.
Various reports can be produced from the system.
These may be either standardized report or that may
be specifically generated according to specific user
definition.
The DBMS interprets and processes users' requests
to retrieve information from a database. In most
cases, a query request will have to penetrate several
layers of software in the DBMS and operating system
before the physical database can be accessed. The
DBMS responds to a query by invoking the
appropriate subprograms, each of which performs its
special function to interpret the query, or to locate
the desired data in the database and present it in the
desired order.
4. Problem Definition & Analysis

Problem definition and Analysis is the activity that


encompasses learning about the problem to be
solved, understanding the needs of customer and
users, trying to find out who the user really is, and
understanding all the constraints on the solution. It
includes all activities related to the following:
 Identification and documentation of customer’s or
user’s needs.
 Creation of a document that describes the
external behavior and the association constraints
that will satisfies those needs.
 Analysis and validation of the requirements
documents to ensure consistency, completeness,
and feasibility
 Evolution of needs.

After the analysis of the functioning of a Sports Shop,


the proposed System is expected to do the following:
-
 To provide a user friendly, Graphical User
Interface (GUI) based integrated and centralized
environment for computerized Sports Shop.
 The proposed system should maintain all the
records and transactions, and should generate
the required reports and information when
required.
 To provide efficient and secured Information
storage, flow and retrieval system, ensuring the
integrity and validity of records.
 To provide graphical and user-friendly interface to
interact with a centralized database based on
client-server architecture.
 To identify the critical operation procedure and
possibilities of simplification using modern IT tools
and practices.
5. System Design & Development
Database Design:
An important aspect of system design is the design of
data storage structure. To begin with a logical model
of data structure is developed first. A database is a
container object which contains tables, queries,
reports and data validation policies enforcement rules
or constraints etc. A logical data often represented as
a records are kept in different tables after reducing
anomalies and redundancies. The goodness of data
base design lies in the table structure and its
relationship.
This software project maintains a database named
shopkeeper which contains the following tables.
Table Design:
The database of shopkeeper System contains 5
tables. The tables are normalized to minimize the
redundancies of data and enforcing the validation
rules of the organization. Most of the tables are
designed to store master records. The tables and their
structure are given below.
Table: shopkeeper
Column Name Type Size
Shooper _id Integer 100
name Varchar 100
city Varchar 100
phone Varchar 11
address Varchar 40

Table: item
Column Name Type Size
Item_id Integer 100
Item_name varchar 100
description Varchar 1000
price float (11,2)

Table: orderitem
Column Name Type Size
orderno varchar 100
item_id int 100
shopper_id Varchar 100
quantity int 100
Order date Date
price float (11,2)
discount Float (11,2)
amount float (11,2)
Menu Design:
JSS Infoware gateway comprises the following options,
organized in a user friendly way. The menu system
divided in Menu Bars, each having a pull down menus
containing options for a specific task.

Sr. Menu Bar Pull Down Menu Purpose Forms Attached


Insertion of Custmor PubUI.java
Custmor entry
records.
Sports
1. Item entry Insertion of item records. PubEditUI.java
club Order entry Insertion of Order records. PubDelUI.java

Custmor list view Custmor list LibUI.java


2. view Item list view Item list LibEditUI.java
Order list view Order list LibDelUI.java
5. Quit Application Close the Application. --

I/O Forms Design & Event Coding:


The software project for Public Library Management
contains various forms along with programming
codes. Forms (JFrames) and their event coding are
given below.
Frame: MainUI.java

Coding for MainUi.java private void


public class MainMenuUI extends jMenu2ActionPerformed(java.awt.event.Ac
javax.swing.JFrame { tionEvent evt) { }
private void
ListCustActionPerformed(java.awt.event.A
/** Creates new form MainMenuUI */
ctionEvent evt) {
public MainMenuUI() {
this.setVisible(false);
initComponents();
new CustListUI().setVisible(true);
}
}
private void
private void
mnuCustAddActionPerformed(java.awt.eve
ListItemActionPerformed(java.awt.event.A
nt.ActionEvent evt) {
ctionEvent evt) {
this.setVisible(false);
this.setVisible(false);
new ShopINUI().setVisible(true);}
new ItemListUI().setVisible(true); }
private void
private void
mnuItemAddActionPerformed(java.awt.eve
ListOrderActionPerformed(java.awt.event.
nt.ActionEvent evt) {
ActionEvent evt) {
this.setVisible(false);
this.setVisible(false);
new ItemINUI().setVisible(true);
new OrdListUI().setVisible(true);
}
}
private void
private void
mnuOrderActionPerformed(java.awt.event.
jMenu3ActionPerformed(java.awt.event.Ac
ActionEvent evt) {
tionEvent evt) {
this.setVisible(false);
// TODO add your handling code here: }
new OrderINUI().setVisible(true);}
private void
private void jMenuItem1ActionPerformed(java.awt.even
jMenu1ActionPerformed(java.awt.event.Ac t.ActionEvent evt) {
tionEvent evt) {
System.exit(0); // TODO add your
// TODO add your handling code here: handling code here:
} }
/**
* @param args the command line
arguments
*/
public static void main(String
args[]) {

java.awt.EventQueue.invokeLater(new }
Runnable() { });
public void run() { }
new
MainMenuUI().setVisible(true);
Frame: SHOPINUI

Coding of ShopINUI }
import java.sql.*; private void
import javax.swing.JOptionPane; btnBackActionPerformed(java.awt.event.
ActionEvent evt) {
public class ShopINUI extends
javax.swing.JFrame { this.setVisible(false);
new MainMenuUI().setVisible(true);
/** Creates new form ShopINUI */ }
public ShopINUI() { private void
btnSaveActionPerformed(java.a
initComponents();
wt.event.ActionEvent evt) { String shno =
try { txtSHno.getText().trim();
String shname =
Class.forName("com.mysql.jdbc.Driver"); txtSHName.getText();
Connection con = (Connection) String shadd =
txtSHAddress.getText();
DriverManager.getConnection("jdbc:mysql: String shcity = txtSHCity.getText();
//localhost:3306/shopkeeper","root","kvuc") double shphone =
; Double.parseDouble(txtSHPhone.getText())
Statement stmt = null; ;
ResultSet rs = null; // ResultSet if (shno.length() <= 4) {
for SHOPKEEPER table. String strSQL = "INSERT INTO
String SQL = "SELECT * FROM shopkeeper(Shopper_id, Name, Address,
shopkeeper"; City, Phone) VALUES ('"+(shno)+"','"+
(shname)+"','"+(shadd)+"','"+(shcity)+"',"+
stmt = con.createStatement(); //
(shphone)+")";
Connection string for ResultSet - rs.
rs = stmt.executeQuery(SQL);
JOptionPane.showMessageDialog(this,
"Record successfully inserted");
// Data transfer from JTextField control to
variables
int rowsEffected =
stmt.executeUpdate(strSQL);
System.out.println(rowsEffected + "
rows effected"); }
else {

JOptionPane.showMessageDialog(this, txtSHAddress.setText("");
"Customer ID should not more than 4 txtSHCity.setText("");
character.");}
txtSHPhone.setText("");}
con.close();
/**
} catch (Exception e) {
* @param args the command line
arguments
JOptionPane.showMessageDialog(this,e.get
*/
Message());
public static void main(String args[]) {
e.printStackTrace(); }
java.awt.EventQueue.invokeLater(new
}
Runnable() {
private void
public void run() {
btnClearActionPerformed(java.awt.event.A
ctionEvent evt) { new ShopINUI().setVisible(true);
}
// TODO add your handling code here:
});
txtSHno.setText("");
}
txtSHName.setText("");

Frame: ItemINUI.java

Coding for ItemINUI.java txtItemName.setText("");


import java.sql.*; txtItemDesc.setText("");
import javax.swing.JOptionPane; txtItemPrice.setText(""); }
public class ItemINUI extends private void
javax.swing.JFrame { btnSaveActionPerformed(java.awt.even
/** Creates new form ItemINUI */ t.ActionEvent evt) {
public ItemINUI() { try {
initComponents(); }
Class.forName("com.mysql.jdbc.Driver
private void
");
btnClearActionPerformed(java.awt.even
t.ActionEvent evt) { Connection con = (Connection)
// TODO add your handling code DriverManager.getConnection("jdbc:my
here: sql://localhost:3306/shopkeeper","root",
"kvuc");
txtItemno.setText("");
Statement stmt = null;
ResultSet rs = null; // System.out.println(rowsEffected
ResultSet for SHOPKEEPER table. + " rows effected");
String SQL = "SELECT * con.close();
FROM item"; } catch (Exception e) {
stmt = con.createStatement(); //
Connection string for ResultSet - rs. JOptionPane.showMessageDialog(this,e
rs = stmt.executeQuery(SQL); .getMessage());
// Data transfer from JTextField e.printStackTrace(); }
control to variables }
String itemno = private void
txtItemno.getText(); btnBackActionPerformed(java.awt.even
String itemname = t.ActionEvent evt) {
txtItemName.getText(); this.setVisible(false);
String desc = new
txtItemDesc.getText(); MainMenuUI().setVisible(true);}
double itemprice = /**
Double.parseDouble(txtItemPrice.getTe * @param args the command line
xt()); String strSQL = "INSERT arguments
INTO item(Item_Id, Item_Name,
Description, Price) VALUES */
public static void main(String args[])
{
('"+(itemno)+"','"+(itemname)+"','"+
(desc)+"',"+(itemprice)+")";
java.awt.EventQueue.invokeLater(new
Runnable() {
JOptionPane.showMessageDialog(this,
"Record successfully inserted"); public void run() {
int rowsEffected = new
stmt.executeUpdate(strSQL); ItemINUI().setVisible(true); }
});
}
Frame: OrderINUI.java
Coding for OrderINUI.Java

import javax.swing.DefaultListModel; txtOrdQty.setText("");


import java.sql.*; }
import javax.swing.JOptionPane;
public class OrderINUI extends private void
javax.swing.JFrame { btnBackActionPerformed(java.awt.even
t.ActionEvent evt) {
/** Creates new form OrderINUI */ this.setVisible(false);
public OrderINUI() { new
MainMenuUI().setVisible(true);
initComponents();
}
}
private void
btnClearActionPerformed(java.awt.even private void
t.ActionEvent evt) { btnSaveActionPerformed(java.awt.even
t.ActionEvent evt) {
// TODO add your handling code
here: try
{ Class.forName("com.mysql.jdbc
txtOrdno.setText("");
.Driver");
txtOrdDate.setText("");
Connection con = (Connection)
txtSID.setText(""); DriverManager.getConnection("jdbc:my
txtItemID.setText(""); sql://localhost:3306/shopkeeper","root",
txtSName.setText(""); "kvuc");
txtItemPrice.setText(""); Statement stmt = null;
ResultSet rs = null; //
ResultSet for SHOPKEEPER table. JOptionPane.showMessageDialog(this,
String SQL = "SELECT * "Order successfully placed");
FROM orderitem"; int rowsEffected =
stmt = con.createStatement(); // stmt.executeUpdate(strSQL);
Connection string for ResultSet - rs. System.out.println(rowsEffected
rs = stmt.executeQuery(SQL); + " rows effected");
con.close();
float discP = 0; // Discount } catch (Exception e) {
// Data transfer from JTextField
control to variables JOptionPane.showMessageDialog(this,e
.getMessage());
String Ordno =
txtOrdno.getText(); e.printStackTrace();
String OrdDate = }
txtOrdDate.getText(); }
String ItemID = private void
txtItemID.getText(); formWindowGainedFocus(java.awt.eve
String ShopID = nt.WindowEvent evt) {
txtSID.getText(); // Creating a ListModel object
String ItemPrice = sModel to perform DefaultListModel
txtItemPrice.getText(); // method operations for
double iPrice = Shopkeeper list
Double.parseDouble(txtItemPrice.getTe DefaultListModel sModel =
xt()); (DefaultListModel) jList1.getModel();
String ordQty =
txtOrdQty.getText(); // Creating a ListModel object
iModel to perform
if (rdYes.isSelected()) { DefaultComboBoxModel
discP = // method operations for Item list
Float.parseFloat(txtDisc.getText()); DefaultListModel iModel =
} (DefaultListModel) jList2.getModel();
else {
discP=0; } sModel.clear();
iModel.clear();
double amt = try {
(Integer.parseInt(txtOrdQty.getText()) *
Double.parseDouble(txtItemPrice.getTe Class.forName("com.mysql.jdbc.Driver
xt())) - ");
(Integer.parseInt(txtOrdQty.getText()) * Connection con = (Connection)
Double.parseDouble(txtItemPrice.getTe
xt()))*(discP*0.01);
DriverManager.getConnection("jdbc:my
String strSQL = "INSERT INTO sql://localhost:3306/shopkeeper","root",
orderitem(orderno, OrderDate, Item_Id, "kvuc");
Shopper_Id, Quantity, price, discount,
Amount ) VALUES ('"+(Ordno)+"','"+ Statement stmt = null;
(OrdDate)+"','"+(ItemID)+"','"+ ResultSet rs = null;
(ShopID)+"',"+(ordQty) ResultSet rs1 = null;
+","+iPrice+","+ discP+","+(amt)+")";
String SQL = "SELECT * String Sname=
FROM shopkeeper"; SidName.substring(6);
String SQL1 = "SELECT *
FROM item"; // Displays ID and name from
stmt = con.createStatement(); ComboBox1
// Steps to extract shopkeepers id txtSID.setText(Sid);
and name txtSName.setText(Sname); }
rs = stmt.executeQuery(SQL); private void
while (rs.next()) { jList2MouseClicked(java.awt.event.Mo
String sID = useEvent evt) {
rs.getString("Shopper_id"); try {
String Sname =
rs.getString("Name"); Class.forName("com.mysql.jdbc.Driver
sModel.addElement(sID + " - ");
" + Sname); Connection con = (Connection)
}
jList1.setModel(sModel); DriverManager.getConnection("jdbc:my
sql://localhost:3306/shopkeeper","root",
"kvuc");
// Steps to extract item id and
Statement stmt = null;
name
ResultSet rs = null;
rs1 = stmt.executeQuery(SQL1);
while (rs1.next()) {
// Extracting item id and item
String iID =
name into a variable ItemIDName
rs1.getString("Item_Id");
String ItemIDName = (String)
String Iname =
jList2.getSelectedValue();
rs1.getString("Item_Name");
String ItemID =
iModel.addElement(iID + " -
ItemIDName.substring(0, 3);
" + Iname);
String Iame=
}
ItemIDName.substring(7);
jList2.setModel(iModel);
txtItemID.setText(ItemID);
con.close();
String SQL = "SELECT *
} catch (Exception e) { FROM item where Item_Id = '"+
(ItemID)+"'";
JOptionPane.showMessageDialog(this,e stmt = con.createStatement();
.getMessage());
rs = stmt.executeQuery(SQL);
e.printStackTrace();
} }
while (rs.next()) {
double iprice =
private void rs.getDouble("Price");
jList1MouseClicked(java.awt.event.Mo
useEvent evt) {
txtItemPrice.setText(Double.toString(ip
// Extracting supplier id and name rice));}
into a variable SidName
con.close();
String SidName = (String)
} catch (Exception e) {
jList1.getSelectedValue();
String Sid =
SidName.substring(0, 3);
public static void main(String args[])
JOptionPane.showMessageDialog(this,e {
.getMessage());
e.printStackTrace(); } java.awt.EventQueue.invokeLater(new
} Runnable() {
/** public void run() {
* @param args the command line new
arguments OrderINUI().setVisible(true); }
*/ });
}

Frame: CustListUI.java

Coding of CustListUI.java
import javax.swing.table.*; * @author gagan
import java.sql.*; */
import javax.swing.JOptionPane; public class CustListUI extends
javax.swing.JFrame {
/*
* To change this template, choose Tools /** Creates new form CustListUI */
| Templates public CustListUI() {
* and open the template in the editor. initComponents();
*/ }
/*
* CustListUI.java /** This method is called from within
* the constructor to
* Created on Mar 18, 2010, 1:24:42 * initialize the form.
PM * WARNING: Do NOT modify this
*/ code. The content of this method is
* always regenerated by the Form
Editor.
/**
*/
*
@SuppressWarnings("unchecked")
// <editor-fold new Object [][] {
defaultstate="collapsed" {null, null, null, null, null},
desc="Generated Code"> {null, null, null, null, null},
private void initComponents() { {null, null, null, null, null},
{null, null, null, null, null}
jButton1 = new },
javax.swing.JButton();
new String [] {
jButton2 = new
javax.swing.JButton(); "Customer ID", "Name",
"Address", "City", "Phone"
jScrollPane1 = new
javax.swing.JScrollPane(); }
jTable1 = new ));
javax.swing.JTable();
jScrollPane1.setViewportView(jTable1);

setDefaultCloseOperation(javax.swing. javax.swing.GroupLayout layout =


WindowConstants.EXIT_ON_CLOSE); new
setTitle("Customers list"); javax.swing.GroupLayout(getContentPa
ne());

jButton1.setFont(new getContentPane().setLayout(layout);
java.awt.Font("Tahoma", 1, 12)); //
NOI18N layout.setHorizontalGroup(

jButton1.setText("Display/Query"); layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING)
jButton1.addActionListener(new
java.awt.event.ActionListener() {
.addGroup(layout.createSequentialGrou
public void p()
actionPerformed(java.awt.event.Action
Event evt) {
.addGroup(layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.LE
jButton1ActionPerformed(evt); ADING)
}
}); .addGroup(layout.createSequentialGrou
p()
jButton2.setText("Back to Menu"); .addContainerGap()
jButton2.addActionListener(new
java.awt.event.ActionListener() { .addComponent(jScrollPane1,
public void javax.swing.GroupLayout.DEFAULT_S
actionPerformed(java.awt.event.Action IZE, 587, Short.MAX_VALUE))
Event evt) {
.addGroup(layout.createSequentialGrou
jButton2ActionPerformed(evt); p()
} .addGap(171, 171, 171)
});
.addComponent(jButton1)
.addGap(38, 38, 38)
jTable1.setModel(new
javax.swing.table.DefaultTableModel(
.addComponent(jButton2)))
.addContainerGap()) String query = "SELECT * FROM
); shopkeeper";
layout.setVerticalGroup( try {
// Connect to MySQL database
layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING) Class.forName("com.mysql.jdbc.Driver
").newInstance();
.addGroup(layout.createSequentialGrou Connection con = (Connection)
p() DriverManager.getConnection("jdbc:my
.addComponent(jScrollPane1, sql://localhost:3306/shopkeeper","root",
javax.swing.GroupLayout.PREFERRE "kvuc");
D_SIZE, 172, // Create SQL statement and
javax.swing.GroupLayout.PREFERRE execute query.
D_SIZE) Statement stmt =
.addGap(35, 35, 35) con.createStatement();
ResultSet rs =
.addGroup(layout.createParallelGroup(j stmt.executeQuery(query);
avax.swing.GroupLayout.Alignment.B
ASELINE) // Iterate through the result and
.addComponent(jButton1) display on screen
.addComponent(jButton2)) while (rs.next()) {
.addContainerGap(19, String Sid =
Short.MAX_VALUE)) rs.getString("Shopper_id");
); String SName =
rs.getString("Name");
pack(); String SAddress =
}// </editor-fold> rs.getString("Address");
String SCity =
rs.getString("City");
private void
jButton1ActionPerformed(java.awt.eve String SPhone =
nt.ActionEvent evt) { rs.getString("Phone");
// Before writting the followng System.out.println(Sid + "|" +
line, you should import the line: SName + "|" + SAddress + "|" + SCity +
"|" + SPhone);
// import javax.swing.table.*; at the
top of your application model.addRow(new Object[]
{Sid, SName, SAddress, SCity,
DefaultTableModel model =
SPhone});
(DefaultTableModel)
jTable1.getModel(); }
// Clear the existing table } catch (Exception e) {
int rows = model.getRowCount();
JOptionPane.showMessageDialog(this,
if (rows > 0) {
e.getMessage());
for (int i = 0; i < rows; i++) {
}
model.removeRow(0);
}
}
}
private void
// SQL Query jButton2ActionPerformed(java.awt.eve
nt.ActionEvent evt) {
this.setVisible(false);
new java.awt.EventQueue.invokeLater(new
MainMenuUI().setVisible(true); Runnable() {
} public void run() {
new
CustListUI().setVisible(true);
/**
}
* @param args the command line
arguments });
*/ }
public static void main(String args[])
{

Frame: ItemListUI.java

Coding for ItemListUI.java


import javax.swing.table.*; * To change this template, choose Tools
import java.sql.*; | Templates
import javax.swing.JOptionPane; * and open the template in the editor.
*/
/*
/*
* ItemListUI.java
* setDefaultCloseOperation(javax.swing.
WindowConstants.EXIT_ON_CLOSE);
* Created on Mar 18, 2010, 1:45:12
PM setTitle("List of items in shop");
*/
jButton2.setText("Back to Menu");
/** jButton2.addActionListener(new
java.awt.event.ActionListener() {
*
public void
* @author gagan
actionPerformed(java.awt.event.Action
*/
Event evt) {
public class ItemListUI extends
javax.swing.JFrame {
jButton2ActionPerformed(evt);
}
/** Creates new form ItemListUI */
});
public ItemListUI() {
initComponents();
jButton1.setFont(new
} java.awt.Font("Tahoma", 1, 12));

/** This method is called from within jButton1.setText("Display/Query");


the constructor to jButton1.addActionListener(new
* initialize the form. java.awt.event.ActionListener() {
* WARNING: Do NOT modify this public void
code. The content of this method is actionPerformed(java.awt.event.Action
* always regenerated by the Form Event evt) {
Editor.
*/ jButton1ActionPerformed(evt);
@SuppressWarnings("unchecked") }
// <editor-fold });
defaultstate="collapsed"
desc="Generated Code"> jTable1.setModel(new
private void initComponents() { javax.swing.table.DefaultTableModel(
new Object [][] {
jButton2 = new {null, null, null, null},
javax.swing.JButton(); {null, null, null, null},
jButton1 = new {null, null, null, null},
javax.swing.JButton();
{null, null, null, null}
jScrollPane1 = new
},
javax.swing.JScrollPane();
new String [] {
jTable1 = new
javax.swing.JTable();
"Item ID", "Name", );
"Description", "Price" layout.setVerticalGroup(
}
)); layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING)
jScrollPane1.setViewportView(jTable1);
.addGroup(layout.createSequentialGrou
p()
javax.swing.GroupLayout layout =
new .addComponent(jScrollPane1,
javax.swing.GroupLayout(getContentPa javax.swing.GroupLayout.PREFERRE
ne()); D_SIZE, 172,
javax.swing.GroupLayout.PREFERRE
D_SIZE)
getContentPane().setLayout(layout);
.addGap(35, 35, 35)
layout.setHorizontalGroup(

.addGroup(layout.createParallelGroup(j
layout.createParallelGroup(javax.swing.
avax.swing.GroupLayout.Alignment.B
GroupLayout.Alignment.LEADING)
ASELINE)
.addComponent(jButton1)
.addGroup(layout.createSequentialGrou
p() .addComponent(jButton2))

.addGroup(layout.createParallelGroup(j .addContainerGap(javax.swing.GroupL
avax.swing.GroupLayout.Alignment.LE ayout.DEFAULT_SIZE,
ADING) Short.MAX_VALUE))
);
.addGroup(layout.createSequentialGrou
p() pack();
.addContainerGap() }// </editor-fold>

.addComponent(jScrollPane1, private void


javax.swing.GroupLayout.DEFAULT_S jButton2ActionPerformed(java.awt.eve
IZE, 564, Short.MAX_VALUE)) nt.ActionEvent evt) {
this.setVisible(false);
.addGroup(layout.createSequentialGrou
new
p()
MainMenuUI().setVisible(true);
.addGap(171, 171, 171)
}

.addComponent(jButton1)
private void
.addGap(38, 38, 38)
jButton1ActionPerformed(java.awt.eve
nt.ActionEvent evt) {
.addComponent(jButton2)))
// Before writting the followng
.addContainerGap()) line, you should import the line:
// import javax.swing.table.*; at the String ITid =
top of your application rs.getString("Item_id");
DefaultTableModel model = String IName =
(DefaultTableModel) rs.getString("Item_Name");
jTable1.getModel(); String IDesc =
// Clear the existing table rs.getString("Description");
int rows = model.getRowCount(); String IPrice =
if (rows > 0) { rs.getString("Price");
for (int i = 0; i < rows; i++) { System.out.println(ITid + "|"
+ IName + "|" + IDesc + "|" + IPrice);
model.removeRow(0);
model.addRow(new Object[]
}
{ITid, IName, IDesc, IPrice});
}
}
// SQL Query
} catch (Exception e) {
String query = "SELECT * FROM
Item";
JOptionPane.showMessageDialog(this,
try {
e.getMessage());
// Connect to MySQL database
}
}
Class.forName("com.mysql.jdbc.Driver
/**
").newInstance();
* @param args the command line
Connection con = (Connection)
arguments
DriverManager.getConnection("jdbc:my
sql://localhost:3306/shopkeeper","root", */
"kvuc"); public static void main(String args[])
// Create SQL statement and {
execute query.
Statement stmt = java.awt.EventQueue.invokeLater(new
con.createStatement(); Runnable() {
ResultSet rs = public void run() {
stmt.executeQuery(query); new
ItemListUI().setVisible(true);
// Iterate through the result and }
display on screen });}
while (rs.next()) {

Frame: OrdListUI.java
Coding for OrdListUI.java
import javax.swing.table.*; initComponents();
import java.sql.*; }
import javax.swing.JOptionPane;
/** This method is called from within
/* the constructor to
* To change this template, choose Tools * initialize the form.
| Templates * WARNING: Do NOT modify this
* and open the template in the editor. code. The content of this method is
*/ * always regenerated by the Form
Editor.
*/
/*
@SuppressWarnings("unchecked")
* OrdListUI.java
// <editor-fold
*
defaultstate="collapsed"
* Created on Mar 18, 2010, 1:50:20
desc="Generated Code">
PM
private void initComponents() {
*/

jButton2 = new
/**
javax.swing.JButton();
*
jButton1 = new
* @author gagan javax.swing.JButton();
*/ jScrollPane1 = new
public class OrdListUI extends javax.swing.JScrollPane();
javax.swing.JFrame { jTable1 = new
javax.swing.JTable();
/** Creates new form OrdListUI */
public OrdListUI() {
new String [] {
setDefaultCloseOperation(javax.swing. "Order No.", "Order Date",
WindowConstants.EXIT_ON_CLOSE); "Item Id", "Customer Id", "Quantity",
setTitle("List of orders"); "Price", "Discount(%)", "Amount"
}
jButton2.setText("Back to Menu"); ));
jButton2.addActionListener(new
java.awt.event.ActionListener() { jScrollPane1.setViewportView(jTable1);
public void
actionPerformed(java.awt.event.Action javax.swing.GroupLayout layout =
Event evt) { new
javax.swing.GroupLayout(getContentPa
jButton2ActionPerformed(evt); ne());
} });
getContentPane().setLayout(layout);
jButton1.setFont(new layout.setHorizontalGroup(
java.awt.Font("Tahoma", 1, 12)); //
NOI18N layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING)
jButton1.setText("Display/Query");
jButton1.addActionListener(new .addGroup(layout.createSequentialGrou
java.awt.event.ActionListener() { p()
public void
actionPerformed(java.awt.event.Action .addGroup(layout.createParallelGroup(j
Event evt) { avax.swing.GroupLayout.Alignment.LE
ADING)
jButton1ActionPerformed(evt);
.addGroup(layout.createSequentialGrou
}
p()
});
.addContainerGap()

jTable1.setModel(new
.addComponent(jScrollPane1,
javax.swing.table.DefaultTableModel(
javax.swing.GroupLayout.DEFAULT_S
new Object [][] { IZE, 588, Short.MAX_VALUE))
{null, null, null, null, null,
null, null, null}, .addGroup(layout.createSequentialGrou
{null, null, null, null, null, p()
null, null, null}, .addGap(171, 171, 171)
{null, null, null, null, null,
null, null, null}, .addComponent(jButton1)
{null, null, null, null, null, .addGap(38, 38, 38)
null, null, null}
}, .addComponent(jButton2)))
.addContainerGap()) DefaultTableModel model =
); (DefaultTableModel)
jTable1.getModel();
layout.setVerticalGroup(
// Clear the existing table
layout.createParallelGroup(javax.swing. int rows = model.getRowCount();
GroupLayout.Alignment.LEADING) if (rows > 0) {
for (int i = 0; i < rows; i++) {
.addGroup(layout.createSequentialGrou model.removeRow(0);
p() } }
.addComponent(jScrollPane1, // SQL Query
javax.swing.GroupLayout.PREFERRE
String query = "SELECT * FROM
D_SIZE, 172,
orderitem";
javax.swing.GroupLayout.PREFERRE
D_SIZE) try {
.addGap(35, 35, // Connect to MySQL database
35)
.addGroup(layout.createParallelGroup(j Class.forName("com.mysql.jdbc.Driver
avax.swing.GroupLayout.Alignment.B ").newInstance();
ASELINE) Connection con = (Connection)
.addComponent(jButton1) DriverManager.getConnection("jdbc:my
.addComponent(jButton2)) sql://localhost:3306/shopkeeper","root",
"kvuc");
.addContainerGap(20,
Short.MAX_VALUE)) // Create SQL statement and
execute query.
);
Statement stmt =
pack();
con.createStatement();
}// </editor-fold>
ResultSet rs =
stmt.executeQuery(query);
private void // Iterate through the result and
jButton2ActionPerformed(java.awt.eve display on screen
nt.ActionEvent evt) {
while (rs.next()) {
this.setVisible(false);
String Ordno =
new rs.getString("Orderno");
MainMenuUI().setVisible(true);
String Ordd =
} rs.getString("OrderDate");
private void String OItemid =
jButton1ActionPerformed(java.awt.eve rs.getString("Item_Id");
nt.ActionEvent evt) {
String OSid =
// Before writting the followng rs.getString("Shopper_Id");
line, you should import the line:
String OQty =
// import javax.swing.table.*; at the rs.getString("Quantity");
top of your application
String IPrice =
rs.getString("price");
String Disc = }}
rs.getString("discount"); /**
String OAmount = * @param args the command line
rs.getString("Amount"); arguments
System.out.println(Ordno + */
"|" + Ordd + "|" +OItemid + "|" + OSid public static void main(String args[])
+ "|" + OQty + "|" + IPrice + "|" + Disc {
+ "|" + OAmount);
model.addRow(new Object[] java.awt.EventQueue.invokeLater(new
{Ordno, Ordd, OItemid, OSid, OQty, Runnable() {
IPrice, Disc, OAmount});
public void run() {
}
new
} catch (Exception e) { OrdListUI().setVisible(true); }
});
JOptionPane.showMessageDialog(this,
}
e.getMessage());

QUIT

Coding of QUIT
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0); // TODO add your handling code here:
}
6. Bibliography

(1) http://www.mysql.org/

(2) http://www.netbeans.org/

(3) Informatics Practices for class XII


-by Sumita Arora
(4) Together with Informatics Practices

Potrebbero piacerti anche