Top Banner
-: Certificate :- This is to certify that CM.SATWIK of class XII-A has successfully completed “INFORMATICS PRACTICES” project entitled SLAM BOOKduring the academic year 2014-2015. Signature of candidate 1
38

Informatics Practices

Dec 26, 2015

Download

Documents

Indira Devi

cbse class xii project based on netbeans and sql
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Informatics Practices

-: Certificate :-

This is to certify that CM.SATWIK of class

XII-A has successfully completed

“INFORMATICS PRACTICES” project entitled

‘SLAM BOOK’’ during the academic year 2014-

2015.

Signature of candidate

Signature of Signature of

Internal Examiner: External Examiner:1

Page 2: Informatics Practices

2

Page 3: Informatics Practices

I hereby declare that the project work

entitled ‘SLAM BOOK’’, submitted to

Department of Computer Science, Army Public

School, Bangalore is prepared by me. All the

coding are result of my personal efforts.

CM.SATWIK

Class XII A

3

DECLARATION

Page 4: Informatics Practices

“Gratitude is the fairest blossom which springs from the

soul” Feeling gratitude and not expressing it is like wrapping

a present and not giving it. We take this opportunity to

convey our heartfelt gratitude to each and every one who

has supported us in every way or the other during the course

of our project.

From the very core of our heart, we would like to express

our sincere gratitude to Mr. Ajith Sir for his supervisory

guidance. We are always indebted to him for his kind support

and constant encouragement and his enthusiasm to

complete our project milestones. I would also like to express

my hearty gratitude to the lab colleague Akash Mitra for his

support during the making of this project.

We are always grateful to our peers and friends who have

always encouraged us and guided us whenever we needed

assistance. I wish to thanks my parents for their undivided

support & interest who inspired & encouraged me to go my

own way, without which I would be unable to complete my

project.4

ACKNOWLEDGEMENT

Page 5: Informatics Practices

. Things always remain hidden in the shadow of the

unsung heroes; still we would to thank all the people

passively involved in the assignment, people who

encouraged us day in and day out to make it a success. At

last but above all, we thank the Almighty for his blessings.

CM.SATWIK

Class: XIIA

1. INTRODUCTION

2. HARDWARE AND SOFTWARE REQUIREMENTS

3. FILES IMPORTED

4. CLASSES WORKING DESCRIPTION

7. CODING

8. CONCLUSION

9. BIBLIOGRAPHY

5

CONTENTS

Page 6: Informatics Practices

A typical Slam Book requires a management system to ease its

operations such as maintaining details of all the people in it, attending

to various needs of users and also achieving increased efficiency in the

accessing of the data.

PURPOSE OF THE SYSTEM The “SLAM BOOK” System aims to make

simpler a user interaction with the various modules and ease the

process of saving information and retrieving whenever needed. The

system also allow searching of a person’s details with his first name.

SCOPE In this system we will make extensive use of files system in

JAVA. We will have a welcome system initially. In this system we will be

6

Introduction

Page 7: Informatics Practices

having separate functions for adding the information, retrieving the

information and also searching. In this software separate functions will

be there for each of the above points so that there is ample scope for

adding more features in the near future. But how ever if it is made web

based then it will become more useful.

Hardware: On the hardware part any hardware that

supports Windows Vista/7/XP installed will sufficient

Software : The platform used is NetBeans. Hence we

decided to use NetBeans IDE 8.0 edition.

7

Hardware & software required

Page 8: Informatics Practices

For optional coding and easy debugging we used this edition

and made explicit jar files.

Henceforth for optimal usage of such software a windows

based operating system preferably Windows vista/7/XP

must be there.

java.awt : Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components uses the resources of system. The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc.

java.io: Java IO is an API that comes with Java which is targeted at reading and writing data (input and output). The Java IO package is primarily focused on input and output to files, network streams, internal memory buffers etc. you read and write data to and from it via Java IO's InputStream and OutputStream classes.

java.sql: This package provides the APIs for accessing and processing data which is stored in the database especially relational database by using the java programming language. It includes a framework where we different drivers can be installed dynamically to access different databases especially relational databases.

8

Files imported

Page 9: Informatics Practices

This java.sql package contains API for the following basic operations other than Mappings and Exceptions.

1 Making a connection with a database with the help of DriverManager class

2). Sending SQL Parameters to a database:

3). Updating and retrieving the results of a query:

javax.imageio: This package contains the basic classes and interfaces for

describing the contents of image files, including metadata and thumbnails (IOImage); for

controlling the image reading process, and image writing process, and for reporting

