Saturday, July 25, 2009

DATABASE SIMULATION JAVA PROJECT (SOURCE CODE)

DATABASE-SIMULATION


CONTENTS


Introduction
Need Analysis/Preliminary Investigation
Objectives
System Requirements/Methodology
Data Flow Diagrams
Input Forms
Coding
Output Forms
Unit Testing and System Testing
Limitations and Problems Faced
Fall Outs and Suggestions for the Future work
Conclusion
References/Bibliography
















INTRODUCTION
----------------------------------------------------------------------------------------------------------


















NEED ANALYSIS / PRELIMINARY INVESTIGATION


One of the most difficult tasks of the system analyst is identifying the real problem of the existing system. Without clear understanding of the problem in the system, any further work done will lead to the wastage of effort at a later stage.

The purpose of the Preliminary Investigation is to evaluate the project requests. It is the collection of the information that helps the committee members to evaluate the merits of the project request and make an informed judgment about the feasibility of the project.

My preliminary investigation was dome by Mrs. Geeta Dahiya and Ms. Pooja Gandhi. After their recommendations, I (Ruchika) move on to the further progress of the project.

















Project mission and objectives
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Mission

Database-Simulation project provides more security to the user by providing every user with username and password before creating its own database. After creating their own database, every user can create as many tables as he needed in their own database. The user can further open the database only if he knows the username and password.
Hence, this application has been designed to implement the overall working of a DATABASE in JAVA Platform.
With the help of this application, one can be able to create its own secured database in the computerized way rather than manually.

Objectives

Increased efficiency:-
This project increases efficiency of manpower with computer in various works. It does not require any creativity which can exhaust soon
Less Time Consuming:-
It is user friendly and less time consuming with bottom line option.
Reduction of Manpower:-
It serves a lot of desk work as there are no efforts in manipulating records.
Less use of paper work:-
In manual system a large number of files are required but in our system paper requirement is very less.
Save memory:-
In computerized systems we are able to save large amount of information.

System Requirements
-----------------------------------------------------------------------------------------------------------------------



Software Requirements

Microsoft Windows 2000/XP Operating System.
Java2 software development kit (J2sdk1.4 Onwards)





Hardware Requirements
------------------------------------------------------

· Processor : P-IV, 2.4GHz

· Hard Disk : 40 GB

· RAM : 256 MB

· CD-ROM









METHODOLOGIES

ABOUT JAVA

Java is a platform independent language that could be used to create software to be embedded in various consumer electronic devices, such as Microwave ovens and Remote Controls. With the emergence of the World Wide Web, java was propelled to the forefront of computer language design, because the Web, too, demanded portable programs.

Hence java was switched from consumer electronics to Internet Programming. Java derives much of its character from C and C++. In addition to the surface similarities , java shares some of the other attributes that helped make C and C++ successful. Because of the similarities between java and C++, it is tempting to think of java as simply the “Internet Version of C++”.

The Java 2 SDK is a development environment for building applications, applets, and components using the Java programming language.

The Java 2 SDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java platform. These tools are designed to be used from the command line. Except for the applet viewer, these tools do not provide a graphical user interface.






Java Applets and Application

Java can be used to create two types of programs: Applications and Applets.

An Application is a program that runs on your computer, under the operating system of that computer.

An Applet is an application designed to be transmitted over the Internet and executed by a Java- compatible Web Browser. An applet is actually a tiny java program, dynamically downloaded across the Network, just like an image, sound file, or video clip. An important difference is that an applet is an intelligent program, not just an animation or media file.

java.awt. *:

This package contain AWT classes.It is one of the Java’s largest package.Some of the classes it contain are:
AWTEvent
BorderLayout
Button
Checkbox
CheckBoxGroup
Container
Event
Font
Frame
GraphicsDevices

java.awt.event. *:
Swings and applets are event-driven programs. Most events are passed to applets and swings in a variety of ways, with the specific methods depending upon the actual event. There are several types of events. All such events are supported by the java.awt.event. *

javax.swing.* :
Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT .
The swing related classes are contained in javax.swing.tree like:
AbstractButton
ButtonGroup
ImageIcon
JApplet
JButton
JCheckBox
JComboBox
JLabel
JTable
JTree

java.io. *:
This header file provides support for I/O operations.It contain classes like:
BufferedInputStream
BufferedOutputStream
File
FileReader
FileWriter
OutputStream




java.io.File.* :

File class deals with files and the file system i.e, it does not specify how information is retrieved from or stored in files, it describes properties of a file itself .A file object is used to obtain or manipulate the information associated with a disk file .
The following are the constructors :
File(String directoryPath)
File(String directoryPath ,String filename)
File(File dirObj ,String filename)
File(URL uriObj)

java.util. *:

A collection is a group of objects .The addition of collections caused fundamental alterations in the structure and the architecture of many elements. This header file contains collection. Its some of the classes are:
AbtractCollection
Arrays
Collections
Date
Calender
Properties
Timer
StringTokenizer






ActionListener Interface :

This interface defines the actionPerformed() method that is invoked when an action event occurs. Its general form is:

Void actionPerformed(ActionEvent ae)

ItemListener Interface :

This interface defines the itemStateChanged() method that is invoked when the state of an item change.its general form is :

