Sunteți pe pagina 1din 71

Objective

The purpose of project is to develop a complete Store Management


System for general purpose use. This project is indented to design the
software for different product to maintain the information related to
product,customer, and daily transactions.

The project is about the activities of a product which are performed by


store staff. The store staff needs to manage the information about the
product in store , customer, purchase and sale.

The user can feed the symptoms through the form in the
window page. The system using mainly five type of activity like master
form, purchase form, sale form, purchase report, sale report.

This software provides easily maintain stock in hand and


easily identify product that is purchase and sale by particular person. To
provide the facility of sorting in sale and purchase report.
Project plan

The project is for STORE management is developed in java as the


front-end with MS-ACCESS as the back-end. It is an attempt to retrieve the
burden of manual system by providing a user friendly, fully automated and
secure system.

In the initial stage of my project, I properly understand the concept of


JAVA & MS-ACCESS under the proper guidance of my project incharge.
The analysis about the project is deeply made by group members and at
many time I was given sufficient information about the project.
Software and Hardware requirements

Software Requirement

Front End :- JAVA

Back End :- MS ACCESS

Operating System :- Window Xp, Window2000

Hardware Requirement

Processor :- 2.4 ghz

Ram :- 128 KB

Hard Disc Capacity :- 1 Gb


Functional module

 PURCHASING PRODUCT

 SALLING PRODUCT

 TO MAINTAIN PRODUCT IN MASTER TABLE

 REPORT RELATED TO PRODUCT (Customer, Product,


source,Hire date)
DATABASE FOR PROJECT

Table 1:-

Table 2:-
Table 3:-
Limitations

This project has all the primary modules which are needed by any
STORE management. This project can be used by any STORE but it has
some limitations such as if STORE usages bar-codes for books and
members, there is no such facility is available to generate bar-codes for
new books and members. This project is also unable to accept bar-codes
and scanning device for scanning the bar-coeds.

Instead of problem discussed above this project is very useful for the
STORE management. And this project can be accepted and run
successfully.
Future scope

The project “Store Management System” is having lot of scope in


future. This project can be used in many product such as product of Genral
store, Store of Firm product, and other private store etc.

This project completely automate the above given stock through the
use of computers instead of old manual system and thus increase the
efficiency of any store management.
ANALYSIS OF THE PROBLEM
AND
DEVELOPMENT OF THE SOLUTION

Computers are extremely versatile and finding their way into every
business, industry and research activity today. Computers have
dynamically changed the way of solving the problems.

We use software applications or create applications according to the need


and specifications of our own. The applications created are much more
interactive and easy to learn and use. The use of computers has reduced the
workload, manpower, time etc. and also increased the accuracy in our
results.

The software “STORE MANAGEMENT ” is based on the system of


managing inventory. Having complete jurisdiction over the operational
data, the administrator a.) Can ensure that the only means of access to the
database is through the proper channels, and, hence, b.) Can define
authorization checks to be carried out whenever access to sensitive data is
attempted. A check is established for unauthorized access, to each piece of
information by providing the password feature. The administrator can
change the password as and when required.

An effort was made to build the software but due to lack of time and
experience, some mistakes may creep in.
Feasibility Study

The main objective of the feasibility study is to test the technical,


operational, logical and economical feasibility of developing the
computerized system. . Given unlimited resources and infinite time, all
projects are feasible. Unfortunately, such results and time are not possible
in real life situations.
Hence, it becomes both necessary and prudent to evaluate the feasibility of
the project at the earliest possible time in order to avoid unnecessary
wastage of time, effort and professional embarrassment over an ill –
conceived system. Feasibility study is:

1 A test of system proposed regarding its workability.


2 Impact on the organization ability, to meet user who is familiar
with the information system techniques.
3 Understand the part of the business or organization that will be
involved or affected by the project, and are skilled in the system
analysis and design process.

It is both necessary and prudent to evaluate the feasibility of a project at


system study phase itself. The feasibility study conducted for this project
involves:

1 Technical Feasibility

2 Operational Feasibility

3 Economical Feasibility

4 Legal Feasibility

5 Technical Feasibility:
Technical feasibility includes risk, resource availability and technologies.
Technical feasibility is the most difficult area to assess at the earlier stage of
system development process. Therefore the process of analysis and
definition of the proposed system was conducted in parallel with the
assessment of technical feasibility. Since the misjudgment at this stage will
be disastrous a cynical attitude was maintained throughout the evaluation
of technical feasibility. The management provides latest hardware and
software facilities for the successful completion of the projects. With these
latest hardware and software support the system will perform extremely
well.

Operational Feasibility:
The development of the system was started because of the requirements
put forward by the management of the concerned end user. This system,
handles the large amount of data in a better way. So, it is sure that the
system developed is operationally feasible.

Economic Feasibility:
It is normal for every organization to choose a system development only if
there is a gain with respect to time and cost overhead. In the economic
feasibility the development cost of the system is evaluated weighing it
against the ultimate benefit derived from the new system. It is found that
the benefit occurred from the new system is more than that cost and time
involved in its development.
Legal Feasibility:
In this feasibility it is checked that whether the system could be
implemented or not within the stipulated time.

CHOICE OF THE LANGUAGE

For making this “STORE MANAGEMENT ” software, I have used


JAVA1.5 as Front-end tool and MS-Access as Back end tool.

FEATURES OF JAVA:

JAVA IS OBJECT-ORIENTED:
In object-oriented programming (OOP), data is treated as objects to which
methods are applied. Java's basic execution unit is the class.

JAVA IS DISTRIBUTED:
Commonly used Internet protocols such as HTTP and FTP as well as calls
for network access are built into Java. Internet programmers can call on the
functions through the supplied libraries and be able to access files on the
Internet as easily as writing to a local file system.

JAVA IS INTERPRETED:
When Java code is compiled, the compiler outputs the Java Byte code
which is an executable for the Java Virtual Machine. The byte code is then
run through a Java interpreter on any given platform that has the
interpreter ported to it. The interpreter converts the code to the target
hardware and executes it.

JAVA IS SECURE:
Java goes to great lengths to address these security issues by putting in
place a very rigorous multilevel system of security:
First and foremost, at compile time, pointers and memory allocation are
removed thereby eliminating the tools that a system breaker could use to
gain access to system resources. Memory allocation is deferred until
runtime.
Even though the Java compiler produces only correct Java code, there is
still the possibility of the code being tampered with between compilation
and runtime. Java guards against this by using the byte code verifier to
check the byte code for language compliance when the code first enters the
interpreter, before it ever even gets the chance to run.

At runtime, the Java interpreter further ensures that classes loaded do not
access the file system except in the manner permitted by the client or the
user.

JAVA IS PORTABLE:
By porting an interpreter for the Java Virtual Machine to any computer
hardware/operating system, one is assured that all code compiled for it will
run on that system. This forms the basis for Java's portability.

JAVA IS HIGH-PERFORMANCE PROVIDER:


The Java language supports many high-performance features such as
multithreading, just-in-time compiling, and native code usage.