errors.

javax.swing: Swing is a GUI widget toolkit for Java . It is part of Oracle's

JavaFoundation Classes (JFC) — an API for providing a graphical user interface (GUI) for

Java programs. Swing was developed to provide a more sophisticated set of GUI

components than the earlier Abstract Window Toolkit (AWT). Swing provides several

advanced components such as tabbed panel, scroll panes, trees, tables, and lists.

Welcome: It is the welcome screen which enables the

user

to enter in to the system . It is set as main file

of

the project.9

Classes generated

Page 10: Informatics Practices

Start: It allows the user to navigate to the various

options of the software

Addbuddy: It allows the user to add various details of the

friend in the database like name, mobile

number etc. It also takes the photograph of

the person whose details are being stored.

Viewbuddy: It allows the user to view list of the friends in

the database. It also shows the details of the

person after clicking the particular name in

listbox.

Search: It allows the user to search a particular

Friend in the database. It also shows the

details of the person.

welcome class

CODING

10

Page 11: Informatics Practices

package myslambook;

import java.awt.Color;

/** * @author CM SATWIK*/

Public class welcome extends javax.swing.JFrame {

public welcome() {

initComponents(); this.getContentPane().setBackground(Color.blue) ; }

private void initComponents() {

jButton1 = new javax.swing.JButton();

jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

setBackground(new java.awt.Color(51, 0, 255));

setPreferredSize(new ava.awt.Dimension(1450, 1000));

setType(java.awt.Window.Type.UTILITY);

jButton1.setBackground(new java.awt.Color(153, 204, 255));

jButton1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N

jButton1.setForeground(new java.awt.Color(0, 0, 153));

jButton1.setText("WELCOME TO MY SLAMBOOK");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt)

jButton1ActionPerformed(evt); } });

Private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

new startup().setVisible(true); }

11

Page 12: Informatics Practices

public static void main(String args[]) {

}

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new welcome().setVisible(true);}

}); }

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabe

// End of variables declaration

}

_____________________ End of Welcome Class___________________________________________

12

Page 13: Informatics Practices

Startup class

CODING

package myslambook;

import java.awt.Color;

public class startup extends javax.swing.JFrame {

public startup() {

initComponents();

this.getContentPane().setBackground(Color.DARK_GRAY) ;

jButton1.setBackground(Color.RED);

jButton2.setBackground(Color.MAGENTA);

jButton3.setBackground(Color.GREEN);

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

new viewbuddy().setVisible(true);

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

new addbuddy().setVisible(true);

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

new search().setVisible(true);

}

13

Page 14: Informatics Practices

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0); }

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new startup().setVisible(true);

} });

}

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JLabel jLabel1;

// End of variables declaration

}

___________________________ End of Startup Class_______________________________

14

Page 15: Informatics Practices

Add buddy

CODING

package myslambook;

import java.awt.Color;

import java.awt.HeadlessException;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

import javax.swing.JFileChooser;

15

Page 16: Informatics Practices

import javax.swing.JOptionPane;

import javax.swing.filechooser.FileNameExtensionFilter;