Void itemStateChanged(itamEvent ie)

Collections:

A collection is a group of objects. The addition of collections caused fundamental alterations in the structure and the alterations of many elements of many elements in java.util.

ContentPane :

The difference between applet and Japplet is that when adding a
Component to an instance of Japplet ,Do not invoke the add of
The applet. Instead call add() for the content pane of the
Japplet object.

Container getContentPane()

LayoutManager :

Each container object has a layout manager associated with
It. It is an instance of any class that implements the
Layoutmanger interface.The layout manger is set by the
setLayout() method is made, then thedefault layout manager is
used.
General forms:
Void setLayout(LayoutManager layoutObj)
Tables
A table is a collection of data about a specific topic, such as students or contacts. Using a separate table for each topic means that you store that data only once, which makes your database more efficient, and reduces data-entry errors.
Tables organize data into columns (called fields) and rows (called records).











Data Flow Diagram
------------------------------------------ ------------------------------------------------------------------------------------

Data-flow diagrams (DFD) are very effective Software-Engineering Tools. They help to identify various sub-modules of a program, the interaction between them and the flow of data between various modules. Going further down the hierarchy, a DFD also represents and explains the functioning of various modules separately.

A DFD is an important part of Software documentation as it keeps a record of what the software is doing and easier to understand than the actual programming code.

DFD Conventional Notations
Many conventional notations are defined for drawing DFD’s to maintain a standard format throughout the world. Certain primitive shapes are reserved for specific representations only. Some of these primitives are:


Data Storage



Processes



Data Flow



External Entity



DFD Hierarchy

DFD’s follow a hierarchy to completely define the program functionality. The hierarchy begins at Level 0 which is also known as context level.

Context level DFD: Context level provides an overview of the whole program. It represents the interaction of sub-modules and it also represents the interaction.


LEVEL 1 DFD: Next comes the level 1. There an be many level 1 DFD’s for a program, depending on the number of modules in the program. Each level 1 DFD represents the basic functioning of the module for which it is defined. If defines the data flow and user interaction of each module. It also defines various sub-modules of that module (if any) and their brief functionality.


FURTHER LEVELS: After level 1 further level can be defined to further explain the functioning of each module’s sub-modules and their sub-modules.














































ZERO (0) LEVEL DFD


MAIN LEVEL DFD









USER VERIFICATION

















CHECKING PROCESS
















Input Forms
------------------------------------------------------------------------------------


MAIIN FRAME









LOGIN FORM













TABLE CREATION FORMS

TABLE CREATION FRAME












FIELD GENERATION FORM


















DATA ENTRY FORM




















Juser.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Juser extends JFrame implements ActionListener,MenuListener {
JTextField field;
Container cp;
public Juser()
{
cp=getContentPane();
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("USER");
JMenuItem tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
menu.addMenuListener(this);
tmp1 = new JMenuItem("NEW USER");
tmp1.addActionListener(this);
tmp1.setActionCommand("NEW USER");
menu.add(tmp1);

tmp2 = new JMenuItem("OPEN USER");
tmp2.addActionListener(this);
tmp2.setActionCommand("OPEN USER");
menu.add(tmp2);

tmp3 = new JMenuItem("DELETE USER");
tmp3.addActionListener(this);
tmp3.setActionCommand("DELETE USER");
menu.add(tmp3);

tmp4 = new JMenuItem("EXIT");
tmp4.addActionListener(this);
tmp4.setActionCommand("EXIT");
menu.add(tmp4);
bar.add(menu);
setJMenuBar(bar);
field = new JTextField(10);
field.addActionListener(this);
field.setActionCommand("text field activated");
cp.add( "South",field);
JMenu menu1 = new JMenu("SEARCH");
cp.setBackground(Color.lightGray);
cp.setLayout(new BorderLayout());
menu.addMenuListener(this);
tmp5 = new JMenuItem("BY NAME");
tmp5.addActionListener(this);
tmp5.setActionCommand("BY NAME");
menu1.add(tmp5);
bar.add(menu1);
}
public void actionPerformed(ActionEvent ae) {
String cmd;
cmd = ae.getActionCommand();
field.setText(cmd);
if(cmd.equals("NEW USER"))
{
Passnew pw1=new Passnew(this);
}

if(cmd.equals("OPEN USER"))
{
Passopen pw2=new Passopen(this);
}

if(cmd.equals("DELETE USER"))
{
Passdel pw3=new Passdel();
}
if(cmd.equals("EXIT"))
{
System.exit(0);
}
if(cmd.equals("BY NAME"))
{
search s1 = new search();
}
}
public void menuSelected(MenuEvent e)
{
}
public void menuDeselected(MenuEvent e)
{
}
public void menuCanceled(MenuEvent e)
{
}
public Dimension getPreferredSize()
{
return new Dimension(980,550);
}

public static void main(String a[])
{
Juser ju=new Juser();
ju.setForeground(Color.black);
ju.setBackground(Color.lightGray);
ju.addWindowListener(new WindowCloser());
ju.setSize(980,550);
ju.setVisible(true);
}
}

class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
System.exit(0);
}
}