JAVA IS DYNAMIC:
By connecting to the Internet, a user immediately has access to thousands
of programs and other computers. During the execution of a program, Java
can dynamically load classes that it requires either from the local hard
drive, from another computer on the local area network or from a
computer somewhere on the Internet.

FEATURES OF MS-ACCESS:
Microsoft Access is a computer application used to create and manage
computer-based databases on desktop computers and/or on connected
computers (a network). Microsoft Access can be used for personal
information management (PIM), in a small business to organize and
manage all data, or in an enterprise to communicate with servers.
SYSTEM ANALYSIS AND DESIGN

SYSTEM ANALYSIS:

System analysis is a detailed study of the various operation performed by a


system and their relationships with in and outside the system.

It is a term used to describe the process of calculation and analyze facts in


respective to existing operation of prevailing situation so that an effective
computerized system may be designed.

During analysis, data are collected on the available files, decision points
and transactions handled by the present system. In this phase a detailed
evaluation of present system is done.

SYSTEM DESIGN:

It is the most creative and challenging phase of a system life cycle. It


describes a final system and process by which it is developed.

What does A Design Implies?

1 It refers to the technical specifications that will be applied in


implementing the system.

2 It includes the construction of programs and program testing.

3 It also includes general design specifications and detailed


design specification.
SYSTEM TESTING
Testing is vital to the success of any system. It makes a logical assumption
that if all the parts of the system are correct, the goal will be successfully
achieved. A system is tested to see whether it produces the correct outputs.
No other test is more crucial than system testing. The purpose of the
system testing is to identify and correct the errors in the candidate system.
In system testing performance and acceptance standards are developed.

Testing is done not only from the technical point of view but also from the
usability side. In addition, it is done to ascertain that the presentation is
readable in multiple browsers.

LEVEL OF TESTING:

The basic levels are unit testing, integration testing and acceptance testing.
These different levels of testing attempt to detect different types of faults.

· Unit testing: the level of the testing is called unit testing. In this
different modules are tested against the specifications produced during the
design modules. Unit testing is essentially for the verification of the code.
· Integration testing: the next level of the testing is the integration
testing. In this, many tested modules are combined into sub-systems that
are then tested. The goal here is to see if the modules can be integrated
properly.
· System Testing and Acceptance Testing: here the entire software
system is tested. The reference document for this process is the
requirement document, and is to see if the software meets its requirement.
SYSTEM IMPLEMENTATION
A crucial phase in system development is the successful implementation of
the new system design. Implementation means converting a new system
design into operation. This involves creation of computer-compatible files,
installing hardware, terminals etc before the system is running. This phase
is less creative than system design.

One of the aspects of implementation is conversion others include post-