public class addbuddy extends javax.swing.JFrame {

public addbuddy() {

initComponents();

this.getContentPane().setBackground(Color.BLUE) ;

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

FileNameExtensionFilter filter = new FileNameExtensionFilter(

"JPG, GIF, and PNG Images", "jpg", "gif", "png");

jFileChooser1.setFileFilter(filter);

int o = jFileChooser1.showOpenDialog(this);

if (o == JFileChooser.APPROVE_OPTION) {

File f = jFileChooser1.getSelectedFile();

filename = f.getAbsolutePath();

System.out.println("You chose to open this file: " + f.getName());

BufferedImage image;

try

{ //display the image in jlabel

image = ImageIO.read(f);

jLabel16.setIcon(new ImageIcon("" + f)); }

catch(IOException e) { }

16

Page 17: Informatics Practices

this.pack();}

}

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {

if (jRadioButton1.isSelected())

jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Acquintance.png")));

relation = "acquintance"; }

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {

if (jRadioButton2.isSelected())

jLabel12.setIcon(newjavax.swing.ImageIcon(getClass().getResource("/images/Best

riend.png"))); relation = "bestfriend"; }

private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {

if (jRadioButton3.isSelected())

jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Family.png")));

relation = "familyfriend"; }

private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {

if(jRadioButton4.isSelected())

jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Stranger.png")));

relation = "stranger"; }

private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {

if (jRadioButton5.isSelected())

jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Friend.png")));

relation = "classmate"; }

public void StoreImage() {

initComponents();

17

Page 18: Informatics Practices

initConnection();

setSize(600,500); }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false); }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");

connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/slambook","root","tiger");

System.out.println("Connection Established Succcesfully..."); }

catch(ClassNotFoundException | SQLException e)

{

JOptionPane.showMessageDialog(this, e.getMessage());

}

try {

if(filename!=null ) {

ps=connection.prepareStatement("insert into friends values(?,?,?,?,?,?,?,?,?,?,?)");

FileInputStream fileInputStream=new FileInputStream(filename);

byte b[]=new byte[fileInputStream.available()];

fileInputStream.read(b);

fileInputStream.close();

ps.setObject(1, jtext1.getText());

ps.setObject(2, jtext2.getText());

18

Page 19: Informatics Practices

ps.setObject(3, jtext3.getText());

ps.setObject(4, jtext4.getText());

ps.setObject(5, jtext5.getText());

ps.setObject(6, jtext6.getText());

ps.setObject(7, jtext7.getText());

ps.setObject(8, jtext8.getText());

ps.setObject(9, jarea1.getText());

ps.setBytes(10, b);

ps.setObject(11, relation);

int val=ps.executeUpdate();

if(val>=1)

{JOptionPane.showMessageDialog(this, "Succesfully Stored...");}

else

{JOptionPane.showMessageDialog(this, "Error in storage...");}

} }

catch(SQLException | IOException | HeadlessException e)

{ JOptionPane.showMessageDialog(this, e.getMessage()); } }

public void clearAll(){

jtext1.setText("");

jtext2.setText("");

jtext3.setText("");

jtext4.setText("");

jtext5.setText("");

19

Page 20: Informatics Practices

jtext6.setText("");

jtext7.setText("");

jtext8.setText("");

jarea1.setText(""); }

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

new addbuddy().setVisible(true);

}

}); }

______________________End of Addbuddy Class_______________________

viewbuddy

CODING

package myslambook;

import java.awt.image.BufferedImage;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

20

Page 21: Informatics Practices

import javax.imageio.ImageIO;

import javax.swing.DefaultListModel;

import javax.swing.ImageIcon;

import javax.swing.table.DefaultTableModel;

public class viewbuddy extends javax.swing.JFrame {

private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

String s = jList1.getSelectedValue().toString();

try {

Class.forName("com.mysql.jdbc.Driver");

connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/

slambook","root","tiger");

statement = connection.createStatement();

resultSet = statement.executeQuery("SELECT * FROM friends WHERE realname = \'" + s + "\';");

while(resultSet.next()){

jLabel2.setText(resultSet.getString(1));

jLabel3.setText(resultSet.getString(2));

jLabel4.setText(resultSet.getString(3));

jLabel5.setText(resultSet.getString(4));

jLabel6.setText(resultSet.getString(5));

jLabel7.setText(resultSet.getString(6));

21

Page 22: Informatics Practices

jLabel8.setText(resultSet.getString(7));

jLabel9.setText(resultSet.getString(8));

jLabel10.setText(resultSet.getString(9));

jLabel11.setText(resultSet.getString(11));

BufferedImage im = ImageIO.read(resultSet.getBinaryStream(10));

ImageIcon image1 = new ImageIcon(im);

jLabel1.setIcon(image1);

showall(); } }

catch (Exception ex) {

ex.printStackTrace(); }

finally

{

try {

resultSet.close();

statement.close();

connection.close();

}

catch (Exception ex) {

ex.printStackTrace();

} } }

public final void clearAll(){

jLabel1.setText("");

jLabel2.setText("");

22

Page 23: Informatics Practices

jLabel3.setText("");

jLabel4.setText("");

jLabel5.setText("");

jLabel6.setText("");

jLabel7.setText("");

jLabel8.setText("");

jLabel9.setText("");

jLabel10.setText("");

jLabel11.setText("");

}

public final void showall(){

l1.setVisible(true);

l2.setVisible(true);

l3.setVisible(true);

l4.setVisible(true);

l5.setVisible(true);

l6.setVisible(true);

l7.setVisible(true);

l8.setVisible(true);

l9.setVisible(true);

l10.setVisible(true); }

public final void hideall(){

l1.setVisible(false);

23

Page 24: Informatics Practices

l2.setVisible(false);

l3.setVisible(false);

l4.setVisible(false);

l5.setVisible(false);

l6.setVisible(false);

l7.setVisible(false);

l8.setVisible(false);

l9.setVisible(false);

l10.setVisible(false);

jList1.setVisible(false); }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