Passnew.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Passnew extends JFrame implements ActionListener
{
JTextField jtf1;
JPasswordField jtf2;
Container c ;
JLabel jl1,jl2,jl3,label;
JButton jb,jb1;
String user="",password="";
Juser j;
public Passnew(Juser j)
{
this.j=j;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("ENTER USER NAME",JLabel.CENTER);
c.add(jl1);
jtf1=new JTextField(10);
c.add(jtf1);
jl2=new JLabel("ENTER PASSWORD",JLabel.CENTER);
c.add(jl2);
jtf2=new JPasswordField(10);
c.add(jtf2);
jb=new JButton("CREATE");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
jl3=new JLabel("",JLabel.CENTER);
c.add(jl3);
c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jb)
{
Juser ju = new Juser();
user=jtf1.getText();
//String
password=jtf2.getText();
try{
File u=new File("c:/j2sdk1.4.1_01/bin/database/" +user);
if(u.exists()){
jl3.setText("USER ALREADY EXISTS");
}
else{
u.mkdir();
File p=new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password);
p.mkdir();

Jtable jt=new Jtable(user,password);
}
}catch(Exception e){System.out.println(e);}
}
if(ae.getSource() == jb1)
{
setVisible(false);
}
}
}

Jtable.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Jtable extends JFrame implements ActionListener,MenuListener {
JTextField field,field1;
JLabel jl;
Container cp1;
String user="",password="";
public Jtable(String user,String password)
{
this.user=user;
this.password=password;
cp1=getContentPane();

////////////////////added from main//////////////////////////

cp1.setForeground(Color.black);
cp1.setBackground(Color.lightGray);
addWindowListener(new WindowCloser());
setSize(980,550);
setVisible(true);

/////////////////////////////////////////////////////////////
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("TABLE");
JMenuItem tmp1,tmp2,tmp3,tmp4,tmp5,tmp6;
menu.addMenuListener(this);
tmp1 = new JMenuItem("NEW");
tmp1.addActionListener(this);
tmp1.setActionCommand("NEW");
menu.add(tmp1);

tmp2 = new JMenuItem("OPEN");
tmp2.addActionListener(this);
tmp2.setActionCommand("OPEN");
menu.add(tmp2);

tmp3 = new JMenuItem("DELETE");
tmp3.addActionListener(this);
tmp3.setActionCommand("DELETE");
menu.add(tmp3);

tmp4 = new JMenuItem("EXIT");
tmp4.addActionListener(this);
tmp4.setActionCommand("EXIT");
menu.add(tmp4);

bar.add(menu);
setJMenuBar(bar);
field = new JTextField(10);
field.addActionListener(this);
field.setActionCommand("text field activated");
cp1.add( "South",field);
JMenu menu1 = new JMenu("SEARCH");
cp1.setBackground(Color.lightGray);
cp1.setLayout(new BorderLayout());
menu.addMenuListener(this);
tmp5 = new JMenuItem("BY NAME");
tmp5.addActionListener(this);
tmp5.setActionCommand("BY NAME");
menu1.add(tmp5);
bar.add(menu1);
}
public void actionPerformed(ActionEvent ae) {
String cmd;
cmd = ae.getActionCommand();
field.setText(cmd);
if(cmd.equals("NEW"))
{
table2 t2=new table2(user,password);
}

if(cmd.equals("OPEN"))
{
table3 t3=new table3(user,password);
}
If(cmd.equals("DELETE"))
{
tabledel tt3 = new tabledel(user,password);
}
if(cmd.equals("EXIT"))
{
System.exit(0);
}
if(cmd.equals("BY NAME"))
{
searchtab st = new searchtab(user,password);
}
}
public void menuSelected(MenuEvent e)
{
}
public void menuDeselected(MenuEvent e)
{
}
public void menuCanceled(MenuEvent e)
{
}
public Dimension getPreferredSize()
{
return new Dimension(980,550);
}
class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
System.exit(0);
}
}
}

Password.java
-------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class PassWord extends JPanel implements ActionListener
{
JTextField jtf;
public PassWord(Jframe frame)
{
setLayout(new FlowLayout(FlowLayout.CENTER));
JLabel j1=new JLabel("ENTER USER NAME",JLabel.CENTER);
add(j1);
jtf=new JTextField(10);
add(jtf);
JLabel j2=new JLabel("ENTER PASSWORD",JLabel.CENTER);
add(j2);
jtf=new JTextField(10);
add(jtf);
JButton jb=new JButton("CREATE");
jb.addActionListener(this);
add(jb);
jb=new JButton("CANCEL");
jb.addActionListener(this);
add(jb);
}

public void actionPerformed(ActionEvent ae)
{
}
public static void main(String a[])
{
JFrame frame = new JFrame("PassWord");
PassWord panel = new PassWord(frame);

frame.setForeground(Color.black);
frame.setBackground(Color.lightGray);
frame.addWindowListener(new WindowCloser());
frame.getContentPane().add(panel,"Center");
frame.setSize(300,150);
frame.setVisible(true);
}
}

class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
System.exit(0);
}
}















