SlideShare a Scribd company logo
1 of 76
Download to read offline
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 1 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
TABLE OF CONTENTS
INTRODUCTION............................................................................................................................................ 2
UML DIAGRAM ............................................................................................................................................ 2
(CLASS DIAGRAM)........................................................................................................................................ 3
USE CASE DIAGRAMS:-................................................................................................................................. 8
ACTIVITY DIAGRAM...................................................................................................................................... 9
SEQUENCE DIAGRAM................................................................................................................................. 10
SOURCE CODES OF PROGRAMS:-................................................................................................................ 11
SAMPLE OUTPUTS AND EXPLANATIONS ..................................................................................................... 71
ADDITIONAL FEATURES.............................................................................................................................. 75
ASSUMPTIONS........................................................................................................................................... 76
REFERENCES............................................................................................................................................... 76
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 2 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
INTRODUCTION
Java is a general purpose, object-oriented programming is. Java, TV sets, consumer
electronics, within the framework of a research, VCRs, toasters machines you can buy in
a store is designed to develop other types of software. Java (Java 1.0), the first public
release of a version of the Java language and the release to establish libraries, meanwhile,
was published in 1995.Coming to the assignment, we are required to develop an
application i.e. prisoner management system which would be helpful for warden and police
to use application and can find details of the prisoner using Java as a programming
language. In this project we had created different forms to update and retrieve the data
from the database. In this project we had created a main menu form where, the entire
management system is controlled by the administrator. In this menu form we had
provided links to other forms to add, search, update, delete, and view all details of the
prisoner, wardens. (Tata McGraw-Hill, 2007)
UML DIAGRAM
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 3 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
(Class Diagram)
Login page
Home page of prison management system:-
Prisoner add page:-
MyFrame1
~f: JFrame
~ok: JButton
~cancel: JButton
~lblLogin: JLabel
~lblpassword: JLabel
~r: JLabel
~txtusername: JTextField
~txtpassword: JTextField
<<create>>~MyFrame1()
+init()
+main(args: String)
+actionPerformed(e: ActionEvent)
MyFrame2
~menuadd_prisoner: JMenuItem
~menuupdate_prisoner: JMenuItem
~menuadd_warden: JMenuItem
~menuupdate_warden: JMenuItem
~menudisplaypriso: JMenuItem
~menudisplaywarden: JMenuItem
~menulogout: JMenuItem
+pnladd: JPanel
+pnlupdate: JPanel
+prisoner: JLabel
~f: JFrame
+menu()
+main(args: String)
+actionPerformed(e: ActionEvent)
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 4 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Prisoner update page:-
Prisoner
~f: JFrame
~btnadd: JButton
~btncncl: JButton
~btnclr: JButton
~lblid: JLabel
~lblname: JLabel
~lbladdress: JLabel
~lbldoc: JLabel
~lblcrime_desc: JLabel
~lbldate_prison: JLabel
~lbldate_rel: JLabel
~r: JLabel
~txtid: JTextField
~txtname: JTextField
~txtaddress: JTextField
~txtdoc: JTextField
~txtcrime_desc: JTextField
~txtdate_prison: JTextField
~txtdate_rel: JTextField
-id: String
-name: String
-address: String
-date_of_crime: String
-crime_description: String
-date_of_prisonment: String
-date_of_release: String
+details()
+main(args: String)
+actionPerformed(e: ActionEvent)
~add()
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 5 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Prisoner1
~f: JFrame
~btnfind: JButton
~btnrel: JButton
~btndel: JButton
~btnupdate: JButton
~btnclr: JButton
~lblid: JLabel
~lblname: JLabel
~lblcrime_desc: JLabel
~r: JLabel
~txtid: JTextField
~txtname: JTextField
~txtcrime_desc: JTextField
-id: String
-name: String
-address: String
-date_of_crime: String
-crime_description: String
-date_of_prisonment: String
-date_of_release: String
-status: String
+init()
+main(args: String)
+actionPerformed(e: ActionEvent)
~Find(id: int): boolean
~delete(id: int)
~Update()
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 6 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Warden page of add and update:-
Wardens_add
~f: JFrame
~btnadd: JButton
~btncncl: JButton
~btnclr: JButton
~lblid: JLabel
~lblname: JLabel
~lbladdress: JLabel
~lblwarden_rank: JLabel
~lblyr_join: JLabel
~lblretire: JLabel
~r: JLabel
~txtid: JTextField
~txtname: JTextField
~txtaddress: JTextField
~txtwarden_rank: JTextField
~txtyr_join: JTextField
~txtwarden_retire: JTextField
-id: String
-name: String
-address: String
-warden_rank: String
-warden_year: String
-warden_retire: String
+information()
+main(args: String)
+actionPerformed(e: ActionEvent)
~add()
Warden_details
~f: JFrame
~btnfind: JButton
~btndel: JButton
~btnupdate: JButton
~btnclr: JButton
~btncncl: JButton
~lbl_id: JLabel
~lblname: JLabel
~lbladdress: JLabel
~lblwarden_rank: JLabel
~lblyr_warden: JLabel
~lblretire: JLabel
~r: JLabel
~txtid: JTextField
~txtname: JTextField
~txtaddress: JTextField
~txtwarden_rank: JTextField
~txtwarden_year: JTextField
~txtwarden_retire: JTextField
-id: String
-name: String
-address: String
-warden_rank: String
-warden_year: String
-warden_retire: String
+init()
+main(args: String)
+actionPerformed(e: ActionEvent)
~Find(id: int): boolean
~delete(id: int)
~Update()
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 7 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Reports of prisoner and warden page:-
Report2
-flag: boolean = true
~lstrpt: List
<<create>>+Report2()
+itemStateChanged(e: ItemEvent)
+windowOpened(e: WindowEvent)
+windowClosing(e: WindowEvent)
+windowClosed(e: WindowEvent)
+windowIconified(e: WindowEvent)
+windowDeiconified(e: WindowEvent)
+windowActivated(e: WindowEvent)
+windowDeactivated(e: WindowEvent)
+main(args: String)
Report1
-flag: boolean = true
~lstrpt: List
<<create>>+Report1()
+itemStateChanged(e: ItemEvent)
+windowOpened(e: WindowEvent)
+windowClosing(e: WindowEvent)
+windowClosed(e: WindowEvent)
+windowIconified(e: WindowEvent)
+windowDeiconified(e: WindowEvent)
+windowActivated(e: WindowEvent)
+windowDeactivated(e: WindowEvent)
+main(args: String)
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 8 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Use Case Diagrams:-
PMS
Login
Admin
PMS
Prisoner
Warden
Reports
Add
Update Prisoner
details
Add
Update Warden
details
Display all
prisoners
Display all wardens
Logout
<<includes>>
<<includes>>
<<includes>>
<<includes>>
<<includes>>
<<includes>>
<<includes>>
<<includes>>
«extends»
«extends»
<<includes>>
Find
«extends»
Release«extends»
Delete
«extends»
Update
<<includes>>
Find
<<includes>>
Cancel Clear
«extends»
Delete
«extends»
Update
<<includes>>
«extends»
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 9 of 76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Activity diagram
Login
Prisoner
[Username Or Password
]
PMS
Warden Reports
Add Prisoner Update Prisoner
ADD
CANCEL
CLEAR
Find
Update
Release
Delete
Add Warden Update Warden
ADD
CLEAR
CANCEL
Find
Update
CLEAR
Delete
Display All Prisoners Display All Wardens
CLEAR CANCEL
Logout
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 10 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Sequence diagram
PMS Login Add Find Update Delete Release Database
Username
Add prisoner
Find Prisoner
Prisoner Details
Prisoner Details
Update Prisoner All Fill Up Details Update
Delete Prisoner All Details Delete
Release Prisoner
ADD PRISONER
FIND PRISONER
UPDATE PRISONER
DELETE PRISONER
Password
Add Prisoner Details on Database
Add prisoner details
Search detailsFill the Prisoner data
All Changed details
Updates prisoner details
Deletes the informationDelete entire Details of Prisoner
status changed
RELEASE PRISONER
Add Warden
Add Warden Details
Add The all Warden Details
Provides all details
ADD WARDEN
Find Warden
Find Warden Details
Finds The Warden Details
Find the warden details from database
Update Warden
Updates The Warden Details
Updates The Warden Details
Updates all the details on Data Base
FIND WARDEN
UPDATE WARDEN
Prisoner Releases
All Status Changes
Delete Warden
Delete entire details Of Warden
Delete Warden Details
Delete all The Warden Details On Data Base DELETE WARDEN
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 11 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
SOURCE CODES OF PROGRAMS:-
i) Login Page:
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** Creating a class MyFrame1 and implementing the interface ActionListener */
class MyFrame1 implements ActionListener
{
/** Declaring the variables*/
/** Declaring the JFrame variable f*/
JFrame f;
JButton ok,cancel;
JLabel lblLogin,lblpassword,r;
JTextField txtusername,txtpassword;
/** Constructor Creation */
MyFrame1() /** Creates new form MyFrame1 */
{
f=new JFrame();
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 12 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
r=new JLabel("LOGIN DETAILS");
r.setForeground(Color.YELLOW);
r.setBounds(510,85,480,55);
f.add(r);
/** Making the frame maximized*/
f.setSize(1580,1250);
Font t=new Font("Dialog",Font.BOLD,55);
r.setFont(t);
/**Object Creation*/
lblLogin=new JLabel("USERNAME");
lblLogin.setForeground(Color.GREEN);
lblLogin.setBounds(100,270,200,20);
f.add(lblLogin);
Font k=new Font("Dialog",Font.BOLD,25);
lblLogin.setFont(k);
lblpassword=new JLabel("PASSWORD");
lblpassword.setForeground(Color.GREEN);
lblpassword.setBounds(100,330,225,50);
f.add(lblpassword);
Font p=new Font("Dialog",Font.BOLD,25);
lblpassword.setFont(p);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 13 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtusername=new JTextField(10);
txtusername.setBounds(280,265,180,30);
f.add(txtusername);
txtpassword=new JPasswordField(10);
txtpassword.setBounds(280,340,180,30);
f.add(txtpassword);
ok=new JButton("OK");
cancel=new JButton("CANCEL");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/** Defining the method init*/
public void init()
{
ok.setBounds(105,440,160,25);
ok.addActionListener(this);
f.add(ok);
cancel.setBounds(300,440,160,25);
cancel.addActionListener(this);
f.add(cancel);
JLabel image_back=new JLabel("");
image_back.setIcon(new ImageIcon("login.jpg"));
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 14 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(image_back);
image_back.setBounds (1,0,1700,700);
f.setLayout(null);
/**Making the Frame visible*/
f.setVisible(true);
}
/** Main Method*/
public static void main(String args[])
{
MyFrame1 f=new MyFrame1();
f.init();
}
/** Providing the implementation of the method of the Interface*/
public void actionPerformed(ActionEvent e)
{
JButton bt=(JButton)e.getSource();
String str=bt.getLabel();
if(str.equals("CANCEL"))
System.exit(0);
else if(str.equals("OK")){
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 15 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
String txtid1=txtusername.getText();
String txtname1=txtpassword.getText();
if (( txtid1.equals(""))||(txtname1.equals("")) )
{
JOptionPane.showMessageDialog(null,"Text field is empty ");
//Validation to check empty or not
}
else if
(e.getSource()==ok)
{
MyFrame2 f=new MyFrame2();
f.menu();
}
}
}
}
ii) Home Page (PMS):-
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
import java.awt.event.*;
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 16 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
import javax.swing.*;
/** Creating a class MyFrame2 and implementing the interface ActionListener*/
class MyFrame2 extends JFrame implements ActionListener
{
/** Declaring the variables*/
JMenuItem menuadd_prisoner, menuupdate_prisoner,menuadd_warden,
menuupdate_warden,menudisplaypriso,menudisplaywarden,menulogout;
public JPanel pnladd, pnlupdate;
public JLabel prisoner;
/** Declaring the JFrame variable f*/
JFrame f;
/** Constructor Creation */
public void menu()
{
f=new JFrame();
f.setTitle("PRISON MANAGEMENT SYSTEM");
prisoner=new JLabel("PRISONER MANAGEMENT SYSTEM");
prisoner.setForeground(Color.GREEN);
prisoner.setBounds(11,85,1550,60);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 17 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(prisoner);
Font t=new Font("Dialog",Font.BOLD,80);
prisoner.setFont(t);
f.setSize(1580,1250);
f.setLocation(100,100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menubar=new JMenuBar();
f.setJMenuBar(menubar);
JMenu filemenu =new JMenu("Prisoner");
menubar.add(filemenu);
menuadd_prisoner = new JMenuItem("Add");
menuupdate_prisoner= new JMenuItem("Update");
menuadd_prisoner.add(new JSeparator());
menuupdate_prisoner.add(new JSeparator());
JMenu filemenu1 =new JMenu("Warden");
menubar.add(filemenu1);
menuadd_warden = new JMenuItem("Add");
menuupdate_warden= new JMenuItem("Update");
menuadd_warden.add(new JSeparator());
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 18 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
menuupdate_warden.add(new JSeparator());
filemenu.add(menuadd_prisoner);
menuadd_prisoner.addActionListener(this);
filemenu.add(menuupdate_prisoner);
menuupdate_prisoner.addActionListener(this);
filemenu1.add(menuadd_warden);
menuadd_warden.addActionListener(this);
filemenu1.add(menuupdate_warden);
menuupdate_warden.addActionListener(this);
JMenu filemenu2 =new JMenu("Reports");
menubar.add(filemenu2);
menudisplaypriso=new JMenuItem("Display the prisoner");
menudisplaywarden=new JMenuItem("Display the warden");
menudisplaypriso.add(new JSeparator());
menudisplaywarden.add(new JSeparator());
filemenu2.add(menudisplaypriso);
menudisplaypriso.addActionListener(this);
filemenu2.add(menudisplaywarden);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 19 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
menudisplaywarden.addActionListener(this);
JMenu filemenu3 =new JMenu("Logout");
menubar.add(filemenu3);
menulogout=new JMenuItem("Logout completely");
filemenu3.add(menulogout);
menulogout.addActionListener(this);
/**Adding backgroung image*/
JLabel image_back=new JLabel("");
image_back.setIcon(new ImageIcon("prison.jpg"));
f.add(image_back);
image_back.setBounds (40,0,1700,700);
f.setLayout(null);
/**Making the Frame visible*/
f.setVisible(true);
}
/** Main Method*/
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 20 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
public static void main(String args[])
{
MyFrame2 f=new MyFrame2();
f.menu();
}
public void actionPerformed(ActionEvent e)
{
/** Methods are called on the basis of the click of the menuitem*/
if (e.getSource()==menuadd_prisoner)
{
Prisoner f1=new Prisoner();
f1.details();
}
else if (e.getSource()==menuupdate_prisoner)
{
Prisoner1 f=new Prisoner1();
f.init();
}
else if (e.getSource()==menuadd_warden)
{
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 21 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Wardens_add f=new Wardens_add();
f.information();
}
else if (e.getSource()==menuupdate_warden)
{
Warden_details f=new Warden_details();
f.init();
}
else if (e.getSource()==menudisplaypriso)
{
Report1 r=new Report1();
}
else if (e.getSource()==menudisplaywarden)
{
Report2 r=new Report2();
}
else if (e.getSource()==menulogout)
{
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 22 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
MyFrame1 f1=new MyFrame1();
f1.init();
f.setVisible(false);
}
}
}
iii) Prisoner page (For adding a Prisoner):
/** Importing in order to use the predefined methods and classes*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
/** Creating a class Prisoner and implementing the interface ActionListener*/
public class Prisoner implements ActionListener
{
/** Declaring the variables*/
/** Declaring the JFrame variable f*/
JFrame f;
JButton btnadd,btncncl,btnclr;
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 23 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
JLabel lblid,lblname,lbladdress,lbldoc,lblcrime_desc,lbldate_prison,lbldate_rel,r;
JTextField txtid,txtname,txtaddress,txtdoc,txtcrime_desc,txtdate_prison,txtdate_rel;
private String id,name,address,date_of_crime, crime_description, date_of_prisonment,
date_of_release;
/** Constructor Creation */
public void details()
{
f=new JFrame();
r=new JLabel("PRISONER DETAILS");
r.setBounds(390,75,800,65);
f.add(r);
Font t=new Font("Showcard Gothic",Font.BOLD,65);
r.setFont(t);
/**Object Creation*/
lblid=new JLabel(" Prisoner Id.");
lblid.setBounds(100,170,200,20);
f.add(lblid);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 24 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Font k=new Font("Dialog",Font.BOLD,25);
lblid.setFont(k);
lblname=new JLabel("NAME");
lblname.setBounds(100,230,225,50);
f.add(lblname);
Font p=new Font("Dialog",Font.BOLD,25);
lblname.setFont(p);
lbladdress=new JLabel("Address");
lbladdress.setBounds(100,300,225,50);
f.add(lbladdress);
Font a=new Font("Dialog",Font.BOLD,25);
lbladdress.setFont(a);
lbldoc=new JLabel("Date of crime");
lbldoc.setBounds(100,370,225,50);
f.add(lbldoc);
Font q=new Font("Dialog",Font.BOLD,25);
lbldoc.setFont(q);
lblcrime_desc=new JLabel("Crime Description");
lblcrime_desc.setBounds(100,440,225,50);
f.add(lblcrime_desc);
Font x=new Font("Dialog",Font.BOLD,25);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 25 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
lblcrime_desc.setFont(x);
lbldate_prison=new JLabel("Date of prisonment");
lbldate_prison.setBounds(100,540,225,50);
f.add(lbldate_prison);
Font w=new Font("Dialog",Font.BOLD,25);
lbldate_prison.setFont(w);
lbldate_rel=new JLabel("Date of Release");
lbldate_rel.setBounds(100,580,225,50);
f.add(lbldate_rel);
Font y=new Font("Dialog",Font.BOLD,25);
lbldate_rel.setFont(y);
txtid=new JTextField(10);
txtid.setBounds(280,170,299,30);
f.add(txtid);
txtname=new JTextField(10);
txtname.setBounds(280,239,299,30);
f.add(txtname);
txtaddress=new JTextField(10);
txtaddress.setBounds(280,310,299,30);
f.add(txtaddress);
txtdoc=new JTextField(10);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 26 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtdoc.setBounds(280,380,299,30);
f.add(txtdoc);
txtcrime_desc=new JTextField(10);
txtcrime_desc.setBounds(324,430,299,110);
f.add(txtcrime_desc);
txtdate_prison=new JTextField(10);
txtdate_prison.setBounds(360,550,299,30);
f.add(txtdate_prison);
txtdate_rel=new JTextField(10);
txtdate_rel.setBounds(360,594,299,30);
f.add(txtdate_rel);
btnadd=new JButton("ADD");
btnadd.setBounds(105,658,120,35);
f.add(btnadd);
btnadd.addActionListener(this);
btncncl=new JButton("CANCEL");
btncncl.setBounds(280,658,120,35);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 27 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(btncncl);
btncncl.addActionListener(this);
btnclr=new JButton("CLEAR");
btnclr.setBounds(435,658,120,35);
f.add(btnclr);
btnclr.addActionListener(this);
/** Making the frame maximized*/
f.setSize(1200,900);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLayout(null);
/**Making the Frame visible*/
f.setVisible(true);
}
/** Main Method*/
public static void main(String args[])
{
Prisoner f=new Prisoner();
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 28 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.details();
}
/** Providing the implementation of the method of the Interface*/
public void actionPerformed(ActionEvent e)
{
name=txtname.getText();
address=txtaddress.getText();
date_of_crime=txtdoc.getText();
id=txtid.getText();
crime_description=txtcrime_desc.getText();
date_of_prisonment=txtdate_prison.getText();
date_of_release=txtdate_rel.getText();
JButton b=(JButton)e.getSource();
String str=b.getLabel();
if(str.equals("CLEAR")){
txtid.setText("");
txtname.setText("");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 29 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtaddress.setText("");
txtdoc.setText("");
txtcrime_desc.setText("");
txtdate_prison.setText("");
txtdate_rel.setText("");
}else if(str.equals("CANCEL")){
f.dispose();
}else if(str.equals("ADD")){
String txtid1=txtid.getText();
String txtname2=txtname.getText();
String txtaddress3=txtaddress.getText();
String txtdoc4=txtdoc.getText();
String txtcrime_desc5=txtcrime_desc.getText();
String txtdate_prison6=txtdate_prison.getText();
String txtdate_rel7=txtdate_rel.getText();
add();
if((txtid1.equals(""))||(txtname2.equals(""))||(txtaddress3.equals(""))||(txtdoc4.equals(""))||(txtcrim
e_desc5.equals(""))||(txtdate_prison6.equals(""))||(txtdate_rel7.equals("")))
JOptionPane.showMessageDialog(null, "Text field is empty");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 30 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
else
JOptionPane.showMessageDialog(null, "Prisoner details added
successfully");
}}
void add(){ //Adding details to the database
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
//Connection connect = DriverManager.getConnection("jdbc:odbc:employee");
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "insert into prisoner_details
(id,name,address,date_of_crime,crime_description,date_of_prisonment,date_of_release ) values
('" + id + "','" + name + "','" + address + "','" + date_of_crime + "','" + crime_description +"','"
+date_of_prisonment + "','" + date_of_release +"')";
state.execute(sql);
// JOptionPane.showMessageDialog(null, "Record added Successfully");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 31 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
System.out.println("Statement executed successfully");
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
}
}
iv) Prisoner page (For updating details of a Prisoner):
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/** Creating a class Prisoner and implementing the interface ActionListener*/
class Prisoner1 implements ActionListener
{
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 32 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
/** Declaring the variables*/
/** Declaring the JFrame variable f*/
JFrame f;
JButton btnfind,btnrel,btndel,btnupdate,btnclr;
JLabel lblid,lblname,lblcrime_desc,r;
JTextField txtid,txtname,txtcrime_desc;
private String id,name,address,date_of_crime,crime_description, date_of_prisonment,
date_of_release,status;
/** Constructor Creation */
public void init()
{
f=new JFrame();
r=new JLabel("UPDATE PRISONER DETAILS");
r.setBounds(210,95,1080,75);
f.add(r);
Font t=new Font("Showcard Gothic",Font.BOLD,65);
r.setFont(t);
/**Object Creation*/
lblid=new JLabel(" Prisoner Id.");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 33 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
lblid.setBounds(10,190,400,20);
f.add(lblid);
Font k=new Font("Dialog",Font.BOLD,25);
lblid.setFont(k);
lblname=new JLabel("NAME");
lblname.setBounds(10,225,200,50);
f.add(lblname);
Font p=new Font("Dialog",Font.BOLD,25);
lblname.setFont(p);
lblcrime_desc=new JLabel("Crime Description");
lblcrime_desc.setBounds(10,280,225,50);
f.add(lblcrime_desc);
Font x=new Font("Dialog",Font.BOLD,25);
lblcrime_desc.setFont(x);
txtid=new JTextField(10);
txtid.setBounds(190,190,250,26);
f.add(txtid);
txtname=new JTextField(10);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 34 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtname.setBounds(140,239,250,26);
f.add(txtname);
txtcrime_desc=new JTextField(10);
txtcrime_desc.setBounds(240,275,370,86);
f.add(txtcrime_desc);
btnfind=new JButton("FIND");
btnfind.setBounds(65,380,120,35);
btnfind.addActionListener(this);
f.add(btnfind);
btnrel=new JButton("RELEASE");
btnrel.setBounds(205,380,120,35);
btnrel.addActionListener(this);
f.add(btnrel);
btndel=new JButton("DELETE");
btndel.setBounds(335,380,120,35);
btndel.addActionListener(this);
f.add(btndel);
btnupdate=new JButton("UPDATE");
btnupdate.setBounds(475,380,120,35);
btnupdate.addActionListener(this);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 35 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(btnupdate);
btnclr=new JButton("CLEAR");
btnclr.setBounds(630,380,120,35);
btnclr.addActionListener(this);
f.add(btnclr);
btnrel.setEnabled(false);
btndel.setEnabled(false);
btnupdate.setEnabled(false);
/** Making the frame maximized*/
f.setSize(1200,900);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(null);
/**Making the Frame visible*/
f.setVisible(true);
}
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 36 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
/** Main Method*/
public static void main(String args[])
{
Prisoner1 f=new Prisoner1();
f.init();
}
/** Providing the implementation of the method of the Interface*/
public void actionPerformed(ActionEvent e)
{
id=txtid.getText();
name=txtname.getText();
crime_description=txtcrime_desc.getText();
int i=0;
try{
i=Integer.parseInt(id);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 37 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
}
catch(Exception ex){}
JButton b=(JButton)e.getSource();
String str=b.getLabel();
if(str.equals("FIND")){
if(txtid.getText().trim().length()!=0) //Validation in
order to show provided message
Find(i);
else
JOptionPane.showMessageDialog(null, "Text field is empty");
}
else if(str.equals("CLEAR")){
txtid.setText("");
txtname.setText("");
txtcrime_desc.setText("");
}else if(e.getSource()==btnrel){
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 38 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Int conf=JOptionPane.showConfirmDialog(null,"Release the
prisoner","Message",JOptionPane.OK_CANCEL_OPTION);
String id=txtid.getText();
if (conf==0)
{
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
//Connection connect = DriverManager.getConnection("jdbc:odbc:employee");
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "update prisoner_details set status=' prisoner released' where id="+id+"";
state.execute(sql);
//JOptionPane.showConfirmDialog(null,"prisoner released");
System.out.println("Statement executed successfully");
state.close();
connect.close();
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 39 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
}
catch (Exception ex) {
System.out.print(ex);
}}
}else if(str.equals("UPDATE")){
Update();
}else if(str.equals("DELETE")){
delete(i);
}
if ((id.equals(""))||(name.equals(""))||(crime_description.equals("")))
{
}
}
boolean Find(int id){
boolean flag=false;
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 40 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "select * from prisoner_details where id="+ id +" and status='prisoned'";
ResultSet rs=state.executeQuery(sql);
if(rs.next())
{
txtid.setText(rs.getString("id"));
txtname.setText(rs.getString("name"));
txtcrime_desc.setText(rs.getString("crime_description"));
flag=true;
btnrel.setEnabled(true);
btndel.setEnabled(true);
btnupdate.setEnabled(true);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 41 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
JOptionPane.showMessageDialog(null, "Record Found
Successfully");
}
else
JOptionPane.showMessageDialog(null, "Check prisoner id and try again ");
rs.close();
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
return flag;
}
void delete(int id){
try{
/** Written in try block, in order to catch the Exception*/
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 42 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "DELETE FROM prisoner_details WHERE id="+ id +"";
state.execute(sql);
// JOptionPane.showMessageDialog(null, "Record deleted Successfully");
System.out.println("Statement executed successfully");
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
}
void Update(){
try{
/** Written in try block, in order to catch the Exception*/
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 43 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
int i=Integer.parseInt(id);
String sql = "UPDATE prisoner_details set id= "+id+", name= '"+name+"',
crime_description='"+crime_description+"' WHERE id= "+id+"";
state.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Record Updated Successfully");
System.out.println("Statement executed successfully");
state.close(); connect.close();
} catch (Exception e) { System.out.print(e);
}
}
}
v) Warden page (For adding details of a Warden):
/** Importing in order to use the predefined methods and classes*/
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 44 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
/** Creating a class Wardens_add and implementing the interface ActionListener*/
class Wardens_add implements ActionListener
{
/** Declaring the variables*/
/** Declaring the JFrame variable f*/
JFrame f;
JButton btnadd,btncncl,btnclr;
JLabel lblid,lblname,lbladdress,lblwarden_rank,lblyr_join,lblretire,r;
JTextField txtid,txtname,txtaddress,txtwarden_rank,txtyr_join,txtwarden_retire;
private String id,name,address,warden_rank,warden_year,warden_retire;
/** Constructor Creation */
public void information()
{
f=new JFrame();
r=new JLabel("WARDEN DETAILS");
r.setBounds(310,95,800,65);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 45 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(r);
Font t=new Font("Showcard Gothic",Font.BOLD,85);
r.setFont(t);
/**Object Creation*/
lblretire=new JLabel("Warden retirement");
lblretire.setBounds(100,490,500,20);
f.add(lblretire);
Font b=new Font("Dialog",Font.BOLD,25);
lblretire.setFont(b);
lblid=new JLabel("Id.");
lblid.setBounds(100,170,200,20);
f.add( lblid);
Font k=new Font("Dialog",Font.BOLD,25);
lblid.setFont(k);
lblname=new JLabel("NAME");
lblname.setBounds(100,230,225,50);
f.add(lblname);
Font p=new Font("Dialog",Font.BOLD,25);
lblname.setFont(p);
lbladdress=new JLabel("Address");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 46 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
lbladdress.setBounds(100,300,225,50);
f.add(lbladdress);
Font a=new Font("Dialog",Font.BOLD,25);
lbladdress.setFont(a);
lblwarden_rank=new JLabel("Warden Rank");
lblwarden_rank.setBounds(100,370,225,50);
f.add(lblwarden_rank);
Font q=new Font("Dialog",Font.BOLD,25);
lblwarden_rank.setFont(q);
lblyr_join=new JLabel("Warden year of joining");
lblyr_join.setBounds(100,420,275,50);
f.add(lblyr_join);
Font x=new Font("Dialog",Font.BOLD,25);
lblyr_join.setFont(x);
txtid=new JTextField(10);
txtid.setBounds(280,180,250,30);
f.add(txtid);
txtname=new JTextField(10);
txtname.setBounds(280,239,250,30);
f.add(txtname);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 47 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtaddress=new JTextField(10);
txtaddress.setBounds(280,310,250,50);
f.add(txtaddress);
txtwarden_rank=new JTextField(10);
txtwarden_rank.setBounds(280,380,170,30);
f.add(txtwarden_rank);
txtyr_join=new JTextField(10);
txtyr_join.setBounds(374,440,280,30);
f.add(txtyr_join);
txtwarden_retire=new JTextField(10);
txtwarden_retire.setBounds(374,495,280,30);
f.add(txtwarden_retire);
btnadd=new JButton("ADD");
btnadd.setBounds(105,560,120,35);
btnadd.addActionListener(this);
f.add(btnadd);
btncncl=new JButton("CANCEL");
btncncl.setBounds(280,560,120,35);
btncncl.addActionListener(this);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 48 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(btncncl);
btnclr=new JButton("CLEAR");
btnclr.setBounds(435,560,120,35);
btnclr.addActionListener(this);
f.add(btnclr);
/** Making the frame maximized*/
f.setSize(1200,900);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(null);
/**Making the Frame visible*/
f.setVisible(true);
}
/** Main Method*/
public static void main(String args[])
{
Wardens_add f=new Wardens_add();
f.information();}
/** Providing the implementation of the method of the Interface*/
public void actionPerformed(ActionEvent e)
{
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 49 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
JButton b=(JButton)e.getSource();
String str=b.getLabel();
id=txtid.getText();
name=txtname.getText();
address=txtaddress.getText();
warden_rank=txtwarden_rank.getText();
warden_year=txtyr_join.getText();
warden_retire=txtwarden_retire.getText();
if(e.getSource()==btnadd){
add();
}
else if(str.equals("CLEAR")){
txtid.setText("");
txtname.setText("");
txtaddress.setText("");
txtwarden_rank.setText("");
txtyr_join.setText("");
txtwarden_retire.setText("");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 50 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
}
else if(str.equals("ADD")){
String txtid1=txtid.getText();
String txtname1=txtname.getText();
String txtname2=txtaddress.getText();
String txtname3=txtwarden_rank.getText();
String txtname4=txtyr_join.getText();
String txtname5=txtwarden_retire.getText();
}
else if(str.equals("CANCEL"))
{
f.dispose();
}
}
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 51 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
void add(){
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
//Connection connect = DriverManager.getConnection("jdbc:odbc:Wardens");
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "INSERT INTO Warden_details (id
,name,address,warden_rank,warden_year,warden_retire) values ('" + id + "','" + name + "','" +
address+ "','" + warden_rank+ "','"+ warden_year+"','"+ warden_retire+"')";
state.execute(sql);
JOptionPane.showMessageDialog(null, "Record added Successfully");
System.out.println("Statement executed successfully");
state.close();
connect.close();
}
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 52 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
catch (Exception e) {
System.out.print(e);
}
}
}
vi) Warden page (For updating details of a Warden):
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/** Creating a class Wardens_add and implementing the interface ActionListener*/
class Warden_details implements ActionListener
{
/** Declaring the variables*/
/** Declaring the JFrame variable f*/
JFrame f;
JButton btnfind,btndel,btnupdate,btnclr,btncncl;
JLabel lbl_id,lblname,lbladdress,lblwarden_rank,lblyr_warden,lblretire,r;
JTextField txtid,txtname,txtaddress,txtwarden_rank,txtwarden_year,txtwarden_retire;
private String id,name,address,warden_rank,warden_year,warden_retire;
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 53 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
/** Constructor Creation */
public void init()
{
f=new JFrame();
r=new JLabel("UPDATE WARDEN DETAILS");
r.setBounds(310,85,1080,65);
f.add(r);
Font t=new Font("Showcard Gothic",Font.BOLD,65);
r.setFont(t);
/**Object Creation*/
lblretire=new JLabel("Warden retirement");
lblretire.setBounds(100,500,500,20);
f.add(lblretire);
Font b=new Font("Dialog",Font.BOLD,25);
lblretire.setFont(b);
lbl_id=new JLabel("Id.");
lbl_id.setBounds(100,170,200,20);
f.add(lbl_id);
Font k=new Font("Dialog",Font.BOLD,25);
lbl_id.setFont(k);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 54 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
lblname=new JLabel("NAME");
lblname.setBounds(100,230,225,50);
f.add(lblname);
Font p=new Font("Dialog",Font.BOLD,25);
lblname.setFont(p);
lbladdress=new JLabel("Address");
lbladdress.setBounds(100,300,225,50);
f.add(lbladdress);
Font a=new Font("Dialog",Font.BOLD,25);
lbladdress.setFont(a);
lblwarden_rank=new JLabel("Warden Rank");
lblwarden_rank.setBounds(100,370,225,50);
f.add(lblwarden_rank);
Font q=new Font("Dialog",Font.BOLD,25);
lblwarden_rank.setFont(q);
lblyr_warden=new JLabel("Warden year of joining");
lblyr_warden.setBounds(100,430,275,50);
f.add(lblyr_warden);
Font x=new Font("Dialog",Font.BOLD,25);
lblyr_warden.setFont(x);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 55 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
txtid=new JTextField(10);
txtid.setBounds(280,170,190,30);
f.add(txtid);
txtname=new JTextField(10);
txtname.setBounds(280,239,190,30);
f.add(txtname);
txtaddress=new JTextField(10);
txtaddress.setBounds(280,310,190,30);
f.add(txtaddress);
txtwarden_rank=new JTextField(10);
txtwarden_rank.setBounds(280,380,190,30);
f.add(txtwarden_rank);
txtwarden_year=new JTextField(10);
txtwarden_year.setBounds(374,440,280,30);
f.add(txtwarden_year);
txtwarden_retire=new JTextField(10);
txtwarden_retire.setBounds(374,495,280,30);
f.add(txtwarden_retire);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 56 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
btnfind=new JButton("FIND");
btnfind.setBounds(95,550,120,35);
btnfind.addActionListener(this);
f.add(btnfind);
btndel=new JButton("DELETE");
btndel.setBounds(295,550,120,35);
btndel.addActionListener(this);
f.add(btndel);
btnupdate=new JButton("UPDATE");
btnupdate.setBounds(495,550,120,35);
btnupdate.addActionListener(this);
f.add(btnupdate);
btncncl=new JButton("CANCEL");
btncncl.setBounds(880,550,120,35);
btncncl.addActionListener(this);
f.add(btncncl);
btnclr=new JButton("CLEAR");
btnclr.setBounds(695,550,120,35);
btnclr.addActionListener(this);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 57 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
f.add(btnclr);
btndel.setEnabled(false);
btnupdate.setEnabled(false);
btncncl.setEnabled(false);
/** Making the frame maximized*/
f.setSize(1200,900);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(null);
f.setVisible(true);
}
/** Main Method*/
public static void main(String args[])
{
Warden_details f=new Warden_details();
f.init();
}
/** Providing the implementation of the method of the Interface*/
public void actionPerformed(ActionEvent e)
{
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 58 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
id=txtid.getText();
name=txtname.getText();
address=txtaddress.getText();
warden_rank=txtwarden_rank.getText();
warden_year=txtwarden_year.getText();
warden_retire=txtwarden_retire.getText();
int i=0;
try{
/** Written in try block, in order to catch the Exception*/
i=Integer.parseInt(id);
}
catch(Exception ex){}
JButton b=(JButton)e.getSource();
String str=b.getLabel();
if(str.equals("FIND")){
if(txtid.getText().trim().length()!=0) //Validation in
order to show provided message
Find(i);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 59 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
else
JOptionPane.showMessageDialog(null, "Text field is empty");
}
else if(str.equals("CANCEL"))
{
f.dispose();
}
else if(str.equals("CLEAR")){
txtid.setText("");
txtname.setText("");
txtaddress.setText("");
txtwarden_rank.setText("");
txtwarden_year.setText("");
txtwarden_retire.setText("");
}else if(str.equals("UPDATE")){
if(txtid.getText().trim().length()!=0)
//Validation in order to show provided message
Update();
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 60 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
else
JOptionPane.showMessageDialog(null, "Text field is empty");
}else if(str.equals("DELETE")){
i=Integer.parseInt(id);
delete(i);
}
if
((id.equals(""))||(name.equals(""))||(address.equals(""))||(warden_rank.equals(""))||(warden_year.e
quals(""))||(warden_retire.equals("")))
{
}
}
boolean Find(int id){
boolean flag=false;
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 61 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
String sql = "select * from Warden_details where id="+ id +"";
ResultSet rs=state.executeQuery(sql);
if(rs.next())
{
txtid.setText(rs.getString("id"));
txtname.setText(rs.getString("name"));
txtaddress.setText(rs.getString("address"));
txtwarden_rank.setText(rs.getString("warden_rank"));
txtwarden_year.setText(rs.getString("warden_year"));
txtwarden_retire.setText(rs.getString("warden_retire"));
flag=true;
btndel.setEnabled(true);
btnupdate.setEnabled(true);
btncncl.setEnabled(true);
}
JOptionPane.showMessageDialog(null, "Record Found Successfully");
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 62 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
System.out.println("Statement executed successfully");
rs.close();
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
return flag;
}
void delete(int id){
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 63 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
String sql = "DELETE FROM Warden_details WHERE id="+ id +"";
state.execute(sql);
JOptionPane.showMessageDialog(null, "Record deleted Successfully");
System.out.println("Statement executed successfully");
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
}
void Update(){
try{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Divers loaded successfully");
String source =
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 64 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Connection connect = DriverManager.getConnection(source);
System.out.println("Connection established successfully");
Statement state = connect.createStatement();
int i=Integer.parseInt(id);
String sql = "UPDATE Warden_details set id= "+id+", name= '"+name+"',
address='"+address+"',warden_rank='"+warden_rank+"',warden_year='"+warden_year+"',warden
_retire='"+warden_retire+"' WHERE id= "+id+"";
state.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Record Updated Successfully");
System.out.println("Statement executed successfully");
state.close();
connect.close();
}
catch (Exception e) {
System.out.print(e);
}
}}
vii)Report page (For report details of a Prisoner):
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 65 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
import java.awt.event.*;
import java.sql.*;
import javax.swing.JFrame;
/** Creating a class Wardens_add and implementing the interface ActionListener*/
class Report1 extends JFrame implements WindowListener
{
private boolean flag=true;
List lstrpt;
public Report1(){
setTitle("Report");
setSize(430,350);
setLayout(null);
/** Making the frame visible*/
setVisible(true);
lstrpt=new List();
add(lstrpt);
lstrpt.setBounds(10,40,1200,400);
addWindowListener(this);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 66 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
try
{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:PMS","","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from prisoner_details");
String st="";
while(rs.next()){
st =rs.getString("id")+" "+rs.getString("name")+"
"+rs.getString("address")+" "+rs.getString("date_of_crime")+"
"+rs.getString("crime_description")+"
"+rs.getString("date_of_prisonment")+" "+rs.getString("date_of_release")+"
"+rs.getString("status");
lstrpt.add(st);
}
}
catch(Exception e){
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 67 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
}
}
//Implementing windows Listener
public void itemStateChanged(ItemEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosing(WindowEvent e){dispose();}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public static void main(String args[]){
Report1 r=new Report1();
}
}
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 68 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
viii) Report page (For report details of a warden):
/** Importing in order to use the predefined methods and classes*/
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JFrame;
/** Creating a class Wardens_add and implementing the interface ActionListener*/
class Report2 extends JFrame implements WindowListener
{
private boolean flag=true;
List lstrpt;
public Report2(){
setTitle("Report");
setSize(430,350);
setLayout(null);
/** Making the frame visible*/
setVisible(true);
lstrpt=new List();
add(lstrpt);
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 69 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
lstrpt.setBounds(10,40,1200,400);
addWindowListener(this);
try
{
/** Written in try block, in order to catch the Exception*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:PMS","","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from Warden_details");
String st="";
while(rs.next()){
st =rs.getString("id")+" "+rs.getString("name")+"
"+rs.getString("address")+"
"+rs.getString("warden_rank")+"
"+rs.getString("warden_year")+" "+rs.getString("warden_retire");
lstrpt.add(st);
}
}
catch(Exception e){
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 70 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
}
}
//Implementing windows Listener
public void itemStateChanged(ItemEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosing(WindowEvent e){dispose();}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public static void main(String args[]){
Report2 r=new Report2();
}
}
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 71 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
SAMPLE OUTPUTS AND EXPLANATIONS
i) Login Screen :
In this ,text Field are used for taking the Username and Password Field used for taking the
password from the user. A Button that submits the user’s entered value and satisfies the
Username and Password of the user and a cancel is used to cancel the details.
ii) Home Screen : After logging in Prison management system screen will appear which is
provided with the following main menu. The administrator had given the privilege to
prisoner, warden, reports and logout. And after clicking on these menu you can go further
sub-menus.
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 72 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
iii) Prisoner Add Screen : This screen very well depicts the entire details of a prisoner all
necessary details will be filled in it and after clicking on the add button you will be shown
with a dialog box indicating that the prisoner details have been added successfully.
iv) Prisoner Update Screen : This screen very well depicts the details which you wish to
find, release, delete, update in a prisoner details and after you add the prisoner id there
you will get all the others details after clicking on the find button you will be shown with
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 73 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
a dialog box indicating that the prisoner details have been found successfully. In it all the
other buttons will be disabled if you don’t find any prisoner.
v) Warden Add Screen : This screen very well depicts the entire details of a warden all
necessary details will be filled in it and after clicking on the add button you will be shown
with a dialog box indicating that the records have been added successfully.
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 74 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
vi) Warden Update Screen : This screen very well depicts the details which you wish to
find, delete, update in a warden details and after you add the warden id there you will get
all the others details after clicking on the find button you will be shown with a dialog box
indicating that the warden details have been found successfully. In it all the other buttons
will be disabled if you don’t find any warden.
vii) Prisoner report Screen : This screen very well depicts the entire report of a prisoner all
necessary details that you have added in the database.
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 75 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
viii) Warden report Screen : This screen very well depicts the entire report of a warden
all necessary details that you have added in the database.
ADDITIONAL FEATURES
i) Use of Exception Handling apart from database.
CE00396-1-Object Oriented & Event Driven Programming Assignment Page 76 of
76
__________________________________________________________________________________
Level 1 Asia Pacific Institute of Information Technology 2015
Apart from database connectivity, Exception handling concept is used in the application
to handle the exceptions more efficiently.
ii) Validation is provided to almost every field.
The validation is provided to almost every aspects of the application to make the data
storage more persistent and the application user-friendly.
iii) Predefined interfaces are implemented.
Predefined interfaces are implemented in the application.
iv) A Log out menu item is provided for logging out of the application.
A logout menu is provided in the main menu of the application, for logging out of the
application.
ASSUMPTIONS
i) Basic User Requirements
It has been assumed that the user of the application should have basic computer
knowledge and all other programming skills, in order to use the application more
effectively.
REFERENCES
i) Schildt, H (2007). Java: The Complete Reference. 7 West Patel Nagar, New Delhi: Tata
McGraw-Hill Publishing Company Limited. p205-217.
ii) http://www.java2s.com/Tutorial/Java/0240__Swing/SetFontandforegroundcol
orforaJLabel.htm. Last accessed 20th April.

More Related Content

Similar to Java

IRJET - Airplane Crash Analysis and Prediction using Machine Learning
IRJET - Airplane Crash Analysis and Prediction using Machine LearningIRJET - Airplane Crash Analysis and Prediction using Machine Learning
IRJET - Airplane Crash Analysis and Prediction using Machine LearningIRJET Journal
 
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...IRJET Journal
 
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...IRJET Journal
 
Kaggle talk series top 0.2% kaggler on amazon employee access challenge
Kaggle talk series  top 0.2% kaggler on amazon employee access challengeKaggle talk series  top 0.2% kaggler on amazon employee access challenge
Kaggle talk series top 0.2% kaggler on amazon employee access challengeVivian S. Zhang
 
IRJET - Automated Fraud Detection Framework in Examination Halls
 IRJET - Automated Fraud Detection Framework in Examination Halls IRJET - Automated Fraud Detection Framework in Examination Halls
IRJET - Automated Fraud Detection Framework in Examination HallsIRJET Journal
 
Machine Learning Model for M.S admissions
Machine Learning Model for M.S admissionsMachine Learning Model for M.S admissions
Machine Learning Model for M.S admissionsOmkar Rane
 
Cortana Analytics Workshop: Predictive Maintenance in the IoT Era
Cortana Analytics Workshop: Predictive Maintenance in the IoT EraCortana Analytics Workshop: Predictive Maintenance in the IoT Era
Cortana Analytics Workshop: Predictive Maintenance in the IoT EraMSAdvAnalytics
 
Capp system process sequence optimization based on genetic algorithms
Capp system process sequence optimization based on genetic algorithmsCapp system process sequence optimization based on genetic algorithms
Capp system process sequence optimization based on genetic algorithmseSAT Journals
 
IRJET- Matrix Multiplication using Strassen’s Method
IRJET-  	  Matrix Multiplication using Strassen’s MethodIRJET-  	  Matrix Multiplication using Strassen’s Method
IRJET- Matrix Multiplication using Strassen’s MethodIRJET Journal
 
More than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12cMore than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12cGuatemala User Group
 
Privacy Preservation using Partition Technique
Privacy Preservation using Partition TechniquePrivacy Preservation using Partition Technique
Privacy Preservation using Partition TechniqueIRJET Journal
 
IRJET - Smart Vet Locator for Hybrid Pets
IRJET -  	  Smart Vet Locator for Hybrid PetsIRJET -  	  Smart Vet Locator for Hybrid Pets
IRJET - Smart Vet Locator for Hybrid PetsIRJET Journal
 
IRJET- Titanic Survival Analysis using Logistic Regression
IRJET-  	  Titanic Survival Analysis using Logistic RegressionIRJET-  	  Titanic Survival Analysis using Logistic Regression
IRJET- Titanic Survival Analysis using Logistic RegressionIRJET Journal
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mayank Prasad
 
IRJET- Next Generation System Assistant
IRJET- Next Generation System AssistantIRJET- Next Generation System Assistant
IRJET- Next Generation System AssistantIRJET Journal
 
522490079-Dream-Report-User-Manual.pdf
522490079-Dream-Report-User-Manual.pdf522490079-Dream-Report-User-Manual.pdf
522490079-Dream-Report-User-Manual.pdfMuhamad Badar
 
UML Foundation for C Self Trimming
UML Foundation for C Self TrimmingUML Foundation for C Self Trimming
UML Foundation for C Self TrimmingPathfinder Solutions
 

Similar to Java (20)

IRJET - Airplane Crash Analysis and Prediction using Machine Learning
IRJET - Airplane Crash Analysis and Prediction using Machine LearningIRJET - Airplane Crash Analysis and Prediction using Machine Learning
IRJET - Airplane Crash Analysis and Prediction using Machine Learning
 
Eds
EdsEds
Eds
 
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...
IRJET-A Study of Programmable Logic Controllers (PLC) and Graphical User Inte...
 
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...
IRJET- A Study of Programmable Logic Controllers (PLC) and Graphical User Int...
 
Kaggle talk series top 0.2% kaggler on amazon employee access challenge
Kaggle talk series  top 0.2% kaggler on amazon employee access challengeKaggle talk series  top 0.2% kaggler on amazon employee access challenge
Kaggle talk series top 0.2% kaggler on amazon employee access challenge
 
IRJET - Automated Fraud Detection Framework in Examination Halls
 IRJET - Automated Fraud Detection Framework in Examination Halls IRJET - Automated Fraud Detection Framework in Examination Halls
IRJET - Automated Fraud Detection Framework in Examination Halls
 
Machine Learning Model for M.S admissions
Machine Learning Model for M.S admissionsMachine Learning Model for M.S admissions
Machine Learning Model for M.S admissions
 
Cortana Analytics Workshop: Predictive Maintenance in the IoT Era
Cortana Analytics Workshop: Predictive Maintenance in the IoT EraCortana Analytics Workshop: Predictive Maintenance in the IoT Era
Cortana Analytics Workshop: Predictive Maintenance in the IoT Era
 
Capp system process sequence optimization based on genetic algorithms
Capp system process sequence optimization based on genetic algorithmsCapp system process sequence optimization based on genetic algorithms
Capp system process sequence optimization based on genetic algorithms
 
IRJET- Matrix Multiplication using Strassen’s Method
IRJET-  	  Matrix Multiplication using Strassen’s MethodIRJET-  	  Matrix Multiplication using Strassen’s Method
IRJET- Matrix Multiplication using Strassen’s Method
 
More than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12cMore than 12 More things about Oracle Database 12c
More than 12 More things about Oracle Database 12c
 
Privacy Preservation using Partition Technique
Privacy Preservation using Partition TechniquePrivacy Preservation using Partition Technique
Privacy Preservation using Partition Technique
 
IRJET - Smart Vet Locator for Hybrid Pets
IRJET -  	  Smart Vet Locator for Hybrid PetsIRJET -  	  Smart Vet Locator for Hybrid Pets
IRJET - Smart Vet Locator for Hybrid Pets
 
IRJET- Titanic Survival Analysis using Logistic Regression
IRJET-  	  Titanic Survival Analysis using Logistic RegressionIRJET-  	  Titanic Survival Analysis using Logistic Regression
IRJET- Titanic Survival Analysis using Logistic Regression
 
Speed bumps ahead
Speed bumps aheadSpeed bumps ahead
Speed bumps ahead
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
 
IRJET- Next Generation System Assistant
IRJET- Next Generation System AssistantIRJET- Next Generation System Assistant
IRJET- Next Generation System Assistant
 
AJP
AJPAJP
AJP
 
522490079-Dream-Report-User-Manual.pdf
522490079-Dream-Report-User-Manual.pdf522490079-Dream-Report-User-Manual.pdf
522490079-Dream-Report-User-Manual.pdf
 
UML Foundation for C Self Trimming
UML Foundation for C Self TrimmingUML Foundation for C Self Trimming
UML Foundation for C Self Trimming
 

Recently uploaded

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Recently uploaded (20)

DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Java

  • 1. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 1 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 TABLE OF CONTENTS INTRODUCTION............................................................................................................................................ 2 UML DIAGRAM ............................................................................................................................................ 2 (CLASS DIAGRAM)........................................................................................................................................ 3 USE CASE DIAGRAMS:-................................................................................................................................. 8 ACTIVITY DIAGRAM...................................................................................................................................... 9 SEQUENCE DIAGRAM................................................................................................................................. 10 SOURCE CODES OF PROGRAMS:-................................................................................................................ 11 SAMPLE OUTPUTS AND EXPLANATIONS ..................................................................................................... 71 ADDITIONAL FEATURES.............................................................................................................................. 75 ASSUMPTIONS........................................................................................................................................... 76 REFERENCES............................................................................................................................................... 76
  • 2. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 2 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 INTRODUCTION Java is a general purpose, object-oriented programming is. Java, TV sets, consumer electronics, within the framework of a research, VCRs, toasters machines you can buy in a store is designed to develop other types of software. Java (Java 1.0), the first public release of a version of the Java language and the release to establish libraries, meanwhile, was published in 1995.Coming to the assignment, we are required to develop an application i.e. prisoner management system which would be helpful for warden and police to use application and can find details of the prisoner using Java as a programming language. In this project we had created different forms to update and retrieve the data from the database. In this project we had created a main menu form where, the entire management system is controlled by the administrator. In this menu form we had provided links to other forms to add, search, update, delete, and view all details of the prisoner, wardens. (Tata McGraw-Hill, 2007) UML DIAGRAM
  • 3. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 3 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 (Class Diagram) Login page Home page of prison management system:- Prisoner add page:- MyFrame1 ~f: JFrame ~ok: JButton ~cancel: JButton ~lblLogin: JLabel ~lblpassword: JLabel ~r: JLabel ~txtusername: JTextField ~txtpassword: JTextField <<create>>~MyFrame1() +init() +main(args: String) +actionPerformed(e: ActionEvent) MyFrame2 ~menuadd_prisoner: JMenuItem ~menuupdate_prisoner: JMenuItem ~menuadd_warden: JMenuItem ~menuupdate_warden: JMenuItem ~menudisplaypriso: JMenuItem ~menudisplaywarden: JMenuItem ~menulogout: JMenuItem +pnladd: JPanel +pnlupdate: JPanel +prisoner: JLabel ~f: JFrame +menu() +main(args: String) +actionPerformed(e: ActionEvent)
  • 4. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 4 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Prisoner update page:- Prisoner ~f: JFrame ~btnadd: JButton ~btncncl: JButton ~btnclr: JButton ~lblid: JLabel ~lblname: JLabel ~lbladdress: JLabel ~lbldoc: JLabel ~lblcrime_desc: JLabel ~lbldate_prison: JLabel ~lbldate_rel: JLabel ~r: JLabel ~txtid: JTextField ~txtname: JTextField ~txtaddress: JTextField ~txtdoc: JTextField ~txtcrime_desc: JTextField ~txtdate_prison: JTextField ~txtdate_rel: JTextField -id: String -name: String -address: String -date_of_crime: String -crime_description: String -date_of_prisonment: String -date_of_release: String +details() +main(args: String) +actionPerformed(e: ActionEvent) ~add()
  • 5. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 5 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Prisoner1 ~f: JFrame ~btnfind: JButton ~btnrel: JButton ~btndel: JButton ~btnupdate: JButton ~btnclr: JButton ~lblid: JLabel ~lblname: JLabel ~lblcrime_desc: JLabel ~r: JLabel ~txtid: JTextField ~txtname: JTextField ~txtcrime_desc: JTextField -id: String -name: String -address: String -date_of_crime: String -crime_description: String -date_of_prisonment: String -date_of_release: String -status: String +init() +main(args: String) +actionPerformed(e: ActionEvent) ~Find(id: int): boolean ~delete(id: int) ~Update()
  • 6. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 6 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Warden page of add and update:- Wardens_add ~f: JFrame ~btnadd: JButton ~btncncl: JButton ~btnclr: JButton ~lblid: JLabel ~lblname: JLabel ~lbladdress: JLabel ~lblwarden_rank: JLabel ~lblyr_join: JLabel ~lblretire: JLabel ~r: JLabel ~txtid: JTextField ~txtname: JTextField ~txtaddress: JTextField ~txtwarden_rank: JTextField ~txtyr_join: JTextField ~txtwarden_retire: JTextField -id: String -name: String -address: String -warden_rank: String -warden_year: String -warden_retire: String +information() +main(args: String) +actionPerformed(e: ActionEvent) ~add() Warden_details ~f: JFrame ~btnfind: JButton ~btndel: JButton ~btnupdate: JButton ~btnclr: JButton ~btncncl: JButton ~lbl_id: JLabel ~lblname: JLabel ~lbladdress: JLabel ~lblwarden_rank: JLabel ~lblyr_warden: JLabel ~lblretire: JLabel ~r: JLabel ~txtid: JTextField ~txtname: JTextField ~txtaddress: JTextField ~txtwarden_rank: JTextField ~txtwarden_year: JTextField ~txtwarden_retire: JTextField -id: String -name: String -address: String -warden_rank: String -warden_year: String -warden_retire: String +init() +main(args: String) +actionPerformed(e: ActionEvent) ~Find(id: int): boolean ~delete(id: int) ~Update()
  • 7. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 7 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Reports of prisoner and warden page:- Report2 -flag: boolean = true ~lstrpt: List <<create>>+Report2() +itemStateChanged(e: ItemEvent) +windowOpened(e: WindowEvent) +windowClosing(e: WindowEvent) +windowClosed(e: WindowEvent) +windowIconified(e: WindowEvent) +windowDeiconified(e: WindowEvent) +windowActivated(e: WindowEvent) +windowDeactivated(e: WindowEvent) +main(args: String) Report1 -flag: boolean = true ~lstrpt: List <<create>>+Report1() +itemStateChanged(e: ItemEvent) +windowOpened(e: WindowEvent) +windowClosing(e: WindowEvent) +windowClosed(e: WindowEvent) +windowIconified(e: WindowEvent) +windowDeiconified(e: WindowEvent) +windowActivated(e: WindowEvent) +windowDeactivated(e: WindowEvent) +main(args: String)
  • 8. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 8 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Use Case Diagrams:- PMS Login Admin PMS Prisoner Warden Reports Add Update Prisoner details Add Update Warden details Display all prisoners Display all wardens Logout <<includes>> <<includes>> <<includes>> <<includes>> <<includes>> <<includes>> <<includes>> <<includes>> «extends» «extends» <<includes>> Find «extends» Release«extends» Delete «extends» Update <<includes>> Find <<includes>> Cancel Clear «extends» Delete «extends» Update <<includes>> «extends»
  • 9. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 9 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Activity diagram Login Prisoner [Username Or Password ] PMS Warden Reports Add Prisoner Update Prisoner ADD CANCEL CLEAR Find Update Release Delete Add Warden Update Warden ADD CLEAR CANCEL Find Update CLEAR Delete Display All Prisoners Display All Wardens CLEAR CANCEL Logout
  • 10. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 10 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Sequence diagram PMS Login Add Find Update Delete Release Database Username Add prisoner Find Prisoner Prisoner Details Prisoner Details Update Prisoner All Fill Up Details Update Delete Prisoner All Details Delete Release Prisoner ADD PRISONER FIND PRISONER UPDATE PRISONER DELETE PRISONER Password Add Prisoner Details on Database Add prisoner details Search detailsFill the Prisoner data All Changed details Updates prisoner details Deletes the informationDelete entire Details of Prisoner status changed RELEASE PRISONER Add Warden Add Warden Details Add The all Warden Details Provides all details ADD WARDEN Find Warden Find Warden Details Finds The Warden Details Find the warden details from database Update Warden Updates The Warden Details Updates The Warden Details Updates all the details on Data Base FIND WARDEN UPDATE WARDEN Prisoner Releases All Status Changes Delete Warden Delete entire details Of Warden Delete Warden Details Delete all The Warden Details On Data Base DELETE WARDEN
  • 11. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 11 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 SOURCE CODES OF PROGRAMS:- i) Login Page: /** Importing in order to use the predefined methods and classes*/ import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Creating a class MyFrame1 and implementing the interface ActionListener */ class MyFrame1 implements ActionListener { /** Declaring the variables*/ /** Declaring the JFrame variable f*/ JFrame f; JButton ok,cancel; JLabel lblLogin,lblpassword,r; JTextField txtusername,txtpassword; /** Constructor Creation */ MyFrame1() /** Creates new form MyFrame1 */ { f=new JFrame();
  • 12. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 12 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 r=new JLabel("LOGIN DETAILS"); r.setForeground(Color.YELLOW); r.setBounds(510,85,480,55); f.add(r); /** Making the frame maximized*/ f.setSize(1580,1250); Font t=new Font("Dialog",Font.BOLD,55); r.setFont(t); /**Object Creation*/ lblLogin=new JLabel("USERNAME"); lblLogin.setForeground(Color.GREEN); lblLogin.setBounds(100,270,200,20); f.add(lblLogin); Font k=new Font("Dialog",Font.BOLD,25); lblLogin.setFont(k); lblpassword=new JLabel("PASSWORD"); lblpassword.setForeground(Color.GREEN); lblpassword.setBounds(100,330,225,50); f.add(lblpassword); Font p=new Font("Dialog",Font.BOLD,25); lblpassword.setFont(p);
  • 13. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 13 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtusername=new JTextField(10); txtusername.setBounds(280,265,180,30); f.add(txtusername); txtpassword=new JPasswordField(10); txtpassword.setBounds(280,340,180,30); f.add(txtpassword); ok=new JButton("OK"); cancel=new JButton("CANCEL"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } /** Defining the method init*/ public void init() { ok.setBounds(105,440,160,25); ok.addActionListener(this); f.add(ok); cancel.setBounds(300,440,160,25); cancel.addActionListener(this); f.add(cancel); JLabel image_back=new JLabel(""); image_back.setIcon(new ImageIcon("login.jpg"));
  • 14. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 14 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(image_back); image_back.setBounds (1,0,1700,700); f.setLayout(null); /**Making the Frame visible*/ f.setVisible(true); } /** Main Method*/ public static void main(String args[]) { MyFrame1 f=new MyFrame1(); f.init(); } /** Providing the implementation of the method of the Interface*/ public void actionPerformed(ActionEvent e) { JButton bt=(JButton)e.getSource(); String str=bt.getLabel(); if(str.equals("CANCEL")) System.exit(0); else if(str.equals("OK")){
  • 15. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 15 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 String txtid1=txtusername.getText(); String txtname1=txtpassword.getText(); if (( txtid1.equals(""))||(txtname1.equals("")) ) { JOptionPane.showMessageDialog(null,"Text field is empty "); //Validation to check empty or not } else if (e.getSource()==ok) { MyFrame2 f=new MyFrame2(); f.menu(); } } } } ii) Home Page (PMS):- /** Importing in order to use the predefined methods and classes*/ import java.awt.*; import java.awt.event.*;
  • 16. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 16 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 import javax.swing.*; /** Creating a class MyFrame2 and implementing the interface ActionListener*/ class MyFrame2 extends JFrame implements ActionListener { /** Declaring the variables*/ JMenuItem menuadd_prisoner, menuupdate_prisoner,menuadd_warden, menuupdate_warden,menudisplaypriso,menudisplaywarden,menulogout; public JPanel pnladd, pnlupdate; public JLabel prisoner; /** Declaring the JFrame variable f*/ JFrame f; /** Constructor Creation */ public void menu() { f=new JFrame(); f.setTitle("PRISON MANAGEMENT SYSTEM"); prisoner=new JLabel("PRISONER MANAGEMENT SYSTEM"); prisoner.setForeground(Color.GREEN); prisoner.setBounds(11,85,1550,60);
  • 17. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 17 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(prisoner); Font t=new Font("Dialog",Font.BOLD,80); prisoner.setFont(t); f.setSize(1580,1250); f.setLocation(100,100); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menubar=new JMenuBar(); f.setJMenuBar(menubar); JMenu filemenu =new JMenu("Prisoner"); menubar.add(filemenu); menuadd_prisoner = new JMenuItem("Add"); menuupdate_prisoner= new JMenuItem("Update"); menuadd_prisoner.add(new JSeparator()); menuupdate_prisoner.add(new JSeparator()); JMenu filemenu1 =new JMenu("Warden"); menubar.add(filemenu1); menuadd_warden = new JMenuItem("Add"); menuupdate_warden= new JMenuItem("Update"); menuadd_warden.add(new JSeparator());
  • 18. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 18 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 menuupdate_warden.add(new JSeparator()); filemenu.add(menuadd_prisoner); menuadd_prisoner.addActionListener(this); filemenu.add(menuupdate_prisoner); menuupdate_prisoner.addActionListener(this); filemenu1.add(menuadd_warden); menuadd_warden.addActionListener(this); filemenu1.add(menuupdate_warden); menuupdate_warden.addActionListener(this); JMenu filemenu2 =new JMenu("Reports"); menubar.add(filemenu2); menudisplaypriso=new JMenuItem("Display the prisoner"); menudisplaywarden=new JMenuItem("Display the warden"); menudisplaypriso.add(new JSeparator()); menudisplaywarden.add(new JSeparator()); filemenu2.add(menudisplaypriso); menudisplaypriso.addActionListener(this); filemenu2.add(menudisplaywarden);
  • 19. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 19 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 menudisplaywarden.addActionListener(this); JMenu filemenu3 =new JMenu("Logout"); menubar.add(filemenu3); menulogout=new JMenuItem("Logout completely"); filemenu3.add(menulogout); menulogout.addActionListener(this); /**Adding backgroung image*/ JLabel image_back=new JLabel(""); image_back.setIcon(new ImageIcon("prison.jpg")); f.add(image_back); image_back.setBounds (40,0,1700,700); f.setLayout(null); /**Making the Frame visible*/ f.setVisible(true); } /** Main Method*/
  • 20. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 20 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 public static void main(String args[]) { MyFrame2 f=new MyFrame2(); f.menu(); } public void actionPerformed(ActionEvent e) { /** Methods are called on the basis of the click of the menuitem*/ if (e.getSource()==menuadd_prisoner) { Prisoner f1=new Prisoner(); f1.details(); } else if (e.getSource()==menuupdate_prisoner) { Prisoner1 f=new Prisoner1(); f.init(); } else if (e.getSource()==menuadd_warden) {
  • 21. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 21 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Wardens_add f=new Wardens_add(); f.information(); } else if (e.getSource()==menuupdate_warden) { Warden_details f=new Warden_details(); f.init(); } else if (e.getSource()==menudisplaypriso) { Report1 r=new Report1(); } else if (e.getSource()==menudisplaywarden) { Report2 r=new Report2(); } else if (e.getSource()==menulogout) {
  • 22. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 22 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 MyFrame1 f1=new MyFrame1(); f1.init(); f.setVisible(false); } } } iii) Prisoner page (For adding a Prisoner): /** Importing in order to use the predefined methods and classes*/ import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.sql.*; /** Creating a class Prisoner and implementing the interface ActionListener*/ public class Prisoner implements ActionListener { /** Declaring the variables*/ /** Declaring the JFrame variable f*/ JFrame f; JButton btnadd,btncncl,btnclr;
  • 23. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 23 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 JLabel lblid,lblname,lbladdress,lbldoc,lblcrime_desc,lbldate_prison,lbldate_rel,r; JTextField txtid,txtname,txtaddress,txtdoc,txtcrime_desc,txtdate_prison,txtdate_rel; private String id,name,address,date_of_crime, crime_description, date_of_prisonment, date_of_release; /** Constructor Creation */ public void details() { f=new JFrame(); r=new JLabel("PRISONER DETAILS"); r.setBounds(390,75,800,65); f.add(r); Font t=new Font("Showcard Gothic",Font.BOLD,65); r.setFont(t); /**Object Creation*/ lblid=new JLabel(" Prisoner Id."); lblid.setBounds(100,170,200,20); f.add(lblid);
  • 24. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 24 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Font k=new Font("Dialog",Font.BOLD,25); lblid.setFont(k); lblname=new JLabel("NAME"); lblname.setBounds(100,230,225,50); f.add(lblname); Font p=new Font("Dialog",Font.BOLD,25); lblname.setFont(p); lbladdress=new JLabel("Address"); lbladdress.setBounds(100,300,225,50); f.add(lbladdress); Font a=new Font("Dialog",Font.BOLD,25); lbladdress.setFont(a); lbldoc=new JLabel("Date of crime"); lbldoc.setBounds(100,370,225,50); f.add(lbldoc); Font q=new Font("Dialog",Font.BOLD,25); lbldoc.setFont(q); lblcrime_desc=new JLabel("Crime Description"); lblcrime_desc.setBounds(100,440,225,50); f.add(lblcrime_desc); Font x=new Font("Dialog",Font.BOLD,25);
  • 25. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 25 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 lblcrime_desc.setFont(x); lbldate_prison=new JLabel("Date of prisonment"); lbldate_prison.setBounds(100,540,225,50); f.add(lbldate_prison); Font w=new Font("Dialog",Font.BOLD,25); lbldate_prison.setFont(w); lbldate_rel=new JLabel("Date of Release"); lbldate_rel.setBounds(100,580,225,50); f.add(lbldate_rel); Font y=new Font("Dialog",Font.BOLD,25); lbldate_rel.setFont(y); txtid=new JTextField(10); txtid.setBounds(280,170,299,30); f.add(txtid); txtname=new JTextField(10); txtname.setBounds(280,239,299,30); f.add(txtname); txtaddress=new JTextField(10); txtaddress.setBounds(280,310,299,30); f.add(txtaddress); txtdoc=new JTextField(10);
  • 26. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 26 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtdoc.setBounds(280,380,299,30); f.add(txtdoc); txtcrime_desc=new JTextField(10); txtcrime_desc.setBounds(324,430,299,110); f.add(txtcrime_desc); txtdate_prison=new JTextField(10); txtdate_prison.setBounds(360,550,299,30); f.add(txtdate_prison); txtdate_rel=new JTextField(10); txtdate_rel.setBounds(360,594,299,30); f.add(txtdate_rel); btnadd=new JButton("ADD"); btnadd.setBounds(105,658,120,35); f.add(btnadd); btnadd.addActionListener(this); btncncl=new JButton("CANCEL"); btncncl.setBounds(280,658,120,35);
  • 27. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 27 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(btncncl); btncncl.addActionListener(this); btnclr=new JButton("CLEAR"); btnclr.setBounds(435,658,120,35); f.add(btnclr); btnclr.addActionListener(this); /** Making the frame maximized*/ f.setSize(1200,900); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLayout(null); /**Making the Frame visible*/ f.setVisible(true); } /** Main Method*/ public static void main(String args[]) { Prisoner f=new Prisoner();
  • 28. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 28 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.details(); } /** Providing the implementation of the method of the Interface*/ public void actionPerformed(ActionEvent e) { name=txtname.getText(); address=txtaddress.getText(); date_of_crime=txtdoc.getText(); id=txtid.getText(); crime_description=txtcrime_desc.getText(); date_of_prisonment=txtdate_prison.getText(); date_of_release=txtdate_rel.getText(); JButton b=(JButton)e.getSource(); String str=b.getLabel(); if(str.equals("CLEAR")){ txtid.setText(""); txtname.setText("");
  • 29. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 29 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtaddress.setText(""); txtdoc.setText(""); txtcrime_desc.setText(""); txtdate_prison.setText(""); txtdate_rel.setText(""); }else if(str.equals("CANCEL")){ f.dispose(); }else if(str.equals("ADD")){ String txtid1=txtid.getText(); String txtname2=txtname.getText(); String txtaddress3=txtaddress.getText(); String txtdoc4=txtdoc.getText(); String txtcrime_desc5=txtcrime_desc.getText(); String txtdate_prison6=txtdate_prison.getText(); String txtdate_rel7=txtdate_rel.getText(); add(); if((txtid1.equals(""))||(txtname2.equals(""))||(txtaddress3.equals(""))||(txtdoc4.equals(""))||(txtcrim e_desc5.equals(""))||(txtdate_prison6.equals(""))||(txtdate_rel7.equals(""))) JOptionPane.showMessageDialog(null, "Text field is empty");
  • 30. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 30 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 else JOptionPane.showMessageDialog(null, "Prisoner details added successfully"); }} void add(){ //Adding details to the database try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); //Connection connect = DriverManager.getConnection("jdbc:odbc:employee"); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "insert into prisoner_details (id,name,address,date_of_crime,crime_description,date_of_prisonment,date_of_release ) values ('" + id + "','" + name + "','" + address + "','" + date_of_crime + "','" + crime_description +"','" +date_of_prisonment + "','" + date_of_release +"')"; state.execute(sql); // JOptionPane.showMessageDialog(null, "Record added Successfully");
  • 31. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 31 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 System.out.println("Statement executed successfully"); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } } } iv) Prisoner page (For updating details of a Prisoner): /** Importing in order to use the predefined methods and classes*/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; /** Creating a class Prisoner and implementing the interface ActionListener*/ class Prisoner1 implements ActionListener {
  • 32. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 32 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 /** Declaring the variables*/ /** Declaring the JFrame variable f*/ JFrame f; JButton btnfind,btnrel,btndel,btnupdate,btnclr; JLabel lblid,lblname,lblcrime_desc,r; JTextField txtid,txtname,txtcrime_desc; private String id,name,address,date_of_crime,crime_description, date_of_prisonment, date_of_release,status; /** Constructor Creation */ public void init() { f=new JFrame(); r=new JLabel("UPDATE PRISONER DETAILS"); r.setBounds(210,95,1080,75); f.add(r); Font t=new Font("Showcard Gothic",Font.BOLD,65); r.setFont(t); /**Object Creation*/ lblid=new JLabel(" Prisoner Id.");
  • 33. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 33 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 lblid.setBounds(10,190,400,20); f.add(lblid); Font k=new Font("Dialog",Font.BOLD,25); lblid.setFont(k); lblname=new JLabel("NAME"); lblname.setBounds(10,225,200,50); f.add(lblname); Font p=new Font("Dialog",Font.BOLD,25); lblname.setFont(p); lblcrime_desc=new JLabel("Crime Description"); lblcrime_desc.setBounds(10,280,225,50); f.add(lblcrime_desc); Font x=new Font("Dialog",Font.BOLD,25); lblcrime_desc.setFont(x); txtid=new JTextField(10); txtid.setBounds(190,190,250,26); f.add(txtid); txtname=new JTextField(10);
  • 34. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 34 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtname.setBounds(140,239,250,26); f.add(txtname); txtcrime_desc=new JTextField(10); txtcrime_desc.setBounds(240,275,370,86); f.add(txtcrime_desc); btnfind=new JButton("FIND"); btnfind.setBounds(65,380,120,35); btnfind.addActionListener(this); f.add(btnfind); btnrel=new JButton("RELEASE"); btnrel.setBounds(205,380,120,35); btnrel.addActionListener(this); f.add(btnrel); btndel=new JButton("DELETE"); btndel.setBounds(335,380,120,35); btndel.addActionListener(this); f.add(btndel); btnupdate=new JButton("UPDATE"); btnupdate.setBounds(475,380,120,35); btnupdate.addActionListener(this);
  • 35. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 35 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(btnupdate); btnclr=new JButton("CLEAR"); btnclr.setBounds(630,380,120,35); btnclr.addActionListener(this); f.add(btnclr); btnrel.setEnabled(false); btndel.setEnabled(false); btnupdate.setEnabled(false); /** Making the frame maximized*/ f.setSize(1200,900); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(null); /**Making the Frame visible*/ f.setVisible(true); }
  • 36. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 36 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 /** Main Method*/ public static void main(String args[]) { Prisoner1 f=new Prisoner1(); f.init(); } /** Providing the implementation of the method of the Interface*/ public void actionPerformed(ActionEvent e) { id=txtid.getText(); name=txtname.getText(); crime_description=txtcrime_desc.getText(); int i=0; try{ i=Integer.parseInt(id);
  • 37. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 37 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 } catch(Exception ex){} JButton b=(JButton)e.getSource(); String str=b.getLabel(); if(str.equals("FIND")){ if(txtid.getText().trim().length()!=0) //Validation in order to show provided message Find(i); else JOptionPane.showMessageDialog(null, "Text field is empty"); } else if(str.equals("CLEAR")){ txtid.setText(""); txtname.setText(""); txtcrime_desc.setText(""); }else if(e.getSource()==btnrel){
  • 38. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 38 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Int conf=JOptionPane.showConfirmDialog(null,"Release the prisoner","Message",JOptionPane.OK_CANCEL_OPTION); String id=txtid.getText(); if (conf==0) { try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); //Connection connect = DriverManager.getConnection("jdbc:odbc:employee"); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "update prisoner_details set status=' prisoner released' where id="+id+""; state.execute(sql); //JOptionPane.showConfirmDialog(null,"prisoner released"); System.out.println("Statement executed successfully"); state.close(); connect.close();
  • 39. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 39 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 } catch (Exception ex) { System.out.print(ex); }} }else if(str.equals("UPDATE")){ Update(); }else if(str.equals("DELETE")){ delete(i); } if ((id.equals(""))||(name.equals(""))||(crime_description.equals(""))) { } } boolean Find(int id){ boolean flag=false;
  • 40. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 40 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "select * from prisoner_details where id="+ id +" and status='prisoned'"; ResultSet rs=state.executeQuery(sql); if(rs.next()) { txtid.setText(rs.getString("id")); txtname.setText(rs.getString("name")); txtcrime_desc.setText(rs.getString("crime_description")); flag=true; btnrel.setEnabled(true); btndel.setEnabled(true); btnupdate.setEnabled(true);
  • 41. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 41 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 JOptionPane.showMessageDialog(null, "Record Found Successfully"); } else JOptionPane.showMessageDialog(null, "Check prisoner id and try again "); rs.close(); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } return flag; } void delete(int id){ try{ /** Written in try block, in order to catch the Exception*/
  • 42. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 42 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "DELETE FROM prisoner_details WHERE id="+ id +""; state.execute(sql); // JOptionPane.showMessageDialog(null, "Record deleted Successfully"); System.out.println("Statement executed successfully"); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } } void Update(){ try{ /** Written in try block, in order to catch the Exception*/
  • 43. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 43 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); int i=Integer.parseInt(id); String sql = "UPDATE prisoner_details set id= "+id+", name= '"+name+"', crime_description='"+crime_description+"' WHERE id= "+id+""; state.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Record Updated Successfully"); System.out.println("Statement executed successfully"); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } } } v) Warden page (For adding details of a Warden): /** Importing in order to use the predefined methods and classes*/
  • 44. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 44 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; /** Creating a class Wardens_add and implementing the interface ActionListener*/ class Wardens_add implements ActionListener { /** Declaring the variables*/ /** Declaring the JFrame variable f*/ JFrame f; JButton btnadd,btncncl,btnclr; JLabel lblid,lblname,lbladdress,lblwarden_rank,lblyr_join,lblretire,r; JTextField txtid,txtname,txtaddress,txtwarden_rank,txtyr_join,txtwarden_retire; private String id,name,address,warden_rank,warden_year,warden_retire; /** Constructor Creation */ public void information() { f=new JFrame(); r=new JLabel("WARDEN DETAILS"); r.setBounds(310,95,800,65);
  • 45. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 45 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(r); Font t=new Font("Showcard Gothic",Font.BOLD,85); r.setFont(t); /**Object Creation*/ lblretire=new JLabel("Warden retirement"); lblretire.setBounds(100,490,500,20); f.add(lblretire); Font b=new Font("Dialog",Font.BOLD,25); lblretire.setFont(b); lblid=new JLabel("Id."); lblid.setBounds(100,170,200,20); f.add( lblid); Font k=new Font("Dialog",Font.BOLD,25); lblid.setFont(k); lblname=new JLabel("NAME"); lblname.setBounds(100,230,225,50); f.add(lblname); Font p=new Font("Dialog",Font.BOLD,25); lblname.setFont(p); lbladdress=new JLabel("Address");
  • 46. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 46 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 lbladdress.setBounds(100,300,225,50); f.add(lbladdress); Font a=new Font("Dialog",Font.BOLD,25); lbladdress.setFont(a); lblwarden_rank=new JLabel("Warden Rank"); lblwarden_rank.setBounds(100,370,225,50); f.add(lblwarden_rank); Font q=new Font("Dialog",Font.BOLD,25); lblwarden_rank.setFont(q); lblyr_join=new JLabel("Warden year of joining"); lblyr_join.setBounds(100,420,275,50); f.add(lblyr_join); Font x=new Font("Dialog",Font.BOLD,25); lblyr_join.setFont(x); txtid=new JTextField(10); txtid.setBounds(280,180,250,30); f.add(txtid); txtname=new JTextField(10); txtname.setBounds(280,239,250,30); f.add(txtname);
  • 47. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 47 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtaddress=new JTextField(10); txtaddress.setBounds(280,310,250,50); f.add(txtaddress); txtwarden_rank=new JTextField(10); txtwarden_rank.setBounds(280,380,170,30); f.add(txtwarden_rank); txtyr_join=new JTextField(10); txtyr_join.setBounds(374,440,280,30); f.add(txtyr_join); txtwarden_retire=new JTextField(10); txtwarden_retire.setBounds(374,495,280,30); f.add(txtwarden_retire); btnadd=new JButton("ADD"); btnadd.setBounds(105,560,120,35); btnadd.addActionListener(this); f.add(btnadd); btncncl=new JButton("CANCEL"); btncncl.setBounds(280,560,120,35); btncncl.addActionListener(this);
  • 48. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 48 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(btncncl); btnclr=new JButton("CLEAR"); btnclr.setBounds(435,560,120,35); btnclr.addActionListener(this); f.add(btnclr); /** Making the frame maximized*/ f.setSize(1200,900); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(null); /**Making the Frame visible*/ f.setVisible(true); } /** Main Method*/ public static void main(String args[]) { Wardens_add f=new Wardens_add(); f.information();} /** Providing the implementation of the method of the Interface*/ public void actionPerformed(ActionEvent e) {
  • 49. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 49 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 JButton b=(JButton)e.getSource(); String str=b.getLabel(); id=txtid.getText(); name=txtname.getText(); address=txtaddress.getText(); warden_rank=txtwarden_rank.getText(); warden_year=txtyr_join.getText(); warden_retire=txtwarden_retire.getText(); if(e.getSource()==btnadd){ add(); } else if(str.equals("CLEAR")){ txtid.setText(""); txtname.setText(""); txtaddress.setText(""); txtwarden_rank.setText(""); txtyr_join.setText(""); txtwarden_retire.setText("");
  • 50. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 50 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 } else if(str.equals("ADD")){ String txtid1=txtid.getText(); String txtname1=txtname.getText(); String txtname2=txtaddress.getText(); String txtname3=txtwarden_rank.getText(); String txtname4=txtyr_join.getText(); String txtname5=txtwarden_retire.getText(); } else if(str.equals("CANCEL")) { f.dispose(); } }
  • 51. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 51 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 void add(){ try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); //Connection connect = DriverManager.getConnection("jdbc:odbc:Wardens"); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "INSERT INTO Warden_details (id ,name,address,warden_rank,warden_year,warden_retire) values ('" + id + "','" + name + "','" + address+ "','" + warden_rank+ "','"+ warden_year+"','"+ warden_retire+"')"; state.execute(sql); JOptionPane.showMessageDialog(null, "Record added Successfully"); System.out.println("Statement executed successfully"); state.close(); connect.close(); }
  • 52. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 52 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 catch (Exception e) { System.out.print(e); } } } vi) Warden page (For updating details of a Warden): /** Importing in order to use the predefined methods and classes*/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; /** Creating a class Wardens_add and implementing the interface ActionListener*/ class Warden_details implements ActionListener { /** Declaring the variables*/ /** Declaring the JFrame variable f*/ JFrame f; JButton btnfind,btndel,btnupdate,btnclr,btncncl; JLabel lbl_id,lblname,lbladdress,lblwarden_rank,lblyr_warden,lblretire,r; JTextField txtid,txtname,txtaddress,txtwarden_rank,txtwarden_year,txtwarden_retire; private String id,name,address,warden_rank,warden_year,warden_retire;
  • 53. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 53 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 /** Constructor Creation */ public void init() { f=new JFrame(); r=new JLabel("UPDATE WARDEN DETAILS"); r.setBounds(310,85,1080,65); f.add(r); Font t=new Font("Showcard Gothic",Font.BOLD,65); r.setFont(t); /**Object Creation*/ lblretire=new JLabel("Warden retirement"); lblretire.setBounds(100,500,500,20); f.add(lblretire); Font b=new Font("Dialog",Font.BOLD,25); lblretire.setFont(b); lbl_id=new JLabel("Id."); lbl_id.setBounds(100,170,200,20); f.add(lbl_id); Font k=new Font("Dialog",Font.BOLD,25); lbl_id.setFont(k);
  • 54. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 54 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 lblname=new JLabel("NAME"); lblname.setBounds(100,230,225,50); f.add(lblname); Font p=new Font("Dialog",Font.BOLD,25); lblname.setFont(p); lbladdress=new JLabel("Address"); lbladdress.setBounds(100,300,225,50); f.add(lbladdress); Font a=new Font("Dialog",Font.BOLD,25); lbladdress.setFont(a); lblwarden_rank=new JLabel("Warden Rank"); lblwarden_rank.setBounds(100,370,225,50); f.add(lblwarden_rank); Font q=new Font("Dialog",Font.BOLD,25); lblwarden_rank.setFont(q); lblyr_warden=new JLabel("Warden year of joining"); lblyr_warden.setBounds(100,430,275,50); f.add(lblyr_warden); Font x=new Font("Dialog",Font.BOLD,25); lblyr_warden.setFont(x);
  • 55. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 55 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 txtid=new JTextField(10); txtid.setBounds(280,170,190,30); f.add(txtid); txtname=new JTextField(10); txtname.setBounds(280,239,190,30); f.add(txtname); txtaddress=new JTextField(10); txtaddress.setBounds(280,310,190,30); f.add(txtaddress); txtwarden_rank=new JTextField(10); txtwarden_rank.setBounds(280,380,190,30); f.add(txtwarden_rank); txtwarden_year=new JTextField(10); txtwarden_year.setBounds(374,440,280,30); f.add(txtwarden_year); txtwarden_retire=new JTextField(10); txtwarden_retire.setBounds(374,495,280,30); f.add(txtwarden_retire);
  • 56. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 56 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 btnfind=new JButton("FIND"); btnfind.setBounds(95,550,120,35); btnfind.addActionListener(this); f.add(btnfind); btndel=new JButton("DELETE"); btndel.setBounds(295,550,120,35); btndel.addActionListener(this); f.add(btndel); btnupdate=new JButton("UPDATE"); btnupdate.setBounds(495,550,120,35); btnupdate.addActionListener(this); f.add(btnupdate); btncncl=new JButton("CANCEL"); btncncl.setBounds(880,550,120,35); btncncl.addActionListener(this); f.add(btncncl); btnclr=new JButton("CLEAR"); btnclr.setBounds(695,550,120,35); btnclr.addActionListener(this);
  • 57. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 57 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 f.add(btnclr); btndel.setEnabled(false); btnupdate.setEnabled(false); btncncl.setEnabled(false); /** Making the frame maximized*/ f.setSize(1200,900); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(null); f.setVisible(true); } /** Main Method*/ public static void main(String args[]) { Warden_details f=new Warden_details(); f.init(); } /** Providing the implementation of the method of the Interface*/ public void actionPerformed(ActionEvent e) {
  • 58. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 58 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 id=txtid.getText(); name=txtname.getText(); address=txtaddress.getText(); warden_rank=txtwarden_rank.getText(); warden_year=txtwarden_year.getText(); warden_retire=txtwarden_retire.getText(); int i=0; try{ /** Written in try block, in order to catch the Exception*/ i=Integer.parseInt(id); } catch(Exception ex){} JButton b=(JButton)e.getSource(); String str=b.getLabel(); if(str.equals("FIND")){ if(txtid.getText().trim().length()!=0) //Validation in order to show provided message Find(i);
  • 59. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 59 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 else JOptionPane.showMessageDialog(null, "Text field is empty"); } else if(str.equals("CANCEL")) { f.dispose(); } else if(str.equals("CLEAR")){ txtid.setText(""); txtname.setText(""); txtaddress.setText(""); txtwarden_rank.setText(""); txtwarden_year.setText(""); txtwarden_retire.setText(""); }else if(str.equals("UPDATE")){ if(txtid.getText().trim().length()!=0) //Validation in order to show provided message Update();
  • 60. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 60 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 else JOptionPane.showMessageDialog(null, "Text field is empty"); }else if(str.equals("DELETE")){ i=Integer.parseInt(id); delete(i); } if ((id.equals(""))||(name.equals(""))||(address.equals(""))||(warden_rank.equals(""))||(warden_year.e quals(""))||(warden_retire.equals(""))) { } } boolean Find(int id){ boolean flag=false; try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully");
  • 61. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 61 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); String sql = "select * from Warden_details where id="+ id +""; ResultSet rs=state.executeQuery(sql); if(rs.next()) { txtid.setText(rs.getString("id")); txtname.setText(rs.getString("name")); txtaddress.setText(rs.getString("address")); txtwarden_rank.setText(rs.getString("warden_rank")); txtwarden_year.setText(rs.getString("warden_year")); txtwarden_retire.setText(rs.getString("warden_retire")); flag=true; btndel.setEnabled(true); btnupdate.setEnabled(true); btncncl.setEnabled(true); } JOptionPane.showMessageDialog(null, "Record Found Successfully");
  • 62. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 62 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 System.out.println("Statement executed successfully"); rs.close(); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } return flag; } void delete(int id){ try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb"; Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement();
  • 63. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 63 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 String sql = "DELETE FROM Warden_details WHERE id="+ id +""; state.execute(sql); JOptionPane.showMessageDialog(null, "Record deleted Successfully"); System.out.println("Statement executed successfully"); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } } void Update(){ try{ /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Divers loaded successfully"); String source = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PMS.mdb";
  • 64. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 64 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Connection connect = DriverManager.getConnection(source); System.out.println("Connection established successfully"); Statement state = connect.createStatement(); int i=Integer.parseInt(id); String sql = "UPDATE Warden_details set id= "+id+", name= '"+name+"', address='"+address+"',warden_rank='"+warden_rank+"',warden_year='"+warden_year+"',warden _retire='"+warden_retire+"' WHERE id= "+id+""; state.executeUpdate(sql); JOptionPane.showMessageDialog(null, "Record Updated Successfully"); System.out.println("Statement executed successfully"); state.close(); connect.close(); } catch (Exception e) { System.out.print(e); } }} vii)Report page (For report details of a Prisoner): /** Importing in order to use the predefined methods and classes*/ import java.awt.*;
  • 65. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 65 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 import java.awt.event.*; import java.sql.*; import javax.swing.JFrame; /** Creating a class Wardens_add and implementing the interface ActionListener*/ class Report1 extends JFrame implements WindowListener { private boolean flag=true; List lstrpt; public Report1(){ setTitle("Report"); setSize(430,350); setLayout(null); /** Making the frame visible*/ setVisible(true); lstrpt=new List(); add(lstrpt); lstrpt.setBounds(10,40,1200,400); addWindowListener(this);
  • 66. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 66 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 try { /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:PMS","",""); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from prisoner_details"); String st=""; while(rs.next()){ st =rs.getString("id")+" "+rs.getString("name")+" "+rs.getString("address")+" "+rs.getString("date_of_crime")+" "+rs.getString("crime_description")+" "+rs.getString("date_of_prisonment")+" "+rs.getString("date_of_release")+" "+rs.getString("status"); lstrpt.add(st); } } catch(Exception e){
  • 67. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 67 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 } } //Implementing windows Listener public void itemStateChanged(ItemEvent e){} public void windowOpened(WindowEvent e){} public void windowClosing(WindowEvent e){dispose();} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public static void main(String args[]){ Report1 r=new Report1(); } }
  • 68. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 68 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 viii) Report page (For report details of a warden): /** Importing in order to use the predefined methods and classes*/ import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.JFrame; /** Creating a class Wardens_add and implementing the interface ActionListener*/ class Report2 extends JFrame implements WindowListener { private boolean flag=true; List lstrpt; public Report2(){ setTitle("Report"); setSize(430,350); setLayout(null); /** Making the frame visible*/ setVisible(true); lstrpt=new List(); add(lstrpt);
  • 69. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 69 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 lstrpt.setBounds(10,40,1200,400); addWindowListener(this); try { /** Written in try block, in order to catch the Exception*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:PMS","",""); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from Warden_details"); String st=""; while(rs.next()){ st =rs.getString("id")+" "+rs.getString("name")+" "+rs.getString("address")+" "+rs.getString("warden_rank")+" "+rs.getString("warden_year")+" "+rs.getString("warden_retire"); lstrpt.add(st); } } catch(Exception e){
  • 70. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 70 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 } } //Implementing windows Listener public void itemStateChanged(ItemEvent e){} public void windowOpened(WindowEvent e){} public void windowClosing(WindowEvent e){dispose();} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public static void main(String args[]){ Report2 r=new Report2(); } }
  • 71. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 71 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 SAMPLE OUTPUTS AND EXPLANATIONS i) Login Screen : In this ,text Field are used for taking the Username and Password Field used for taking the password from the user. A Button that submits the user’s entered value and satisfies the Username and Password of the user and a cancel is used to cancel the details. ii) Home Screen : After logging in Prison management system screen will appear which is provided with the following main menu. The administrator had given the privilege to prisoner, warden, reports and logout. And after clicking on these menu you can go further sub-menus.
  • 72. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 72 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 iii) Prisoner Add Screen : This screen very well depicts the entire details of a prisoner all necessary details will be filled in it and after clicking on the add button you will be shown with a dialog box indicating that the prisoner details have been added successfully. iv) Prisoner Update Screen : This screen very well depicts the details which you wish to find, release, delete, update in a prisoner details and after you add the prisoner id there you will get all the others details after clicking on the find button you will be shown with
  • 73. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 73 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 a dialog box indicating that the prisoner details have been found successfully. In it all the other buttons will be disabled if you don’t find any prisoner. v) Warden Add Screen : This screen very well depicts the entire details of a warden all necessary details will be filled in it and after clicking on the add button you will be shown with a dialog box indicating that the records have been added successfully.
  • 74. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 74 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 vi) Warden Update Screen : This screen very well depicts the details which you wish to find, delete, update in a warden details and after you add the warden id there you will get all the others details after clicking on the find button you will be shown with a dialog box indicating that the warden details have been found successfully. In it all the other buttons will be disabled if you don’t find any warden. vii) Prisoner report Screen : This screen very well depicts the entire report of a prisoner all necessary details that you have added in the database.
  • 75. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 75 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 viii) Warden report Screen : This screen very well depicts the entire report of a warden all necessary details that you have added in the database. ADDITIONAL FEATURES i) Use of Exception Handling apart from database.
  • 76. CE00396-1-Object Oriented & Event Driven Programming Assignment Page 76 of 76 __________________________________________________________________________________ Level 1 Asia Pacific Institute of Information Technology 2015 Apart from database connectivity, Exception handling concept is used in the application to handle the exceptions more efficiently. ii) Validation is provided to almost every field. The validation is provided to almost every aspects of the application to make the data storage more persistent and the application user-friendly. iii) Predefined interfaces are implemented. Predefined interfaces are implemented in the application. iv) A Log out menu item is provided for logging out of the application. A logout menu is provided in the main menu of the application, for logging out of the application. ASSUMPTIONS i) Basic User Requirements It has been assumed that the user of the application should have basic computer knowledge and all other programming skills, in order to use the application more effectively. REFERENCES i) Schildt, H (2007). Java: The Complete Reference. 7 West Patel Nagar, New Delhi: Tata McGraw-Hill Publishing Company Limited. p205-217. ii) http://www.java2s.com/Tutorial/Java/0240__Swing/SetFontandforegroundcol orforaJLabel.htm. Last accessed 20th April.