implementation review and software review. System implementation
mainly focuses on user training, site preparation and file conversion.
Source Code
Main class
public class Welc extends Frame implements ActionListener
{
Toolkit t;
Image im;
Label l1,l2,l3,l4,l5;
TextField t1,t2;
Font f;
Button b1,b2;
Welc()
{
super("WELCOME TO STORE MANAGEMENT SYSTEM");
l1=nimport java.awt.*;
import javax.swing.*;
import java.awt.event.*;
ew Label("Login ID ");
l2=new Label("Password.");
l3=new Label("Developed by : TEAM A");
l4=new Label("MCA IV Semester ");
l5=new Label(" Institute of Management & research ,Ghaziabad");
t1 = new TextField(20);
t2 = new TextField(20);
b1 = new Button("Enter");
b2 = new Button("Cancel");
t2.setEchoChar('*');
f = new Font("Courier New",1,20);
l1.setForeground(Color.red);
l2.setForeground(Color.red);
l3.setForeground(Color.black);
l4.setForeground(Color.black);
l5.setForeground(Color.black);
t1.setForeground(Color.black);
t2.setForeground(Color.black);
b1.setForeground(Color.red);
b2.setForeground(Color.red);
t1.setBackground(Color.white);
t2.setBackground(Color.white);
b1.setBackground(new Color(192,192,192));
b2.setBackground(new Color(192,192,192));
setBackground(new Color(255,190,125));
//setBackground(Color.pink);
l1.setFont(f);
l2.setFont(f);
t1.setFont(f);
t2.setFont(f);
b1.setFont(f);
b2.setFont(f);
l3.setFont(f);
l4.setFont(f);
l5.setFont(f);
b1.addActionListener(this);
b2.addActionListener(this);
l1.setBounds(220,270,80,30);
l2.setBounds(220,330,100,30);
l3.setBounds(50,450,300,30);
l4.setBounds(310,490,400,30);
l5.setBounds(160,520,700,30);
t1.setBounds(350,270,200,30);
t2.setBounds(350,330,150,30);
b1.setBounds(270,390,100,30);
b2.setBounds(390,390,100,30);
setLayout(null);
add(l1);
add(l2);
add(l3);
add(l4);
add(t1);
add(t2);
add(b1);
add(b2);
add(l5);
t = getToolkit();
im = t.getImage("visacard.jpg");
setSize(800,800);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o==b1)
{
String ss=t2.getText();
String login=t1.getText();
if(!login.equalsIgnoreCase("DEEPAK"))
{
JOptionPane.showMessageDialog(Welc.this,"I n v a l i d L o g i n . . . C
l i c k O K "," A c c e s s D e n i e d ",JOptionPane.WARNING_MESSAGE);
}
else if(!ss.equalsIgnoreCase("DEEPAK"))
{
JOptionPane.showMessageDialog(Welc.this,"I n v a l i d P a s s w o r d
. . . C l i c k O K "," A c c e s s D e n i e d
",JOptionPane.WARNING_MESSAGE);
}

if((ss.equalsIgnoreCase("DEEPAK"))&&(login.equalsIgnoreCase("DEEPAK")))
{
MenuApp aa = new MenuApp();
aa.setSize(780,570);
aa.setVisible(true);
hide();
}
}
else if(o==b2)
{
int x = JOptionPane.showConfirmDialog(Welc.this,"A r e y o u s u r e y
o u w a n t t o E x i t ! "," C o n f i r m a t i o
n",JOptionPane.WARNING_MESSAGE,JOptionPane.YES_NO_OPTION);
if(x==0)
{
hide() ;
System.exit(0);
}
}
}
public void paint(Graphics g)// = getGraphics();
{
g.drawImage(im,180,110,500,100,this);
}

public static void main(String aa[])


{
Welc w = new Welc();
}
}
Purchase form
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class Purc extends JFrame
{
Container f;
JTextField t1 = new JTextField("0",10);
JTextField t2 = new JTextField(20);
JTextField t3 = new JTextField(20);
JTextField t4 = new JTextField(20);
JTextField t5 = new JTextField(20);
JTextField t6 = new JTextField(20);
JTextField t7 = new JTextField(20);
Font fo = new Font("Courier New",1,17);
JLabel l1 = new JLabel("Prod Code :");
JLabel l2 = new JLabel("Prod Name :");
JLabel l3 = new JLabel("Quantity :");
JLabel l4 = new JLabel("Proc. Date:");
JLabel l5 = new JLabel("Unit Price:");
JLabel l6 = new JLabel("Tot Price :");
JLabel l7 = new JLabel("Source :");
JButton b1 = new JButton("Submit");
JButton b2 = new JButton("Cancel");
JButton b3 = new JButton("Exit");
public static void main(String args[])
{
Purc app = new Purc();
}
public Purc()
{
super("Procurement");
b1.setBackground(new Color(208,208,255));
b2.setBackground(new Color(208,208,255));
b3.setBackground (new Color(208,208,255));
l1.setFont(fo);
l2.setFont(fo);
l3.setFont(fo);
l4.setFont(fo);
l5.setFont(fo);
l6.setFont(fo);
l7.setFont(fo);
b1.setFont(fo);
b2.setFont(fo);
b3.setFont(fo);
t1.setFont(fo);
t2.setFont(fo);
t3.setFont(fo);
t4.setFont(fo);
t5.setFont(fo);
t6.setFont(fo);
t7.setFont(fo);

t1.setForeground(Color.magenta);
t2.setForeground(Color.magenta);
t1.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
String ss = t1.getText();
checkRec(ss);
}
});

t3.setForeground(Color.magenta);
t4.setForeground(Color.magenta);
t5.setForeground(Color.magenta);
t6.setForeground(Color.magenta);
t7.setForeground(Color.magenta);
b1.addActionListener(new ButtonHandler());
b2.addActionListener(new ButtonHandler());
b3.addActionListener(new ButtonHandler());
t5.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
double x = Double.valueOf(t3.getText()).doubleValue();
double y = Double.valueOf(t5.getText()).doubleValue();
t6.setText(""+(x*y));
}
});
f=getContentPane();
f.setBackground(new Color(255,215,255));
f.setLayout(null);
l1.setBounds(60,50,160,30);
l2.setBounds(60,100,160,30);
l3.setBounds(60,150,160,30);
l4.setBounds(60,200,160,30);
l5.setBounds(60,250,160,30);
l6.setBounds(60,300,160,30);
l7.setBounds(60,350,160,30);
t1.setBounds(210,50,70,30);
t2.setBounds(210,100,200,30);
t3.setBounds(210,150,100,30);
t4.setBounds(210,200,140,30);
t5.setBounds(210,250,90,30);
t6.setBounds(210,300,100,30);
t7.setBounds(210,350,180,30);
b1.setBounds(50,420,120,30);
b2.setBounds(190,420,105,30);
b3.setBounds(310,420,100,30);
f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(l6);
f.add(l7);
f.add(t1);
t1.setToolTipText("Enter Product Code");
f.add(t2);
t2.setToolTipText("Enter Product Name");
f.add(t3);
t3.setToolTipText("Enter Quantity ");
f.add(t4);
t4.setToolTipText("Enter Proc Date(dd/mm/yyyy)");
f.add(t5);
t5.setToolTipText("Enter Unit Price ");
f.add(t6);
t6.setEditable(false);
f.add(t7);
t7.setEditable(true);
t7.setToolTipText("Enter source ");
f.add(b1);
b1.setToolTipText("Click here to submit data");
f.add(b2);
b3.setToolTipText("Click here to cancel data");
f.add(b3);
b3.setToolTipText("Click here to unload the current form");
pack();
addWindowListener(new WindowEventHandler());
}
void accessDB()
{
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
Statement s,s1,s2,s3;
s= connection.createStatement();
String sql;
sql = "INSERT INTO purchase VALUES ("+t1.getText()+",'"+t2.getText()
+"'";
sql+=","+t3.getText()+",'"+t4.getText();
sql+="',"+t5.getText()+","+t6.getText();
sql+=",'"+t7.getText()+"')";
boolean hasResults = s.execute(sql);
s1= connection.createStatement();
s2= connection.createStatement();
s3= connection.createStatement();
boolean ss = s1.execute("select * from master where itemcode =
"+t1.getText());
if(ss==true)
{
int i= s2.executeUpdate("update master set
stockinhand=stockinhand+"+t3.getText()+",purchasedate='"+t4.getText()
+"',price="+t5.getText()+" where itemcode = "+t1.getText());
if(i==0)
{
s3.execute("INSERT INTO master VALUES("+t1.getText()
+",'"+t2.getText()+"','"+t4.getText()+"','"+t3.getText()+"',"+t5.getText()+")");
}
}
connection.close();
}
catch(Exception ex)
{
System.out.println("sanaman"+ex);
}
}
boolean checkRec(String xx)
{
int x1=0;
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
Connection c1=DriverManager.getConnection(url);
Statement s3;
s3 = c1.createStatement();
s3.execute("select * from master where itemcode="+xx);
ResultSet rs1 = s3.getResultSet();
if(rs1!=null)
{
while(rs1.next())
{
if(xx.equals(rs1.getString(1)))
{
x1=1;
t2.setText(rs1.getString(2));
}
}
}
}
catch(Exception e){System.out.println("--> "+e);}
if(x1==1)
return(true);
else
return(false);
}

class ButtonHandler implements ActionListener