Table1.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class table1 extends JFrame implements ActionListener
{
Object[] data = new Object[2];
String user="",password="";
String file1="";
Container c;
DefaultTableModel dtm;
JPanel p;
///////////////////////////////
JButton jb1;
JButton jb2;
JButton jb3;
JButton jb4;
JTable jtable;

//////////////////////////////////

public table1(String user,String password,String file1)
{
this.user=user;
this.password=password;
this.file1=file1;

//////////////////////////////////////////

jb1 = new JButton("CREATE NEW ROW");
jb2 = new JButton("CREATE NEW COLUMN");
jb3 = new JButton("SAVE");
jb4 = new JButton("CANCEL");

///////////////////////////////////////
p=new JPanel();
c=getContentPane();
dtm = new DefaultTableModel();
jtable = new JTable(dtm);

/////////////////////////////////////////////
p.add(jb1);
p.add(jb2);
p.add(jb3);
p.add(jb4);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);

//////////////////////////////////////////
String s = new String("manu");
for(int col = 0;col<2;col++)
{
dtm.addColumn("column"+col);
}

for(int row=0;row<2;row++)
{
for(int col =0;col<2;col++)
{
data[col]=null;
}
dtm.addRow(data);
}
c.add(new JScrollPane(jtable),BorderLayout.CENTER);
c.add(p,BorderLayout.SOUTH);
setSize(800,550);
setVisible(true);
}

///////////////////////////////////////////////////////////

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jb1) {
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
Object[] data = new Object[nc];

for (int col=0;col
{
data[col] = "";
}
dtm.addRow(data);
}
else if(e.getSource() == jb2)
{
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
dtm.addColumn("column" + nc);
}
else if(e.getSource() == jb3)
{
try{
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
File file = new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+file1+".txt");
FileOutputStream foi = new FileOutputStream(file,true);
PrintWriter pw=new PrintWriter(new OutputStreamWriter(foi));

for(int row=0;row
{
for(int col=0;col
{
String sss=(String)jtable.getValueAt(row,col);
pw.print(sss);
pw.print("*");
}
pw.print("!");
}
pw.close();

}
catch(Exception ee){}
}
else if(e.getSource() == jb4)
{
System.exit(0);
}
jtable.sizeColumnsToFit(0);
}
}






















Table2.java
-------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class table2 extends JFrame implements ActionListener
{
Object[] data = new Object[5];
Container c;
DefaultTableModel dtm;
JPanel p;
///////////////////////////////
JLabel jl1;
JTextField jtf1;
JButton jb1;
JButton jb3;
JButton jb4;
JTable jtable;
String user="",password="";
String file1 = "";
//////////////////////////////////
public table2(String user,String password)
{
this.user=user;
this.password=password;
//////////////////////////////////////////
jl1 = new JLabel("ENTER NAME OF TABLE");
jtf1 = new JTextField(20);
jb1 = new JButton("CREATE NEW ROW");
jb3 = new JButton("CREATE");
jb4 = new JButton("CANCEL");
///////////////////////////////////////
p=new JPanel();
c=getContentPane();
dtm = new DefaultTableModel();
jtable = new JTable(dtm);
/////////////////////////////////////////////
p.add(jl1);
p.add(jtf1);
p.add(jb1);
p.add(jb3);
p.add(jb4);
jtf1.addActionListener(this);
jb1.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
//////////////////////////////////////////
for(int col = 0;col<2;col++)
{
if(col==0)
{
dtm.addColumn("FIELD TYPE ");
}
else
{
dtm.addColumn("DATA TYPE");
}
}
for(int row=0;row<2;row++)
{
for(int col = 0;col<2;col++)
{
data[col]="";
}
dtm.addRow(data);
}
c.add(new JScrollPane(jtable),BorderLayout.CENTER);
c.add(p,BorderLayout.SOUTH);
setSize(800,550);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jb1) {
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
Object[] data = new Object[nc];
for (int col=0;col
{
data[col] = "";
}
dtm.addRow(data);
}
else if(e.getSource() == jb3)
{
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
try {
file1 = jtf1.getText();
File f = new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+file1+".txt");
FileOutputStream foi = new FileOutputStream(f,true);
PrintWriter pw=new PrintWriter(new OutputStreamWriter(foi));
for(int row=0;row
{
for(int col = 0;col<2;col++)
{
String ssss=(String)jtable.getValueAt(row,col);
pw.println(ssss);
}
}
pw.close();
}
catch(Exception ee){}
table1 tt1 = new table1(user,password,file1);
}
else if(e.getSource() == jb4)
{
setVisible(false);
}
jtable.sizeColumnsToFit(0);
}
}