jList1.setVisible(true);

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

try {

Class.forName("com.mysql.jdbc.Driver");

connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/

slambook","root","*****");

statement = connection.createStatement();

resultSet = statement.executeQuery("SELECT * FROM friends;" );

24

Page 25: Informatics Practices

DefaultListModel list = new DefaultListModel();

int i = 0 ;

while(resultSet.next()) {

list.addElement(resultSet.getString(1)); }

jList1.setModel(list); }

catch (ClassNotFoundException | SQLException ex) {

ex.printStackTrace(); }

finally {

try {

resultSet.close();

statement.close();

connection.close(); }

catch (Exception ex) {

ex.printStackTrace();

} } }

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new viewbuddy().setVisible(true);

} }); }}

__________________________________________ End of Viewbuddy Class_________________

search25

Page 26: Informatics Practices

CODING

package myslambook;

import java.awt.Color;

import java.awt.image.BufferedImage;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

public class search extends javax.swing.JFrame {

public search() {

initComponents();

clearAll();

hideall();

this.getContentPane().setBackground(Color.BLUE) ; }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

try {

Class.forName("com.mysql.jdbc.Driver");

26

Page 27: Informatics Practices

connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/

slambook","root","*****");

statement = connection.createStatement();

resultSet = statement.executeQuery("SELECT * FROM friends WHERE realname = \'" +

jsearch.getText() + "\';");

while(resultSet.next()){

jLabel2.setText(resultSet.getString(1));

jLabel3.setText(resultSet.getString(2));

jLabel4.setText(resultSet.getString(3));

jLabel5.setText(resultSet.getString(4));

jLabel6.setText(resultSet.getString(5));

jLabel7.setText(resultSet.getString(6));

jLabel8.setText(resultSet.getString(7));

jLabel9.setText(resultSet.getString(8));

jLabel10.setText(resultSet.getString(9));

jLabel1.setText(resultSet.getString(11));

BufferedImage im = ImageIO.read(resultSet.getBinaryStream(10));

ImageIcon image1 = new ImageIcon(im);

jLabel1.setIcon(image1);

showall(); } }

catch (Exception ex) {

ex.printStackTrace(); }

finally {

27

Page 28: Informatics Practices

try {

resultSet.close();

statement.close();

connection.close();

}

catch (Exception ex) {

ex.printStackTrace(); } }

}

public final void clearAll(){

jLabel1.setText("");

jLabel2.setText("");

jLabel3.setText("");

jLabel4.setText("");

jLabel5.setText("");

jLabel6.setText("");

jLabel7.setText("");

jLabel8.setText("");

jLabel9.setText("");

jLabel10.setText("");

jLabel11.setText("");

}

public final void showall(){

l1.setVisible(true);

28

Page 29: Informatics Practices

l2.setVisible(true);

l3.setVisible(true);

l4.setVisible(true);

l5.setVisible(true);

l6.setVisible(true);

l7.setVisible(true);

l8.setVisible(true);

l9.setVisible(true);

l10.setVisible(true); }

public final void hideall(){

l1.setVisible(false);

l2.setVisible(false);

l3.setVisible(false);

l4.setVisible(false);

l5.setVisible(false);

l6.setVisible(false);

l7.setVisible(false);

l8.setVisible(false);

l9.setVisible(false);

l10.setVisible(false); }

public static void main(String args[]) {

public void run() {

new search().setVisible(true);

29

Page 30: Informatics Practices

}

}); }}

________________________ End of Search Class____________________

Conclusion

This Software is developed initially with basic features. First

the welcome Screen appears, from where a user is allowed to traverse

through. Then various options like Addbuddy, Viewbuddy, Search and

Exit options comes.

A user can save details of a friend in Addbuddy. View the list

of friends in Viewbuddy, and further clicking on any name, one can see

the full details. He can also search any particular friend by typing name.

Right now we are developing this software for testing

purpose but after completing this project it can be used as web

application. It will reduce use of paper and it will be time saving

software. It will produce result efficiently and quickly.

The software removes the redundancy by providing the check on

mobile no., which allows only one data record, can exist in table for one

mobile no. we can modify the software according their further requirements

and additional features can be added.

30

Page 31: Informatics Practices

Bibliography

1 h t t p : // w ww . g o o g l e . c o m /

2 h t t p : / / e n . w i k i p e d i a . o r g

3 http://cbsecsnip.in

4 http://cbse.nic.in

5 www . b O t s k OO L . c o m

31

Page 32: Informatics Practices

32