{
public void actionPerformed(ActionEvent ev)
{
String s=ev.getActionCommand();
if(s=="Submit")
{
String ss = t1.getText();
boolean flag = checkRec(ss);
if(flag)
{
int x = JOptionPane.showConfirmDialog(Purc.this,"Prod. Already
Exists,Want to Cont..."," C o n f i r m a t i o
n",JOptionPane.WARNING_MESSAGE,JOptionPane.YES_NO_OPTION);
if(x==0)
{
accessDB();
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
else if(x==1)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
}
else
{
accessDB();
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");

}
}
if(s=="Exit")
{
int x = JOptionPane.showConfirmDialog(Purc.this,"A r e y o u s u r e y
o u w a n t t o E x i t ! "," C o n f i r m a t i o
n",JOptionPane.WARNING_MESSAGE,JOptionPane.YES_NO_OPTION);
if(x==0)
hide() ;
}
if(s=="Cancel")
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
t5.setText(" ");
t6.setText(" ");
t7.setText(" ");
}
}
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
hide();
}
}
}
Sales form
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class Sale extends JFrame
{
int index;
Container f;
int i,x;
String driver,url;
Connection c;
Statement s,s1;
String rr1[],rr2[],rr3[],rr4[],rr5[],rr6[],rr7[],rr8[];
boolean flag = false;
boolean flag1 = false;

String data[];
JList t1;
Font fo = new Font("Courier New",1,17);

JTextField t2 = new JTextField(20);


JTextField t3 = new JTextField(20);
JTextField t4 = new JTextField(20);
JTextField t5 = new JTextField(20);
JTextField t6 = new JTextField(20);
JTextField t7 = new JTextField(20);
JTextField t8 = new JTextField(20);

JLabel l1 = new JLabel("Prod Code :");


JLabel l2 = new JLabel("Prod Name :");
JLabel l3 = new JLabel("No of item:");
JLabel l4 = new JLabel("Date :");
JLabel l5 = new JLabel("Cust name :");
JLabel l6 = new JLabel("Bill no :");
JLabel l7 = new JLabel("Unit Price:");
JLabel l8 = new JLabel("Tot Price :");

JButton b1 = new JButton("Submit");


JButton b2 = new JButton("Cancel");
JButton b3 = new JButton("Exit");
JButton bb1 = new JButton("First");
JButton bb2 = new JButton("Last");
JButton bb3 = new JButton("Prev.");
JButton bb4 = new JButton("Next");
public static void main(String args[])
{
Sale app = new Sale();
}
public Sale()
{
super("Sale");
x=0;
i=0;
l1.setFont(fo);
l2.setFont(fo);
l3.setFont(fo);
l4.setFont(fo);
l5.setFont(fo);
l6.setFont(fo);
l7.setFont(fo);
l8.setFont(fo);

bb1.setFont(fo);
bb2.setFont(fo);
bb3.setFont(fo);
bb4.setFont(fo);
b1.setFont(fo);
b2.setFont(fo);
b3.setFont(fo);

t2.setFont(fo);
t3.setFont(fo);
t4.setFont(fo);
t5.setFont(fo);
t6.setFont(fo);
t7.setFont(fo);
t8.setFont(fo);

b1.setBackground(new Color(215,254,171));
b2.setBackground(new Color(215,254,171));
b3.setBackground(new Color(215,254,171));
b1.setForeground(Color.black);
b2.setForeground(Color.black);
b3.setForeground(Color.black);
t1 = new JList(data);
t1.setFont(fo);

t1.setForeground(new Color(0,48,96));
t2.setForeground(new Color(0,48,96));
t3.setForeground(new Color(0,48,96));
t4.setForeground(new Color(0,48,96));
t5.setForeground(new Color(0,48,96));
t6.setForeground(new Color(0,48,96));
t7.setForeground(new Color(0,48,96));
t8.setForeground(new Color(0,48,96));

bb1.setBackground(new Color(215,254,171));
bb2.setBackground(new Color(215,254,171));
bb3.setBackground(new Color(215,254,171));
bb4.setBackground(new Color(215,254,171));
b1.addActionListener(new ButtonHandler());
b2.addActionListener(new ButtonHandler());
b3.addActionListener(new ButtonHandler());
bb1.addActionListener(new ButtonHandler());
bb2.addActionListener(new ButtonHandler());
bb3.addActionListener(new ButtonHandler());
bb4.addActionListener(new ButtonHandler());
checkRec3();
t1=new JList(data);
t1.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
String ss=(String)t1.getSelectedValue();
checkRec4(ss);
rec();
}
});
t2.addFocusListener(new FocusAdapter()
{/*for quantity sold*/
public void focusLost(FocusEvent e1)
{
int cc=0;
String y1 = t2.getText();
for(int i=0;i<y1.length();i++)
{
int c = (int)y1.charAt(i);
if(c<48 || c>=57)
cc=1;
}
if(cc==1)
{
JOptionPane.showMessageDialog(Sale.this,"Please Enter Only 0 to 9
Number ....","Data Validation",JOptionPane.WARNING_MESSAGE);
}
else
{
String ss=(String)t1.getSelectedValue();
checkRec2(ss);
// System.out.println(ss);
}
}
});
JScrollPane sc=new JScrollPane(t1);
f=getContentPane();
f.setLayout(null);
f.setBackground(new Color(217,236,255));
l1.setBounds(100,50,160,30);
l2.setBounds(100,100,160,30);
l3.setBounds(100,150,160,30);
l4.setBounds(100,200,160,30);
l5.setBounds(100,250,160,30);
l6.setBounds(100,300,160,30);
l7.setBounds(100,350,160,30);
l8.setBounds(100,400,160,30);

sc.setBounds(235,50,80,25);

t8.setBounds(235,100,200,30);
t2.setBounds(235,150,100,30);
t3.setBounds(235,200,140,30);
t4.setBounds(235,250,200,30);
t5.setBounds(235,300,100,30);
t6.setBounds(235,350,100,30);
t7.setBounds(235,400,120,30);

b1.setBounds(50,460,100,30);
b2.setBounds(170,460,100,30);
b3.setBounds(290,460,100,30);

bb1.setBounds(530,120,120,35);
bb2.setBounds(530,190,120,35);
bb3.setBounds(530,260,120,35);
bb4.setBounds(530,330,120,35);

f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(l6);
f.add(l7);
f.add(l8);
f.add(sc);
t1.setToolTipText("Product Code");
f.add(t2);
t2.setToolTipText("Enter Product sold");
f.add(t3);
t3.setToolTipText("Enter Date");
f.add(t4);
t4.setToolTipText("Enter Customer name");
f.add(t5);
t5.setToolTipText("Bill no");
t5.setEditable(false);
f.add(t6);
t6.setToolTipText("Unit price");
f.add(t7);
t7.setToolTipText("Total price");
f.add(t8);
t8.setEditable(false);
t8.setToolTipText("Product Name");
f.add(b1);
b1.setToolTipText("Click here to submit data");
f.add(b2);
b3.setToolTipText("Click here to cancel data");
f.add(b3);
b3.setToolTipText("Click here to unload the current form");
f.add(bb1);
bb1.setToolTipText("Click here to view the First Record");
f.add(bb2);
bb2.setToolTipText("Click here to view the Last Record");
f.add(bb3);
bb3.setToolTipText("Click here to view the Prev Record");
f.add(bb4);
bb4.setToolTipText("Click here to view the Next Record");
pack();
addWindowListener(new WindowEventHandler());
setSize(800,600);
show();
rec();
t5.setText(""+index);
}
void accessDB()/*to insert data into DB*/
{
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s=c.createStatement();
String sql;
sql = "INSERT INTO sale VALUES ("+(String)t1.getSelectedValue()
+",'"+t8.getText()+"',"+t2.getText()+","+"'"+t3.getText()+"','"+t4.getText()
+"',"+t5.getText()+","+t6.getText()+","+t7.getText()+")";
boolean hasResults = s.execute(sql);
int i= s.executeUpdate("update master set
stockinhand=stockinhand-"+t2.getText()+" where itemcode = "+
(String)t1.getSelectedValue());
c.close();
}
catch(Exception ex)
{
}
}

//to put itemcode in the listbox


void checkRec3()
{
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select itemcode from master");
ResultSet r = s1.getResultSet();
if(r!=null)
{
ResultSetMetaData rmeta = r.getMetaData();
int counts=rmeta.getColumnCount();
data = new String[200];
int oo=0;
while(r.next())
{
data[oo]=r.getString(1);
// System.out.println(data[oo]);
oo++;
}
t1=new JList(data);
t1.setVisibleRowCount(2);
}
}
catch(Exception e){System.out.println("--> "+e);}
}/*for getting tot price & sale price*/
void checkRec2(String xx)
{
try
{
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select * from master");
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
if(rs.getString(1).equals(xx))
{
double ff = Double.valueOf(rs.getString(5)).doubleValue();
ff=ff*.10+ff;
t6.setText(""+ff);
float tot = Float.valueOf(t2.getText()).floatValue();
t7.setText(""+tot*ff);
}
}
}
}
catch(Exception e){System.out.println("--> "+e);}
java.util.Date date = new java.util.Date();
t3.setText(date.getDate()+"/"+(date.getMonth()+1)+"/2005");

}/*for getting item namr*/