Table3.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class table3 extends JFrame implements ActionListener
{
Object[] data = new Object[2];
Container c;
int nc,nr,ncol;
String [][]str1=new String[50][50];
int count1=0,count2=0;
JLabel jl;
JTextField tf2;
JButton jb5;
JTable jt;
DefaultTableModel dtm=new DefaultTableModel();
///////////////////////////////
JPanel p;
JButton jb1;
JButton jb2;
JButton jb3;
JButton jb4;
JTable jtable = new JTable(dtm);
//////////////////////////////////
String user = "";
String password = "";
public table3(String user,String password)
{
this.user = user;
this.password = password;
//////////////////////////////////////////
jl = new JLabel("ENTER TABLE NAME");
tf2 = new JTextField(20);
jb5 = new JButton("OPEN");
jb1 = new JButton("ADD NEW ROW");
jb2 = new JButton("ADD NEW COLUMN");
jb3 = new JButton("SAVE");
jb4 = new JButton("CANCEL");

///////////////////////////////////////

p=new JPanel();
c=getContentPane();

/////////////////////////////////////////////
p.add(jl);
p.add(tf2);
p.add(jb5);
p.add(jb1);
p.add(jb2);
p.add(jb3);
p.add(jb4);
tf2.addActionListener(this);
jb5.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);

//////////////////////////////////////////
c.add(p,BorderLayout.NORTH);

setSize(900,600);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jb5) {
try {
String file2 = new String();
file2 = tf2.getText();
File f = new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+file2+".txt");

FileInputStream inStream = new FileInputStream(f);
int inbyte = inStream.available();
byte inBuf[] = new byte[inbyte];
int byteread = inStream.read(inBuf,0,inbyte);
nc=0;nr=0;
System.out.println(byteread);
String str="";
for(int j=0;j < byteread;j++)
{
System.out.print((char)inBuf[j]+" ");
str= str + (char)inBuf[j];
if(inBuf[j] == 42 )
{
System.out.println(str);
str1[count1][count2]=str.substring(0,str.length()-1);
count2=count2+1;
if(inBuf[j+1]!=33)
{
str="";
}
nc=nc+1;
}

if(inBuf[j] == 33)
{
count1=count1+1;
count2=0;
str1[count1][count2]=str.substring(1,str.length()-1);
str="";
nr=nr+1;
}
}

inStream.close();
ncol = nc/nr;
System.out.println("no of column "+ncol + "no of row " + nr);
}
catch(Exception eee) {}

for(int col = 0;col
{
dtm.addColumn("column"+col);
}

for(int row=0;row
{
for(int col =0;col
{
String str2;
str2=str1[row][col];
data[col]=str2;
}
dtm.addRow(data);
}
c.add(new JScrollPane(jtable),BorderLayout.CENTER);
setVisible(false);
setVisible(true);
}
if(e.getSource() == jb1)
{
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
Object[] data = new Object[nc];
for (int col=0;col
{
data[col] = "0";
}
dtm.addRow(data);
}

if(e.getSource() == jb2)
{
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
dtm.addColumn("column" + nc);
}

if(e.getSource() == jb3)
{
try{
int nr = dtm.getRowCount();
int ncol = dtm.getColumnCount();
String file3 = new String();
file3 = tf2.getText();
File f3 = new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+file3+".txt");
FileOutputStream foi = new FileOutputStream(f3,true);
PrintWriter pw=new PrintWriter(new OutputStreamWriter(foi));

for(int row=0;row
{
for(int col=0;col
{
String sss=(String)jtable.getValueAt(row,col);
pw.print(sss);
pw.print("*");
}
pw.print("!");
}
pw.close();
}

catch(Exception ee){}
}

if(e.getSource() == jb4)
{
System.exit(0);
}
jtable.sizeColumnsToFit(0);
}
}






Tabopen.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class tabopen extends JFrame implements ActionListener
{

JTextField jtf1;
Container c ;
JLabel j1;
JButton jb,jb1;
Jtable j;
public tabopen(Jtable j)
{
this.j=j;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});
c =getContentPane();
c.setLayout(new FlowLayout());
j1=new JLabel("ENTER TABLE NAME",JLabel.CENTER);
c.add(j1);
jtf1=new JTextField(10);
c.add(jtf1);
jb=new JButton("OPEN");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setSize(300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{

if(ae.getSource()==jb)
{
Jtable ju = new Jtable();
String user=jtf1.getText();
try
{
File u=new File(user);
if(u.exists())
{
}
Else
{
JLabel j2= new JLabel("TABLE DOES NOT EXIST",JLabel.CENTER);
c.add(j2);
}
}catch(Exception e){System.out.println(e);}

}
}
}









Tabledel.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class tabledel extends JFrame implements ActionListener
{
JTextField jtf1;
Container c ;
JLabel jl1,jl2,jl3,label;
JButton jb,jb1;
String user="",password="";
String tabname;
Juser j;

public tabledel(String user,String password)
{
this.user=user;
this.password=password;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("ENTER TABLE NAME",JLabel.CENTER);
c.add(jl1);
jtf1=new JTextField(10);
c.add(jtf1);
jb=new JButton("DELETE");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
jl3=new JLabel("",JLabel.CENTER);
c.add(jl3);

c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jb)
{
tabname=jtf1.getText();
try
{
File u=new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+tabname+".txt");
if(u.exists()){
u.delete();
jl3.setText(" TABLE DELETED ");

}
else{
jl3.setText("TABLE DOES NOT EXIST");
}
}
catch(Exception e){
System.out.println(e);
}
}
if(ae.getSource() == jb1)
{
setVisible(false);
}
}
}
Choose1.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class choose extends JApplet // implements ActionListener
{
Object[] data = new Object[5];
DefaultTableModel dtm = new DefaultTableModel();
JTable jtable = new JTable(dtm);

public void init()
{
for(int col = 0;col<2;col++)
{

if(col==0)
{
dtm.addColumn("FIELD'S NEME");
}
Else
{
dtm.addColumn("DATA TYPE");
}
}
for(int row=0;row<10;row++)
{
for(int col = 0;col<2;col++)
{
data[col]="";
}

dtm.addRow(data);
}
getContentPane().add(new JScrollPane(jtable),BorderLayout.CENTER);
getContentPane().add(new jpanel(),BorderLayout.SOUTH);
}
class jpanel extends JPanel implements ActionListener
{
JButton jb1 = new JButton("CREATE NEW ROW");
public jpanel()
{
add(jb1);
jb1.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jb1) {
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
Object[] data = new Object[nc];
for (int col=0;col
{
data[col] = "";
}
dtm.addRow(data);
}
jtable.sizeColumnsToFit(0);
}
}
}











