Professional Documents
Culture Documents
APIIT SD INDIA
CE00396-1-OOEDP
Object Oriented & Event Driven Programming
Lecturer
Gaurav Gambhir
Submitted by:
Prince Kumar
Intake no: PT1082219
E-mail id: Pt1082219@apiit.edu.in
ACKNOWLEDGEMENT
Prince Kumar
ABSTRACT
Table of Contents
S.no Topic Page no:
2. Story Boarding 10
5. Assumptions 31
6. Conclusion 32
7. References 33
1. UML Diagram
1.1 Use Case Diagram...
System
Add
Delete
Search
Prisoner **
*
*
* *
**
Update
*
Find
*
Display
*
Add
* *
*
Warden **
* Delete
* *
* *
Users Update
*
Find
*
*
Display
*
Exit
Prisoner showpRecord
Welcome Frame
Decision
by user
Prisoner Warden
Add
Add
Delete
Delete
Find
Display
Release
Warden
Display
A sequence diagram in a Unified Modeling Language (UML) is a kind of interaction diagram that
shows how processes operate with one another and in what order. It is a construct of a Message
Sequence Chart. A sequence diagram shows object interactions arranged in time sequence. It
depicts the objects and classes involved in the scenario and the sequence of messages exchanged
between the objects needed to carry out the functionality of the scenario. Sequence diagrams
typically are associated with use case realizations in the Logical View of the system under
development.
Sequence diagrams are sometimes called event diagrams, event scenarios, and timing diagrams
Prisoner : Add Prisoner : Delete Prisoner : Release Prisoner : Find Prisoner : Display All
Add
Find
Display Result
Display Records
Find Prisoner
Return Prisoner
Return Records
2. Story Boarding
For Warden Window
Add
Prisoner
3. Source code
Save as : PMS.java
import java.awt.Color;
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public PMS()
{
c=getContentPane();
c.setLayout(null);
pnlWarden=new JPanel();
pnlWarden.setLayout(null);
pnlWarden.setBounds(new Rectangle(100,10,700,600));
pnlWarden.setBackground(Color.lightGray);
c.add(pnlWarden);
name=new JLabel("Warden ID: ");
name.setBounds(new Rectangle(90,200,100,30));
pnlWarden.add(name);
c.add(pnlWarden);
name = new JLabel("Warden Name: ");
name.setBounds(new Rectangle(90,250,100,30));
pnlWarden.add(name);
//name = new JLabel("Date Of Birth: ");
//name.setBounds(new Rectangle(90,150,100,30));
//pnlWarden.add(name);
name = new JLabel("Rank :");
name.setBounds(new Rectangle(90,300,100,30));
pnlWarden.add(name);
txtname = new JTextField();
txtname.setBounds(new Rectangle(200,250,120,30));
pnlWarden.add(txtname);
txtwardenid = new JTextField();
txtwardenid.setBounds(new Rectangle(200,200,120,30));
pnlWarden.add(txtwardenid);
cborank.addItem("5");
pnlWarden.add(cborank);
btndisplay.addActionListener(this);
btnupdate.addActionListener(this);
btnsearch.addActionListener(this);
btndelete.addActionListener(this);
btnadd.addActionListener(this);
pnlWarden.setVisible(true);
try {
con=db.getDBConnection();
i=ptmt.executeUpdate();
if(i>0)
{
JOptionPane.showMessageDialog(null, "Warden Inserted Successfully");
}
else {
JOptionPane.showMessageDialog(null, "Warden Not Inserted Successfully");
}
try {
con=db.getDBConnection();
String sql="SELECT * FROM WARDEN WHERE Warden_Id LIKE ?";
ptmt=con.prepareStatement(sql);
ptmt.setString(1, txtwardenid.getText());
ResultSet rs=ptmt.executeQuery();
while(rs.next())
{
txtwardenid.setText(rs.getString(1));
txtname.setText(rs.getString(2));
cborank.setSelectedItem(rs.getString(3));
}
if(i>0)
{
JOptionPane.showMessageDialog(null, "Warden DELETED Successfully");
}
else {
if(ev.getSource()==btndisplay)
{
showWardens ws=new showWardens();
ws.setVisible(true);
ws.setSize(700, 500);
}
Save as : prisonedbase.java
import java.sql.Connection;
import java.sql.*;
Save as : Prisoner.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
/**
*
*/
private static final long serialVersionUID = 1L;
Container c;
JPanel pnlPrisoner;
JLabel lblpid , lblname , lblsecuritylevel , lbldateofprison , lblrelease ;
JTextField txtid , txtname ;
JComboBox cboseclevel , cboddp , cbommp , cboyyp , cboddr , cbommr , cboyyr ;
JButton btndisplay, btnupdate, btnsearch, btndelete, btnadd ;
prisondbase mydb=new prisondbase();
public Prisoner()
{
c=getContentPane();
c.setLayout(null);
pnlPrisoner=new JPanel();
pnlPrisoner.setBounds(new Rectangle(10,10,780,600));
pnlPrisoner.setLayout(null);
pnlPrisoner.setBackground(Color.LIGHT_GRAY);
txtid=new JTextField();
txtname=new JTextField();
cboseclevel=new JComboBox();
cboseclevel.addItem("High");
cboseclevel.addItem("Low");
cboddp=new JComboBox();
cboddp.addItem("Day");
cboddp.addItem("1");
cboddp.addItem("2");
cboddp.addItem("3");
cboddp.addItem("4");
cboddp.addItem("5");
cboddp.addItem("6");
cboddp.addItem("7");
cboddp.addItem("8");
cboddp.addItem("9");
cboddp.addItem("10");
cboddp.addItem("11");
cboddp.addItem("12");
cboddp.addItem("13");
cboddp.addItem("14");
cboddp.addItem("15");
cboddp.addItem("16");
cboddp.addItem("17");
cboddp.addItem("18");
cboddp.addItem("19");
cboddp.addItem("20");
cboddp.addItem("21");
cboddp.addItem("23");
cboddp.addItem("24");
cboddp.addItem("25");
cboddp.addItem("26");
cboddp.addItem("27");
cboddp.addItem("28");
cboddp.addItem("29");
cboddp.addItem("30");
cboddp.addItem("31");
cbommp=new JComboBox();
cbommp.addItem("Month");
cbommp.addItem("1");
cbommp.addItem("2");
cbommp.addItem("3");
cbommp.addItem("4");
cbommp.addItem("5");
cbommp.addItem("6");
cbommp.addItem("7");
cbommp.addItem("8");
cbommp.addItem("9");
cbommp.addItem("10");
cbommp.addItem("11");
cbommp.addItem("12");
cboyyp=new JComboBox();
cboyyp.addItem("Year");
cboyyp.addItem("1980");
cboyyp.addItem("1981");
cboyyp.addItem("1982");
cboyyp.addItem("1983");
cboyyp.addItem("1984");
cboyyp.addItem("1985");
cboyyp.addItem("1986");
cboyyp.addItem("1987");
cboyyp.addItem("1988");
cboyyp.addItem("1989");
cboyyp.addItem("1990");
cboyyp.addItem("1991");
cboyyp.addItem("1992");
cboyyp.addItem("1993");
cboyyp.addItem("1994");
cboyyp.addItem("1995");
cboyyp.addItem("1996");
cboyyp.addItem("1997");
cboyyp.addItem("1998");
cboyyp.addItem("1999");
cboyyp.addItem("2000");
cboyyp.addItem("2001");
cboyyp.addItem("2002");
cboyyp.addItem("2003");
cboyyp.addItem("2004");
cboyyp.addItem("2005");
cboyyp.addItem("2006");
cboyyp.addItem("2007");
cboyyp.addItem("2008");
cboyyp.addItem("2009");
cboyyp.addItem("2010");
cboyyp.addItem("2011");
cboyyp.addItem("2012");
cboddr=new JComboBox();
cboddr.addItem("Day");
cboddr.addItem("1");
cboddr.addItem("2");
cboddr.addItem("3");
cboddr.addItem("4");
cboddr.addItem("5");
cboddr.addItem("6");
cboddr.addItem("7");
cboddr.addItem("8");
cboddr.addItem("9");
cboddr.addItem("10");
cboddr.addItem("11");
cboddr.addItem("12");
cboddr.addItem("13");
cboddr.addItem("14");
cboddr.addItem("15");
cboddr.addItem("16");
cboddr.addItem("17");
cboddr.addItem("18");
cboddr.addItem("19");
cboddr.addItem("20");
cboddr.addItem("21");
cboddr.addItem("23");
cboddr.addItem("24");
cboddr.addItem("25");
cboddr.addItem("26");
cboddr.addItem("27");
cboddr.addItem("28");
cboddr.addItem("29");
cboddr.addItem("30");
cboddr.addItem("31");
cbommr=new JComboBox();
cbommr.addItem("Month");
cbommr.addItem("1");
cbommr.addItem("2");
cbommr.addItem("3");
cbommr.addItem("4");
cbommr.addItem("5");
cbommr.addItem("6");
cbommr.addItem("7");
cbommr.addItem("8");
cbommr.addItem("9");
cbommr.addItem("10");
cbommr.addItem("11");
cbommr.addItem("12");
cboyyr =new JComboBox();
cboyyr.addItem("Year");
cboyyr.addItem("1980");
cboyyr.addItem("1981");
cboyyr.addItem("1982");
cboyyr.addItem("1983");
cboyyr.addItem("1984");
cboyyr.addItem("1985");
cboyyr.addItem("1986");
cboyyr.addItem("1987");
cboyyr.addItem("1988");
cboyyr.addItem("1989");
cboyyr.addItem("1990");
cboyyr.addItem("1991");
cboyyr.addItem("1992");
cboyyr.addItem("1993");
cboyyr.addItem("1994");
cboyyr.addItem("1995");
cboyyr.addItem("1996");
cboyyr.addItem("1997");
cboyyr.addItem("1998");
cboyyr.addItem("1999");
cboyyr.addItem("2000");
cboyyr.addItem("2001");
cboyyr.addItem("2002");
cboyyr.addItem("2003");
cboyyr.addItem("2004");
cboyyr.addItem("2005");
cboyyr.addItem("2006");
cboyyr.addItem("2007");
cboyyr.addItem("2008");
cboyyr.addItem("2009");
cboyyr.addItem("2010");
cboyyr.addItem("2011");
cboyyr.addItem("2012");
lblpid.setBounds(new Rectangle(50,80,100,30));
txtid.setBounds(new Rectangle(200,80,100,30));
lblname.setBounds(new Rectangle(50,130,100,30));
txtname.setBounds(new Rectangle(200,130,100,30));
lblsecuritylevel.setBounds(new Rectangle(50,180,100,30));
cboseclevel.setBounds(new Rectangle(200,180,100,30));
lbldateofprison.setBounds(new Rectangle(50,230,100,30));
cboddp.setBounds(new Rectangle(200,230,50,30));
cbommp.setBounds(new Rectangle(260,230,50,30));
cboyyp.setBounds(new Rectangle(320,230,100,30));
lblrelease.setBounds(new Rectangle(50,280,100,30));
cboddr.setBounds(new Rectangle(200,280,50,30));
cbommr.setBounds(new Rectangle(260,280,50,30));
cboyyr.setBounds(new Rectangle(320,280,100,30));
//buttons
pnlPrisoner.add(lblpid);
pnlPrisoner.add(txtid);
pnlPrisoner.add(lblname);
pnlPrisoner.add(txtname);
pnlPrisoner.add(lblsecuritylevel);
pnlPrisoner.add(cboseclevel);
pnlPrisoner.add(lbldateofprison);
pnlPrisoner.add(cboddp);
pnlPrisoner.add(cbommp);
pnlPrisoner.add(cboyyp);
pnlPrisoner.add(lblrelease);
pnlPrisoner.add(cboddr);
pnlPrisoner.add(cbommr);
pnlPrisoner.add(cboyyr);
pnlPrisoner.add(btndisplay);
pnlPrisoner.add(btnupdate);
pnlPrisoner.add(btnsearch);
pnlPrisoner.add(btndelete);
pnlPrisoner.add(btnadd);
c.add(pnlPrisoner);
btndisplay.addActionListener(this);
btnupdate.addActionListener(this);
btnsearch.addActionListener(this);
btndelete.addActionListener(this);
btnadd.addActionListener(this);
pnlPrisoner.setVisible(true);
}
public static void main(String[] args) {
Prisoner prison = new Prisoner ();
prison.setSize(815,700);
prison.setVisible(true);
}
@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent ev)
{
if(ev.getSource()==btnadd)
{
int i=0;
Connection con=mydb.getDBConnection();
String sql="INSERT INTO PRISON VALUES (?,?,?,?,?,?)";
PreparedStatement ptmt=con.prepareStatement(sql);
ptmt.setString(1, txtid.getText());
ptmt.setString(2,txtname.getText() );
ptmt.setString(3,(String)cboseclevel.getSelectedItem() );
ptmt.setDate(4, dop);
ptmt.setDate(5,dor );
ptmt.setString(6,"Not released" );
i=ptmt.executeUpdate();
if(i>0)
{
JOptionPane.showMessageDialog(null, "Prisoner Inserted Successfully");
}
else {
JOptionPane.showMessageDialog(null, "Prisoner Not Inserted Successfully");
}
} catch (Exception e) {
e.printStackTrace();
}
}
if(ev.getSource()==btnsearch)
{
Connection con=null;
PreparedStatement ptmt;
try {
con=mydb.getDBConnection();
ResultSet rs=ptmt.executeQuery();
while(rs.next())
{
txtid.setText(rs.getString(1));
txtname.setText(rs.getString(2));
cboseclevel.setSelectedItem(rs.getString(3));
cboddp.setSelectedItem(rs.getDate(6).getDate());
cbommp.setSelectedItem(rs.getDate(6).getMonth());
cboyyp.setSelectedItem(rs.getDate(6).getYear());
cboddr.setSelectedItem(rs.getDate(7).getDate());
cbommr.setSelectedItem(rs.getDate(7).getMonth());
cboyyr.setSelectedItem(rs.getDate(7).getYear());
}
} catch (Exception e) {
e.printStackTrace();
}
}
if(ev.getSource()==btndelete)
{
int i=0;
try {
Connection con3=mydb.getDBConnection();
String sql3 = "UPDATE PRISON SET Status=? WHERE PID=?";
PreparedStatement ptmt3 = con3.prepareStatement(sql3);
ptmt3.setString(1, "Dead");
ptmt3.setString(2, txtid.getText());
i = ptmt3.executeUpdate();
if(i>0)
{
JOptionPane.showMessageDialog(null,"Prisoner Successfully
deletd");
}
else
{
JOptionPane.showMessageDialog(null,"Prisoner Successfully Not
deletd");
}
}
if(ev.getSource()==btnupdate)
{
ResultSet rs = null;
int dd, mm, yy;
int totaldaysLeft = 0;
Calendar cd = Calendar.getInstance();
Date dateOfRelese = null, dateDifference = null;
try {
Connection con = mydb.getDBConnection();
String sql = "SELECT * FROM PRISON WHERE PID LIKE ?";
PreparedStatement ptmt = con.prepareStatement(sql);
ptmt.setString(1, txtid.getText());
rs = ptmt.executeQuery();
while (rs.next()) {
dateOfRelese = rs.getDate(6);
}
dd = dateOfRelese.getDate();
mm = dateOfRelese.getMonth();
yy = dateOfRelese.getYear();
con.close();
ptmt.close();
cd.set(yy, mm, dd);
System.out.println(cd);
dateDifference = new Date(cd.getTimeInMillis()
- Calendar.getInstance().getTimeInMillis());
System.out.println(dateDifference);
totaldaysLeft = dateDifference.getDay();
System.out.println("Total days left+"+totaldaysLeft);
if (totaldaysLeft > 7) {
JOptionPane.showMessageDialog(null,
"The Prisoner Could not be released");
} else {
int i = 0;
try {
}
else {
JOptionPane.showMessageDialog(null,
"Prisoner Couldnot Be Released");
}
if (rs == null) {
JOptionPane.showMessageDialog(null,
"Prisoner Couldnot Be Found");
}
}
if(ev.getSource()==btndisplay)
{
showpRecord ps=new showpRecord();
ps.setVisible(true);
ps.setVisible(true);
}
}
}
Save as : showpRecord
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;
Container c;
DefaultTableModel prisonerTablemodel;
prisondbase db=new prisondbase();
Vector<String> prisonVector;
JTable prisonTable;
showpRecord()
{
c=getContentPane();
setSize(1300,700);
setTitle("Records For Prisoner ");
c.setBackground(Color.white);
c.setLayout(null);
setResizable(false);
String pRecord[]={"Prisoner ID","Name"," Security Level ","Date Of Prison","Date Of
Release","Status"};
prisonerTablemodel=new DefaultTableModel(pRecord,0);
prisonTable=new JTable(prisonerTablemodel);
JScrollPane jspPrisoner=new JScrollPane(prisonTable);
jspPrisoner.setSize(1150, 700);
c.add(jspPrisoner);
try{
Connection con=db.getDBConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from PRISON");
while(rs.next())
{
prisonVector=new Vector<String>();
prisonVector.add(rs.getString(1));
prisonVector.add(rs.getString(2));
prisonVector.add(rs.getString(3));
prisonVector.add(rs.getString(4));
prisonVector.add(rs.getString(5));
prisonVector.add(rs.getString(6));
prisonerTablemodel.addRow(prisonVector);
}
st.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
setVisible(true);
setDefaultCloseOperation(3);
}
}
Save as : showWardens.java
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;
Container c;
DefaultTableModel WardenTablemodel;
prisondbase db=new prisondbase();
Vector<String> WVector;
JTable WardenTable;
showWardens()
{
c=getContentPane();
setSize(1000,700);
setTitle("Records For Warden ");
c.setBackground(Color.white);
c.setLayout(null);
setResizable(false);
String pRecord[]={"Warden ID"," Name "," Rank "};
WardenTablemodel=new DefaultTableModel(pRecord,0);
WardenTable=new JTable(WardenTablemodel);
JScrollPane jspWarden=new JScrollPane(WardenTable);
jspWarden.setSize(900, 700);
c.add(jspWarden);
ResultSet rs=null;
try{
Connection con=db.getDBConnection();
Statement st=con.createStatement();
rs=st.executeQuery("Select * from WARDEN");
while(rs.next())
{
WVector=new Vector<String>();
WVector.add(rs.getString(1));
WVector.add(rs.getString(2));
WVector.add(rs.getString(3));
WardenTablemodel.addRow(WVector);
}
st.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}
setDefaultCloseOperation(3);
}
4. Sample Output
Prisoner Form
Warden Form
5. Assumptions
Due to limited knowledge the following assumptions were made in the assignment:
validations on the textboxes have not been given, so it has been assumed that the user
enters correct data
all the functionalities like add, delete, find etc are given on the same page
combo box has not been used to select warden id while adding a prisoner .
6. Conclusion
Finally completing this assignment I came to know more about Object oriented.
I have to implement some of the features of java to design Prisoner management
system. This assignment based on Prisoner management through database.
During the completion of the assignment, I have learned a many new things like
working with swing, action listeners. Now i can create Stand Alone
Application easily. I have become well aware of the following concepts of java:
Arrays
Classes
Objects
Constructors
Inheritance
Exception Handling
Abstract classes
Interface
Polymorphism
Looping
7.References
[3] Dietel, H.M. & Dietel, P.J. (2001) Java: How to Program, Prentice Hall. (ISBN:
0130341517)