void checkRec4(String xx)
{
try
{
java.util.Date date = new java.util.Date();
t3.setText(date.getDate()+"/"+(date.getMonth()+1)+"/2005");
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";

Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select Itemname from master where itemcode="+xx);
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
t8.setText(rs.getString(1));
}
}
}
catch(Exception e){System.out.println("--> "+e);}
}/*for putting limitations on sold quantity*/
boolean checkRec1(String xx)
{
int x=0;
try
{
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select stockinhand from master where itemcode="+xx);
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
int sc=Integer.parseInt(rs.getString(1));
if(sc<=10)
{
x=1;
}
if(sc<=Integer.parseInt(t2.getText()))
flag1=true;
else
flag1=false;
}
}
}
catch(Exception e){System.out.println("--> "+e);}
if(x==1)
return(true);
else
return(false);
}/*to put records in array & getting the bill no.*/
boolean rec()
{
i=0;
x=0;
index=1;
try
{
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s = c.createStatement();
s.execute("select * from sale ORDER BY bill_No");
ResultSet rs = s.getResultSet();
rr1 = new String[300];
rr2 = new String[300];
rr3 = new String[300];
rr4 = new String[300];
rr5 = new String[300];
rr6 = new String[300];
rr7 = new String[300];
rr8 = new String[300];

while(rs.next())
{
index++;
rr1[i]=rs.getString(1);
rr2[i]=rs.getString(2);
rr3[i]=rs.getString(3);
// for Date Column
String ss = rs.getString(4);
char arr[]=new char[10];
arr[0]=ss.charAt(8);
arr[1]=ss.charAt(9);
arr[2]='/';
arr[3]=ss.charAt(5);
arr[4]=ss.charAt(6);
arr[5]='/';
arr[6]=ss.charAt(0);
arr[7]=ss.charAt(1);
arr[8]=ss.charAt(2);
arr[9]=ss.charAt(3);
ss = new String(arr);
rr4[i]=ss;

rr5[i]=rs.getString(5);
rr6[i]=rs.getString(6);
rr7[i]=rs.getString(7);
rr8[i]=rs.getString(8);
x=i;
i++;
}
}
catch(Exception e){System.out.println(" --> "+e);}
t5.setText(""+index);
return(true);
}/*to show records in the textfields*/
void showRec(int a)
{
t1.setSelectedValue(rr1[a],true);
t2.setText(rr3[a]);
t3.setText(rr4[a]);
t4.setText(rr5[a]);
t5.setText(rr6[a]);
t6.setText(rr7[a]);
t7.setText(rr8[a]);
t8.setText(rr2[a]);
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
String s=ev.getActionCommand();
if(s=="Submit")
{
String ss = (String)t1.getSelectedValue();
boolean fla1 = checkRec1(ss);
if(fla1)
{
MyDialog d = new MyDialog(Sale.this,"Data Validation","Cannot Sell as
Instock<10 units");
d.setVisible(false);
}
if(flag1)
{
MyDialog d = new MyDialog(Sale.this,"Data Validation","Cannot
Sell as Instock<Items to be Sold....");
d.setVisible(false);
}
else
{
accessDB();
rec();
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText(""+index);
t6.setText("");
t7.setText("");
t8.setText("");

}
}
if(s=="Exit")
{
int x = JOptionPane.showConfirmDialog(Sale.this,"A r e y o u s u r e y
o u w a n t t o E x i t ! "," C o n f i r m a t i o
n",JOptionPane.WARNING_MESSAGE,JOptionPane.YES_NO_OPTION);
if(x==0)
hide() ;
}
if(s=="Cancel")
{
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");

}
if(s.equals("Next"))
{
x++;
if(x>=i)
{
x=i-1;
JOptionPane.showMessageDialog(Sale.this,"I t i s t h e L a s t R e c o r
d . . . ","Data Validation",JOptionPane.WARNING_MESSAGE);
}
showRec(x);
}
if(s.equals("Prev."))
{
x--;
if(x<=0)
{
x=0;
JOptionPane.showMessageDialog(Sale.this,"I t i s t h e F i r s t R e c o
r d . . . ","Data Validation",JOptionPane.WARNING_MESSAGE);
}
showRec(x);
}
if(s.equals("First"))
{
x=0;
showRec(x);
}
if(s.equals("Last"))
{
x=i-1;
showRec(x);
}
}
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
setVisible(true);
}
}

}
Report form

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class Sale extends JFrame
{
int index;
Container f;
int i,x;
String driver,url;
Connection c;
Statement s,s1;
String rr1[],rr2[],rr3[],rr4[],rr5[],rr6[],rr7[],rr8[];
boolean flag = false;
boolean flag1 = false;

String data[];
JList t1;
Font fo = new Font("Courier New",1,17);

JTextField t2 = new JTextField(20);


JTextField t3 = new JTextField(20);
JTextField t4 = new JTextField(20);
JTextField t5 = new JTextField(20);
JTextField t6 = new JTextField(20);
JTextField t7 = new JTextField(20);
JTextField t8 = new JTextField(20);

JLabel l1 = new JLabel("Prod Code :");


JLabel l2 = new JLabel("Prod Name :");
JLabel l3 = new JLabel("No of item:");
JLabel l4 = new JLabel("Date :");
JLabel l5 = new JLabel("Cust name :");
JLabel l6 = new JLabel("Bill no :");
JLabel l7 = new JLabel("Unit Price:");
JLabel l8 = new JLabel("Tot Price :");

JButton b1 = new JButton("Submit");


JButton b2 = new JButton("Cancel");
JButton b3 = new JButton("Exit");
JButton bb1 = new JButton("First");
JButton bb2 = new JButton("Last");
JButton bb3 = new JButton("Prev.");
JButton bb4 = new JButton("Next");
public static void main(String args[])
{
Sale app = new Sale();
}
public Sale()
{
super("Sale");
x=0;
i=0;
l1.setFont(fo);
l2.setFont(fo);
l3.setFont(fo);
l4.setFont(fo);
l5.setFont(fo);
l6.setFont(fo);
l7.setFont(fo);
l8.setFont(fo);

bb1.setFont(fo);
bb2.setFont(fo);
bb3.setFont(fo);
bb4.setFont(fo);
b1.setFont(fo);
b2.setFont(fo);
b3.setFont(fo);

t2.setFont(fo);
t3.setFont(fo);
t4.setFont(fo);
t5.setFont(fo);
t6.setFont(fo);
t7.setFont(fo);
t8.setFont(fo);

b1.setBackground(new Color(215,254,171));
b2.setBackground(new Color(215,254,171));
b3.setBackground(new Color(215,254,171));
b1.setForeground(Color.black);
b2.setForeground(Color.black);
b3.setForeground(Color.black);
t1 = new JList(data);
t1.setFont(fo);

t1.setForeground(new Color(0,48,96));
t2.setForeground(new Color(0,48,96));
t3.setForeground(new Color(0,48,96));
t4.setForeground(new Color(0,48,96));
t5.setForeground(new Color(0,48,96));
t6.setForeground(new Color(0,48,96));
t7.setForeground(new Color(0,48,96));
t8.setForeground(new Color(0,48,96));

bb1.setBackground(new Color(215,254,171));
bb2.setBackground(new Color(215,254,171));
bb3.setBackground(new Color(215,254,171));
bb4.setBackground(new Color(215,254,171));
b1.addActionListener(new ButtonHandler());
b2.addActionListener(new ButtonHandler());
b3.addActionListener(new ButtonHandler());
bb1.addActionListener(new ButtonHandler());
bb2.addActionListener(new ButtonHandler());
bb3.addActionListener(new ButtonHandler());
bb4.addActionListener(new ButtonHandler());
checkRec3();
t1=new JList(data);
t1.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
String ss=(String)t1.getSelectedValue();
checkRec4(ss);
rec();
}
});
t2.addFocusListener(new FocusAdapter()
{/*for quantity sold*/
public void focusLost(FocusEvent e1)
{
int cc=0;
String y1 = t2.getText();
for(int i=0;i<y1.length();i++)
{
int c = (int)y1.charAt(i);
if(c<48 || c>=57)
cc=1;
}
if(cc==1)
{
JOptionPane.showMessageDialog(Sale.this,"Please Enter Only 0 to 9
Number ....","Data Validation",JOptionPane.WARNING_MESSAGE);
}
else
{
String ss=(String)t1.getSelectedValue();
checkRec2(ss);
// System.out.println(ss);
}
}
});
JScrollPane sc=new JScrollPane(t1);
f=getContentPane();
f.setLayout(null);
f.setBackground(new Color(217,236,255));
l1.setBounds(100,50,160,30);
l2.setBounds(100,100,160,30);
l3.setBounds(100,150,160,30);
l4.setBounds(100,200,160,30);
l5.setBounds(100,250,160,30);
l6.setBounds(100,300,160,30);
l7.setBounds(100,350,160,30);
l8.setBounds(100,400,160,30);

sc.setBounds(235,50,80,25);

t8.setBounds(235,100,200,30);
t2.setBounds(235,150,100,30);
t3.setBounds(235,200,140,30);
t4.setBounds(235,250,200,30);
t5.setBounds(235,300,100,30);
t6.setBounds(235,350,100,30);
t7.setBounds(235,400,120,30);

b1.setBounds(50,460,100,30);
b2.setBounds(170,460,100,30);
b3.setBounds(290,460,100,30);

bb1.setBounds(530,120,120,35);
bb2.setBounds(530,190,120,35);
bb3.setBounds(530,260,120,35);
bb4.setBounds(530,330,120,35);

f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(l6);
f.add(l7);
f.add(l8);
f.add(sc);
t1.setToolTipText("Product Code");
f.add(t2);
t2.setToolTipText("Enter Product sold");
f.add(t3);
t3.setToolTipText("Enter Date");
f.add(t4);
t4.setToolTipText("Enter Customer name");
f.add(t5);
t5.setToolTipText("Bill no");
t5.setEditable(false);
f.add(t6);
t6.setToolTipText("Unit price");
f.add(t7);
t7.setToolTipText("Total price");
f.add(t8);
t8.setEditable(false);
t8.setToolTipText("Product Name");
f.add(b1);
b1.setToolTipText("Click here to submit data");
f.add(b2);
b3.setToolTipText("Click here to cancel data");
f.add(b3);
b3.setToolTipText("Click here to unload the current form");
f.add(bb1);
bb1.setToolTipText("Click here to view the First Record");
f.add(bb2);
bb2.setToolTipText("Click here to view the Last Record");
f.add(bb3);
bb3.setToolTipText("Click here to view the Prev Record");
f.add(bb4);
bb4.setToolTipText("Click here to view the Next Record");
pack();
addWindowListener(new WindowEventHandler());
setSize(800,600);
show();
rec();
t5.setText(""+index);
}
void accessDB()/*to insert data into DB*/
{
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s=c.createStatement();
String sql;
sql = "INSERT INTO sale VALUES ("+(String)t1.getSelectedValue()
+",'"+t8.getText()+"',"+t2.getText()+","+"'"+t3.getText()+"','"+t4.getText()
+"',"+t5.getText()+","+t6.getText()+","+t7.getText()+")";
boolean hasResults = s.execute(sql);
int i= s.executeUpdate("update master set
stockinhand=stockinhand-"+t2.getText()+" where itemcode = "+
(String)t1.getSelectedValue());
c.close();
}
catch(Exception ex)
{
}
}