Dbase.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class dbase extends Frame implements ActionListener,KeyListener
{
String user="",password="";
TextField t;
TextArea ta;
String pt="";
Panel pn;
Button change;
Prompt p;
help hp=null;
public dbase()
{
addWindowListener(new WindowAdapter()

{
public void WindowClosing(WindowEvent w)
{
System.exit(0);
}
});

t=new TextField();
add("south",t);
ta=new TextArea();
ta.setFont(new Font("arial",Font.BOLD,16));
add("Center",ta);
setSize(1000,580);
setVisible(true);
t.addActionListener(this);
pn=new Panel();
pn.setLayout(new FlowLayout());
change=new Button("CHANGE PROMPT");
change.setBounds(450,20,50,30);
pn.add(change);
add("North",pn);
change.addActionListener(this);
t.addKeyListener(this);
p=new prompt(this,"Enter Your Prompt",true);
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource()==t)
{
try{
String s=t.getText ();
if(s.equals("clear screen"))
{
ta.setText("");
}

///////////CREATE USER///////////////

if(s.toLowerCase().startsWith("create user"))
{
user=s.toLowerCase().substring("create user".length(),s.indexOf("identified"));
user=user.trim();
System.out.println(user.length());
File f1=new File(user);
if(f1.exists())
ta.append("\n"+pt+">User Already Exists");
else
{
f1.mkdir();
password=s.substring(s.indexOf("identified")+14,s.length());
File pw=new File("c:/j2sdk1.4.1_01/bin/"+user+"/"+password);
pw.mkdir();
ta.append("\n"+pt+">user created");
try{
Runtime rt=Runtime.getRuntime();
Process p=rt.exec("insert.bat"+user);
Thread.sleep(3000);
f1.deleteOnExit();
}
catch(Exception e)
{
ta.setText(e.toString());
}
}
}

/////////////SELECT FROM TABLE////////////////

if(s.toLowerCase().startsWith("select from"))
{
ta.append("\n"+pt+".");
File f4=new File("c:/j2sdk1.4.1_01/bin/"+user+"/"+s.substring("select from".length(),s.length()));
if(f4.exists())
{
FileInputStream fout2=new FileInputStream(f4);
StreamTokenizer stk=new StreamTokenizer(fout2);
int tok;
while((tok=stk.nextToken())!= -1)
{
stk.eoIIsSignificant(true);
if(tok==StreamTokenizer.TT_EOL)
{
ta.append("\n");
}
if(tok==StreamTokenizer.TT_WORD)
{
String xx=stk.sval.replace(',','a');
ta.append(" "+xx);
}
if(tok==StreamTokenizer.TT_NUMBER)
{
double yy=stk.nval;
ta.append(" "+yy);
}
}
}
else
{
ta.append("\n"+pt+">Object NOT found");
}
}

////////////DROP TABLE//////////////

if(s.toLowerCase().startsWith("drop user"))
{
File f2 = new File(s.toLowerCase().Substring("drop user".length(),s.length()));
if(f2.exists())
{
f2.delete();
ta.append("\n"+pt+">user dropped");
}
else
ta.append("\n"+pt+">no such user");
}

///////////CONNECTING USER///////////////

if(s.toLowerCase().starttWith("connect"))

{
String misa = s.toLowerCase().Substring("connect".length(),s.indexOf('/'));
try
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("extract.bat"+misa.trim());
Thread.sleep(5000);
}
catch(Exception e) {}

File f3 = new File(s.toLowerCase().substring("connect".length(),s.indexOf('/').trim()));
user = s.toLowerCase().substring("connect".length(),s.indexOf('/').trim());
File ff = new
File("c:/j2sdk1.4.1_01/bin/"+user+"+s.toLowerCase().substring(s.indexOf('/')+1,s.length());
Syttem.out.println(f3.getPath()+"\n"+ff.getPath());
if(f3.exists()) {
if(ff.exists()) {
ta.append("\n"+pt+">connected");
}
else ta.append("\n wrong password");
}
Else
{
ta.append("\n+pt+"+s.substring("connect".length(),s.indexOf('/'))+"user does not exist");
}
}

//////////CREATING TABLES///////////////

String str = "";
if(s.toLowerCase().startsWith("create table"))
{
String xx = "c:/j2sdk1.4.1_01/bin/"+user+"/"+s.substring("create table".length,s.indexOf('('));
File f3 = new File("c:/j2sdk1.4.1_01/bin/"+user+"/"s.substring("create table".length()'s.indexOf('(')));

if(f3.exists())
ta.append("\n"+pt+">table already exusts");

else
{
File.OutputStream fout1 = new FileOutputStream(xx,true);
str = s.substring(s.indexOf('(')+1,indexOf(')'));
byte b[]=str.getBytes();
fout1.write(b);
ta.append("\n"+pt+">table created");


try {
File ujar = new File("c:/j2sdk1.4.1_01/bin/"+user);
Runtime rt = Runtime.getRuntime();
rt.exec("insert.bat"+user);
Thread.sleep(3000);
ujar.deleteOnExit();
}
catch(Exception e) {}
}
}

///////////DROPPING TABLE//////////////

if(s.toLowerCase().startWith("drop table"))
{
File f4 = new File("c:/j2sdk1.4.1_01/bin/"+user+"/"+s.substring("drop table".length(),s.length()));
if(f4.exists()) {
boolean b1 = f4.delete();
if(b1==true)
ta.append("\n"+pt+">table deleted");
}
else
{
ta.append("\n"+pt+">object not found");
}
try {
File ujar = new File(user);
Runtime rt = Runtime.getRuntime();
rt.exec("insert.bat"+user);
Thread.sleep(3000);
ujar.deleteOnExit();
}
catch(Exception e) {}
}


////////////INSERTING INTO TABLE//////////////

if(s.toLowerCase().startsWith("insert into"))
{

string xy = "c:/j2sdk1.4.1_01/bin" +user+ "/"+s.substring("insert into".length(),s.indexOf("values"));

File f4 = new File("c:/j2sdk1.4.1_01/bin" +user+ "/"+s.substring("insert into".length(),s.indexOf("values")));
if(f4.exists()) {
FileOutputStream fout2 = new FileOutputStream(xy,true);
str = s.substring(s.indexOf("values")+7,s.indexOf(')'));
byte bb[] = ("\n"+str).getBytes();
fout2.write(bb);
ta.append(\n"+pt+">inserted);
}
else
{
ta.append("\n"+pt+>object not found");
}
try
{
File ujar = new File("c:/j2sdk1.4.1_01/bin"+user);
Runtime rt = Runtime.getRuntime();
rt.exec("insert.bat"+user);
Thread.sleep(3000);
ujar.deleteOnExit();
}
catch(Exception e) {}
}
















Jpanel.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

class jpanel extends JPanel implements ActionListener {
JButton jb1 = new JButton("CREATE NEW ROW");
JButton jb2 = new JButton("CREATE NEW COLUMN");
public jpanel()
{
add(jb1);
add(jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb1) {
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
Object[] data = new Object(nc);
for (int col=0;col
data[col] = "";
}
dtm.addRow(data);
}
else if(e.getSource() == jb2) {
int nr = dtm.getRowCount();
int nc = dtm.getColumnCount();
dtm.addColumn("colu"+col);
for (int row=0;row
dtm.setValueAt("");
data[col] = "";
}
dtm.addRow(data);
}
}

Passdel.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Passdel extends JFrame implements ActionListener
{

JTextField jtf1;
JPasswordField jtf2;
Container c ;
JLabel j1,j2,j3;
JButton jb,jb1;

public Passdel()

{
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
j1=new JLabel("ENTER USER NAME",JLabel.CENTER);
c.add(j1);
jtf1=new JTextField(10);
c.add(jtf1);
j2=new JLabel("ENTER PASSWORD",JLabel.CENTER);

c.add(j2);
jtf2=new JPasswordField(10);
c.add(jtf2);
jb=new JButton("DELETE");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
j3 = new JLabel();
c.add(j3);

c.setForeground(Color.black);

c.setBackground(Color.lightGray);

setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);

}

public void actionPerformed(ActionEvent ae)
{

if(ae.getSource()==jb)
{

Juser ju = new Juser();

String user=jtf1.getText();
String pass=jtf2.getText();
try{
File u=new File("c:/j2sdk1.4.1_01/bin/database/"+user);
if(u.exists()){
{
File p=new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+pass);

if(p.exists()){

p.delete();
u.delete();
j3.setText(" USER DELETED ");
}
else
j3.setText(" WRONG PASSWORD ");
}
}
Else
{
j3.setText("USER DOES NOT EXISTS");
}
}
catch(Exception e){
System.out.println(e);
}

}
if(ae.getSource() == jb1){
setVisible(false);}
}
}















Passopen.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Passopen extends JFrame implements ActionListener
{

JTextField jtf1;
JPasswordField jtf2;
Container c ;
JLabel j1,j2,j3;
JButton jb,jb1;
Juser j;
Jtable jtable;
String password = "";
String user= "";
public Passopen(Juser j)
{
this.j=j;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
j1=new JLabel("ENTER USER NAME",JLabel.CENTER);
c.add(j1);
jtf1=new JTextField(10);
c.add(jtf1);
j2=new JLabel("ENTER PASSWORD",JLabel.CENTER);
c.add(j2);
jtf2=new JPasswordField(10);
c.add(jtf2);
jb=new JButton("OPEN");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
j3=new JLabel();
c.add(j3);

c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}

public void actionPerformed(ActionEvent ae) {

if(ae.getSource()==jb)
{

// String
user=jtf1.getText();
// String
password=jtf2.getText();

try{
File u = new File("c:/j2sdk1.4.1_01/bin/database/"+user);

if(u.exists()){
File p = new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password);

if(p.exists())
jtable = new Jtable(user,password);

else
j3.setText("YOUR PASSWORD IS WRONG");

}
else
j3.setText("USER DOES NOT EXISTS");
}
catch(Exception e){System.out.println(e);}
}
if(ae.getSource()==jb1) {
setVisible(false);}

}
}





















Search.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class search extends JFrame implements ActionListener
{

JTextField jtf1;
Container c ;
JLabel jl1,jl2,jl3,label;
JButton jb,jb1;
String username;
Juser j;
public search()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("ENTER USER NAME",JLabel.CENTER);
c.add(jl1);
jtf1=new JTextField(10);
c.add(jtf1);
jb=new JButton("SEARCH");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
jl3=new JLabel("",JLabel.CENTER);
c.add(jl3);

c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{

if(ae.getSource()==jb)
{
username=jtf1.getText();
//String
try{

File u=new File("c:/j2sdk1.4.1_01/bin/database/"+"/"+username);

if(u.exists())
{
jl3.setText(" USER EXISTS ");
}
else{
jl3.setText("USER DOES NOT EXIST");
}

}catch(Exception e){System.out.println(e);}

}
if(ae.getSource() == jb1)
{
setVisible(false);
}
}
}

Searchtab.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class searchtab extends JFrame implements ActionListener
{

JTextField jtf1;
Container c ;
JLabel jl1,jl2,jl3,label;
JButton jb,jb1;
String user="",password="";
String tabname;
Juser j;

public searchtab(String user,String password)
{
this.user=user;
this.password=password;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
setVisible(false);
}});

c =getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("ENTER TABLE NAME",JLabel.CENTER);
c.add(jl1);
jtf1=new JTextField(10);
c.add(jtf1);
jb=new JButton("SEARCH");
jb.addActionListener(this);
c.add(jb);
jb1=new JButton("CANCEL");
jb1.addActionListener(this);
c.add(jb1);
jl3=new JLabel("",JLabel.CENTER);
c.add(jl3);

c.setForeground(Color.black);
c.setBackground(Color.lightGray);
setBounds(250,200,300,150);
c.setLayout(new FlowLayout(FlowLayout.CENTER));
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{

if(ae.getSource()==jb)
{

tabname=jtf1.getText();
//String
try
{
File u=new File("c:/j2sdk1.4.1_01/bin/database/"+user+"/"+password+"/"+tabname+".txt");

if(u.exists())
{
jl3.setText(" TABLE EXISTS ");
}
else{
jl3.setText("TABLE DOES NOT EXIST");
}
}catch(Exception e){System.out.println(e);}

}
if(ae.getSource() == jb1)
{
setVisible(false);
}
}
}
OUTPUT FORMS
------------------------------------------------------------------------------------

TABLE OUTPUT












STORED DATABASE













SEARCHING USER BY NAME

















DELETING USER














SECURED DATABASE














TESTING
------------------------------------------------------------------------------------


Testing each module individually is called UNIT TESTING.
I have tested each module individually for its proper functioning.

Testing the software after combining the different modules is called SYSTEM TESTING.
I have integrated all the modules properly and tested the software for its proper functioning.

Running the system under live or realistic data by the actual user is called Acceptance Testing.
Realistic data that was given to our project is all the inputs that are been required by any user. For eg. I have added all the features that must be required to create a database.

We have also carried out the execution of our project by many of our friends and Ms. Pooja Gandhi (Java Faculty)

After being giving realistic conditions to our project, we have found the performance of our project quite satisfactory. This project can be implemented by any user.









Limitations and problems faced
-- ---------------------------------------------------------------------------------- -----------------------------------------------------------------------------------

LIMITATION:-

























Fall outs and suggestions for the
future work


Fall Outs:-

1. Any small working Institute like BMIET, APTECH, CMC Computer
center,TATA Infotech etc...
2. It can be beneficial for many Coaching Centers who have been teaching
many courses.


Suggestions for the Future work:-

1. This project can be extended for an Institute running on a large scale.
For e.g- NIIT.
2. Various facilities like college administrative work and whole student management system can be integrated in a single platform .

3. Society comprises of students and candidates who have been learning in
many Institutes. They also needed to access many kind of information at
various stages. If a manual procedure is being used by these Institutes,then
these students may face many difficulties like Institute time, holidays etc...




Conclusion
------------------------------------------------------------------------------------

Rather than using a manual procedure for an Institute, if this computerized project is being implemented then all the students, faculty members and Institute members like Administator can eliminate all the difficulties and can run the Institute successfully in an effective way.

Like students can access their information in a shorter period of time, faculty members convey their messages more effectively and Administrator himself can manage the complete /College Institute in a much better way.






















Books Referred


Java 2 The Complete Reference
-Tata McGraw Hill Publication.
Fundamentals of Java
-E Balaguruswamy

Other References

Microsoft Encyclopedia Encarta 2002.
http://www.javasun.com
http://www.google.com
http://www.altavista.net
http://www.download.com


No comments:

Post a Comment