//to put itemcode in the listbox


void checkRec3()
{
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select itemcode from master");
ResultSet r = s1.getResultSet();
if(r!=null)
{
ResultSetMetaData rmeta = r.getMetaData();
int counts=rmeta.getColumnCount();
data = new String[200];
int oo=0;
while(r.next())
{
data[oo]=r.getString(1);
// System.out.println(data[oo]);
oo++;
}
t1=new JList(data);
t1.setVisibleRowCount(2);
}
}
catch(Exception e){System.out.println("--> "+e);}
}/*for getting tot price & sale price*/
void checkRec2(String xx)
{
try
{
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select * from master");
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
if(rs.getString(1).equals(xx))
{
double ff = Double.valueOf(rs.getString(5)).doubleValue();
ff=ff*.10+ff;
t6.setText(""+ff);
float tot = Float.valueOf(t2.getText()).floatValue();
t7.setText(""+tot*ff);
}
}
}
}
catch(Exception e){System.out.println("--> "+e);}
java.util.Date date = new java.util.Date();
t3.setText(date.getDate()+"/"+(date.getMonth()+1)+"/2005");

}/*for getting item namr*/


void checkRec4(String xx)
{
try
{
java.util.Date date = new java.util.Date();
t3.setText(date.getDate()+"/"+(date.getMonth()+1)+"/2005");
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";

Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select Itemname from master where itemcode="+xx);
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
t8.setText(rs.getString(1));
}
}
}
catch(Exception e){System.out.println("--> "+e);}
}/*for putting limitations on sold quantity*/
boolean checkRec1(String xx)
{
int x=0;
try
{
Class.forName(driver);
c=DriverManager.getConnection(url);
s1 = c.createStatement();
s1.execute("select stockinhand from master where itemcode="+xx);
ResultSet rs = s1.getResultSet();
if(rs!=null)
{
while(rs.next())
{
int sc=Integer.parseInt(rs.getString(1));
if(sc<=10)
{
x=1;
}
if(sc<=Integer.parseInt(t2.getText()))
flag1=true;
else
flag1=false;
}
}
}
catch(Exception e){System.out.println("--> "+e);}
if(x==1)
return(true);
else
return(false);
}/*to put records in array & getting the bill no.*/
boolean rec()
{
i=0;
x=0;
index=1;
try
{
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
c=DriverManager.getConnection(url);
s = c.createStatement();
s.execute("select * from sale ORDER BY bill_No");
ResultSet rs = s.getResultSet();
rr1 = new String[300];
rr2 = new String[300];
rr3 = new String[300];
rr4 = new String[300];
rr5 = new String[300];
rr6 = new String[300];
rr7 = new String[300];
rr8 = new String[300];

while(rs.next())
{
index++;
rr1[i]=rs.getString(1);
rr2[i]=rs.getString(2);
rr3[i]=rs.getString(3);
// for Date Column
String ss = rs.getString(4);
char arr[]=new char[10];
arr[0]=ss.charAt(8);
arr[1]=ss.charAt(9);
arr[2]='/';
arr[3]=ss.charAt(5);
arr[4]=ss.charAt(6);
arr[5]='/';
arr[6]=ss.charAt(0);
arr[7]=ss.charAt(1);
arr[8]=ss.charAt(2);
arr[9]=ss.charAt(3);
ss = new String(arr);
rr4[i]=ss;

rr5[i]=rs.getString(5);
rr6[i]=rs.getString(6);
rr7[i]=rs.getString(7);
rr8[i]=rs.getString(8);
x=i;
i++;
}
}
catch(Exception e){System.out.println(" --> "+e);}
t5.setText(""+index);
return(true);
}/*to show records in the textfields*/
void showRec(int a)
{
t1.setSelectedValue(rr1[a],true);
t2.setText(rr3[a]);
t3.setText(rr4[a]);
t4.setText(rr5[a]);
t5.setText(rr6[a]);
t6.setText(rr7[a]);
t7.setText(rr8[a]);
t8.setText(rr2[a]);
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
String s=ev.getActionCommand();
if(s=="Submit")
{
String ss = (String)t1.getSelectedValue();
boolean fla1 = checkRec1(ss);
if(fla1)
{
MyDialog d = new MyDialog(Sale.this,"Data Validation","Cannot Sell as
Instock<10 units");
d.setVisible(false);
}
if(flag1)
{
MyDialog d = new MyDialog(Sale.this,"Data Validation","Cannot
Sell as Instock<Items to be Sold....");
d.setVisible(false);
}
else
{
accessDB();
rec();
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText(""+index);
t6.setText("");
t7.setText("");
t8.setText("");

}
}
if(s=="Exit")
{
int x = JOptionPane.showConfirmDialog(Sale.this,"A r e y o u s u r e y
o u w a n t t o E x i t ! "," C o n f i r m a t i o
n",JOptionPane.WARNING_MESSAGE,JOptionPane.YES_NO_OPTION);
if(x==0)
hide() ;
}
if(s=="Cancel")
{
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");

}
if(s.equals("Next"))
{
x++;
if(x>=i)
{
x=i-1;
JOptionPane.showMessageDialog(Sale.this,"I t i s t h e L a s t R e c o r
d . . . ","Data Validation",JOptionPane.WARNING_MESSAGE);
}
showRec(x);
}
if(s.equals("Prev."))
{
x--;
if(x<=0)
{
x=0;
JOptionPane.showMessageDialog(Sale.this,"I t i s t h e F i r s t R e c o
r d . . . ","Data Validation",JOptionPane.WARNING_MESSAGE);
}
showRec(x);
}
if(s.equals("First"))
{
x=0;
showRec(x);
}
if(s.equals("Last"))
{
x=i-1;
showRec(x);
}
}
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
setVisible(true);
}
}

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
public class PRepo2 extends Frame implements ActionListener
{

MenuBar mb;
Menu m1;
MenuItem i1,i2;
ScrollPane s;
TextPanel7 t1;
Toolkit tool;
PrintJob pj;
public PRepo2()
{
super("Report Sorted by Purchase date.");
mb = new MenuBar();
m1 = new Menu("File");
i1 = new MenuItem("Exit");
i2 = new MenuItem("Print");
m1.add(i2);
m1.add(i1);
mb.add(m1);
tool=getToolkit();
setMenuBar(mb);
i1.addActionListener(this);
i2.addActionListener(this);
s = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
t1 = new TextPanel7();
s.add(t1);
add(s);
setSize(780,580);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o==i1)
setVisible(false);
if(o==i2)
{
Properties prop = new Properties();
pj = tool.getPrintJob(PRepo2.this,"Hello",prop);
if(pj!=null)
{
t1.printAll(pj.getGraphics());
pj.end();
}
}
repaint();
}
public static void main(String aa[])
{
PRepo2 p = new PRepo2();
}
}
class TextPanel7 extends Canvas
{
public Dimension getPreferredSize()
{
return new Dimension(1000, 1000);
}
public void paint(Graphics g)
{

int x=80,y=80;
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
Connection c=DriverManager.getConnection(url);
Statement s = c.createStatement();
s.execute("select
hiredate,itemcode,itemname,quantity,unit_price,total_price,source from purchase
order by hiredate");
ResultSet r=s.getResultSet();
ResultSetMetaData rmeta = r.getMetaData();
int numColumns=rmeta.getColumnCount();
g.setFont(new Font("Times new Roman",1,34));
g.setColor(Color.red);
g.drawString("Procurement Status Report by Procurement Date .",30,30);
g.drawLine(30,40,760,40);
g.setFont(new Font("Times new Roman",1,14));
// setBackground(Color.pink);
g.setColor(Color.red);
g.drawString("S.No.",20,80);
for(int i=1;i<=numColumns;++i)
{
String cap=rmeta.getColumnName(i);
g.drawString(cap,x,y);
if(i==1)
x+=80;
else
x+=100;
}
int xx=1;
g.setColor(Color.black);
while(r.next())
{
x=90;
y+=22;
g.drawString(xx+" . ",25,y);
xx++;
for(int i=1;i<=numColumns;++i)
{
String ss=r.getString(i);
if(i==1)
{
char a[]=new char[10];
a[0]=ss.charAt(8);
a[1]=ss.charAt(9);
a[2]=ss.charAt(7);
a[3]=ss.charAt(5);
a[4]=ss.charAt(6);
a[5]=ss.charAt(4);
a[6]=ss.charAt(0);
a[7]=ss.charAt(1);
a[8]=ss.charAt(2);
a[9]=ss.charAt(3);
ss = new String(a);
}
// System.out.print(ss);
if(i==1)
x=65;
g.drawString(ss,x,y);
if(i==1)x+=100;
else if(i==2)x+=70;
else if(i==3)x+=140;
else if(i==4)x+=105;
else if(i==6)x+=75;

else if(i==7)x+=70;
else x+=110;
}
//System.out.println();
}
}
catch(Exception e){System.out.println("--> "+e);}
}
}

Report sorted by source

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
public class PRepo2 extends Frame implements ActionListener
{

MenuBar mb;
Menu m1;
MenuItem i1,i2;
ScrollPane s;
TextPanel7 t1;
Toolkit tool;
PrintJob pj;
public PRepo2()
{
super("Report Sorted by Purchase date.");
mb = new MenuBar();
m1 = new Menu("File");
i1 = new MenuItem("Exit");
i2 = new MenuItem("Print");
m1.add(i2);
m1.add(i1);
mb.add(m1);
tool=getToolkit();
setMenuBar(mb);
i1.addActionListener(this);
i2.addActionListener(this);
s = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
t1 = new TextPanel7();
s.add(t1);
add(s);
setSize(780,580);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o==i1)
setVisible(false);
if(o==i2)
{
Properties prop = new Properties();
pj = tool.getPrintJob(PRepo2.this,"Hello",prop);
if(pj!=null)
{
t1.printAll(pj.getGraphics());
pj.end();
}
}
repaint();
}
public static void main(String aa[])
{
PRepo2 p = new PRepo2();
}
}
class TextPanel7 extends Canvas
{
public Dimension getPreferredSize()
{
return new Dimension(1000, 1000);
}
public void paint(Graphics g)
{

int x=80,y=80;
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
Connection c=DriverManager.getConnection(url);
Statement s = c.createStatement();
s.execute("select
hiredate,itemcode,itemname,quantity,unit_price,total_price,source from purchase
order by hiredate");
ResultSet r=s.getResultSet();
ResultSetMetaData rmeta = r.getMetaData();
int numColumns=rmeta.getColumnCount();
g.setFont(new Font("Times new Roman",1,34));
g.setColor(Color.red);
g.drawString("Procurement Status Report by Procurement Date .",30,30);
g.drawLine(30,40,760,40);
g.setFont(new Font("Times new Roman",1,14));
// setBackground(Color.pink);
g.setColor(Color.red);
g.drawString("S.No.",20,80);
for(int i=1;i<=numColumns;++i)
{
String cap=rmeta.getColumnName(i);
g.drawString(cap,x,y);
if(i==1)
x+=80;
else
x+=100;
}
int xx=1;
g.setColor(Color.black);
while(r.next())
{
x=90;
y+=22;
g.drawString(xx+" . ",25,y);
xx++;
for(int i=1;i<=numColumns;++i)
{
String ss=r.getString(i);
if(i==1)
{
char a[]=new char[10];
a[0]=ss.charAt(8);
a[1]=ss.charAt(9);
a[2]=ss.charAt(7);
a[3]=ss.charAt(5);
a[4]=ss.charAt(6);
a[5]=ss.charAt(4);
a[6]=ss.charAt(0);
a[7]=ss.charAt(1);
a[8]=ss.charAt(2);
a[9]=ss.charAt(3);
ss = new String(a);
}
// System.out.print(ss);
if(i==1)
x=65;
g.drawString(ss,x,y);
if(i==1)x+=100;
else if(i==2)x+=70;
else if(i==3)x+=140;
else if(i==4)x+=105;
else if(i==6)x+=75;

else if(i==7)x+=70;
else x+=110;
}
//System.out.println();
}
}
catch(Exception e){System.out.println("--> "+e);}
}
}
Report sorted by item description

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
public class PRepo4 extends Frame implements ActionListener
{

MenuBar mb;
Menu m1;
MenuItem i1,i2;
ScrollPane s;
TextPanel9 t1;
Toolkit tool;
PrintJob pj;
public PRepo4()
{
super("Report Sorted by Item Desc.");
mb = new MenuBar();
m1 = new Menu("File");
i1 = new MenuItem("Exit");
i2 = new MenuItem("Print");
m1.add(i2);
m1.add(i1);
mb.add(m1);
tool=getToolkit();
setMenuBar(mb);
i1.addActionListener(this);
i2.addActionListener(this);
s = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
t1 = new TextPanel9();
s.add(t1);
add(s);
setSize(780,580);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o==i1)
setVisible(false);
if(o==i2)
{
Properties prop = new Properties();
pj = tool.getPrintJob(PRepo4.this,"Hello",prop);
if(pj!=null)
{
t1.printAll(pj.getGraphics());
pj.end();
}
}
repaint();
}
public static void main(String aa[])
{
PRepo4 p = new PRepo4();
}
}
class TextPanel9 extends Canvas
{
public Dimension getPreferredSize()
{
return new Dimension(1000, 1000);
}
public void paint(Graphics g)
{

int x=80,y=80;
try
{
String driver,url;
driver="sun.jdbc.odbc.JdbcOdbcDriver";
url="jdbc:odbc:lib";
Class.forName(driver);
Connection c=DriverManager.getConnection(url);
Statement s = c.createStatement();
s.execute("select
itemname,itemcode,source,quantity,unit_price,total_price,hiredate from purchase
order by itemname");
ResultSet r=s.getResultSet();
ResultSetMetaData rmeta = r.getMetaData();
int numColumns=rmeta.getColumnCount();
g.setFont(new Font("Times new Roman",1,34));
g.setColor(Color.red);
g.drawString("Procurement Status Report by Product Desc .",30,30);
g.drawLine(30,40,730,40);
g.setFont(new Font("Times new Roman",1,14));
// setBackground(Color.pink);
g.setColor(Color.red);
g.drawString("S.No.",20,80);
for(int i=1;i<=numColumns;++i)
{
String cap=rmeta.getColumnName(i);
g.drawString(cap,x,y);
if(i==1)
x+=120;
else
x+=100;
}
int xx=1;
g.setColor(Color.black);
while(r.next())
{
x=90;
y+=22;
g.drawString(xx+" . ",25,y);
xx++;
for(int i=1;i<=numColumns;++i)
{
String ss=r.getString(i);
if(i==7)
{
char a[]=new char[10];
a[0]=ss.charAt(8);
a[1]=ss.charAt(9);
a[2]=ss.charAt(7);
a[3]=ss.charAt(5);
a[4]=ss.charAt(6);
a[5]=ss.charAt(4);
a[6]=ss.charAt(0);
a[7]=ss.charAt(1);
a[8]=ss.charAt(2);
a[9]=ss.charAt(3);
ss = new String(a);
}
// System.out.print(ss);
if(i==1)
x=65;
g.drawString(ss,x,y);
if(i==1)x+=150;
else if(i==2)x+=70;
else if(i==3)x+=140;
else if(i==4)x+=105;
else if(i==5)x+=85;

else if(i==6)x+=90;

else if(i==7)x+=70;
else x+=110;
}
//System.out.println();
}
}
catch(Exception e){System.out.println("--> "+e);}
}
}
References

Books :-
 Java-TM The Complete Reference fifth edition (Herbert Schildt)

 MS-Access 2000, BPB Publication

 Black Book-Steven Holzner

Websites :-

 www.java.sun.com

S-ar putea să vă placă și