0% found this document useful (0 votes)
82 views41 pages

Polling System - Final Report

This document provides a software requirements specification for an online polling system project built in Java. The system allows administrators to create polls and view voting results, while voters can register and cast their votes. It describes the purpose, audience, product scope, functions, and classes of users. Requirements include allowing administrators to add candidates and see vote details, and enabling voters to register, log in and submit their votes. The system will use a Java interface, MySQL database, and be run on a Windows operating system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views41 pages

Polling System - Final Report

This document provides a software requirements specification for an online polling system project built in Java. The system allows administrators to create polls and view voting results, while voters can register and cast their votes. It describes the purpose, audience, product scope, functions, and classes of users. Requirements include allowing administrators to add candidates and see vote details, and enabling voters to register, log in and submit their votes. The system will use a Java interface, MySQL database, and be run on a Windows operating system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Project Report on

POLLING SYSTEM
Java Application

B.Tech. in
COMPUTER SCIENCE & ENGINEERING

SUBMITTED BY:

SOMAAY MAHESHWARI 19070122170


VIDHI KHATWANI 19070122194

CSE 2019-23

Under the Guidance of

PROF. KALYANI KADAM

SYMBIOSIS INSTITUTE OF TECHNOLOGY

(A CONSTITUTENT OF SYMBIOSIS INTERNATIONAL UNIVERSITY)


Pune - 412115
2019-23
Software Requirement Specification
Table of Contents

1. Introduction ............................................................................................................................... 3
1.1 Purpose .................................................................................................................................. 3
1.2 Document Conventions ......................................................................................................... 3
1.3 Intended Audience and Reading Suggestions ....................................................................... 3
1.4 Product Scope ........................................................................................................................ 4
1.5 References ............................................................................................................................. 4

2. Overall Description.................................................................................................................... 4
2.1 Product Perspective ............................................................................................................... 4
2.2 Product Functions .................................................................................................................. 5
2.3 User Classes and Characteristics ........................................................................................... 5
2.4 Operating Environment ......................................................................................................... 5
2.5 Design and Implementation Constraints................................................................................ 5
2.6 User Documentation .............................................................................................................. 6
2.7 Assumptions and Dependencies ............................................................................................ 6

3. Functional Requirements .......................................................................................................... 6


3.1 Requirement 1
3 1.1 Refinement of Requirement 1:
Input:
Output

3.2 Requirement 2
3 2.1 Refinement of Requirement 2:
Input: Outpt:
3.n Requirement n
4. Other Nonfunctional Requirements ......................................................................................... 7
4.1 Performance Requirements.................................................................................................... 7
4.2 Safety Requirements .............................................................................................................. 8
4.3 Security Requirements........................................................................................................... 8
4.4 Software Quality Attributes ................................................................................................... 8

5. Analysis Models .......................................................................... …………………………………….9


5.1 Use-Case Diagram .......................................................................................................... 9

5.2 Class Diagram ............................................................................................................... 10

6. Implementation Screenshots ............................................................................................. 10,35

7. Project Outcome ....................................................................................................................... 42

8. Conclusion and Future Scope ................................................................................................. 42


Detailed description of the above SRS template:
1. Introduction
1.1 Purpose
The word “vote” means to choose from a list, to elect or to determine. The main goal of
voting (in a scenario involving the citizens of a given country) is to come up with leaders of
the people’s choice. And the process of voting in an election is called Pole.

The Online Polling System is a java application which has important features related to GUI
and database properties that determine the software requirements for this project. This
project is meant for small scale voting processes like college elections or feedback forms. In
this project, we will provide an online tool to vote on various questions submitted by the
administrator/organizer.

The purpose of this document is to make the practical and non-functional requirements of the
Online Polling System easier to understand. It also works with the aim of making the
function clear to end-users.

1.2 Document Conventions


When writing this document, it was inherited that all requirements have the same priority.
First an overall view of the system is presented and then all features and functions are
analyzed in detail.

1.3 Intended Audience and Reading Suggestions


This project is a prototype for the online polling system and it is restricted within the college
premises. This has been implemented under the guidance of college professors. This project
is useful for the students and professors for e-voting.

1.4 Product Scope


A software product is an independent program and not part of a larger program. The
system will be made up of two parts. Prior to the voting day, the system will be used for
general purposes such as viewing participant profiles and previous voting results.
Voters will be able to access the system through Java IDE only.

The system can be used for general polling in any institutions or communities. E.g.: for
college elections, feedback forms etc.
• Less effort and less labour intensive, as the primary cost and focus primary on
creating, managing the votes.
• Increasing number of voters as individuals will find it easier and more convenient
to vote.
1.5 References
https://www.eballot.com/votes-and-elections/what-is-an-online-voting-system

https://www.researchgate.net/publication/326059800_An_Online_Voting_System_for_Colle
ges_and_Universities
GUI in JAVA: https://www.youtube.com/watch?v=Kmgo00avvEw
https://www.youtube.com/watch?v=Kmgo00avvEw
https://www.slideshare.net/nitinbhasin3/online-voting-system-project-file

2. Overall Description
2.1 Product Perspective
“College Online Polling/ Voting System” is a java application which uses the concept of
Advance Java and GUI. This application provides an easy and simple way to both
administrator and voters in the collect polling process. In this application, voters can give
their votes to the options that are already provided. The administrator can add all the details
of the candidates with the selected department. The administrator can view all the details of
the candidates and if necessary, he can delete the details of the candidate. In this application,
all the details of the voters can be view in a combine form which makes the work of the
administrator easy in analyzing the votes.

2.2 Product Functions


The system can work in two ways, namely, Normal Interaction Mode and Voting
Mode.
The program will be in voting mode, with the sole purpose of voting on voting day.
Normal Collaborative Mode to accept registrations, conversations between voters, and
campaigns and programs are available in this mode at all times without voting Days.

2.3 User Classes and Characteristics


2 major classes will be there

Admin class: Admin can get logged into the application by entering valid credentials. Admin
can add candidates. Admin can view the details of the votes and result. Class name is
AminFrame.

Voter class: Voters can need to get registered with the application by entering all the details
in the registration form. The voter can get logged in to the application by entering unique
username and password. The voter can fill all the details to give his/her vote.

For the Registration process, there are classes named RegisterService and RegistrationFrame
while for the Voting process, the classes are VoteService, VoteFrame, and VoteException.
DAO class includes all the function by which connectivity with the database is being
processed. The Result is being calculated in the Result class. MyProject is the main class of
this project which contains the psvm for the users to sign in and cast their votes.

All the classes including ‘Frame’ in their name, such as WelcomeFrame and ExitFrame, are
being used for the GUI function to display the data.

2.4 Operating Environment


The poll server runs on JVM and IDE itself. It uses a friendship database to keep track
of polling stations, which connects via a standard database connection way of meeting.
To use the setup software, the environment needs to have Java Virtual machine you
work on.
➢ Operating system: windows XP and above.
➢ Coding language: Advance Java
➢ Tool: IntelliJ IDE
➢ Database: MySQL
GUI (graphical user interface) will be used for this mini project.

2.5 Design and Implementation Constraints


Due to the sensitive nature of the information handled by the “Online Polling System”
software, a good deal of specific design constraints will be taken into consideration:
• The system shall only have the ability to write vote data (not read).
• The system shall not have the ability to overwrite any previously written vote
data.
• Ballot information cannot be changed once a vote has been cast.

2.6 User Documentation


Documentation for the “Online Voting System” software package will be provided in
the form of an online help manual, accessible directly from any portion of the user
interface. Two distinct variations will exist:
• The voter manual will cover, in detail, the process by which a voter chooses
candidates, confirms their selections, makes corrections if necessary, and casts a
ballot. This manual will be accessible to all users of the system.
• The system support manual will describe the steps necessary for a system
administrator to add, remove or change a ballot entry - along with all other
administrative functions. This manual will only be accessible to system
administrators when properly logged in.

2.7 Assumptions and Dependencies


• It is assumed that the user knows his/her password
• It is assumed that the list of options/choices is been already provided to the users.

3. Functional Requirements / System Features


3.1 Main Feature
Voting and choosing their favorable option.

3.2 Question Answer Feature

3.1.1 Description and Priority


Priority – Less
We can use a feedback or question answer feature which will help the voter have
good interactive with the Candidates.
3.1.2 Stimulus/Response Sequences
The Voter could ask any questions to the candidates and if the candidate gives an
appropriate answer the voter would be more satisfied and the candidate too.

4. Other Nonfunctional Requirements


4.1 Performance Requirements
The program is expected to have a sensible short-term response. The voter must know the
login details and should be able to get a response to his requests in 2-3 seconds.
System performance varies depending on its mode

• The “Electronic Polling System” software package will perform all functions with
minimal delay from the time of the initial request.
• The software will only accommodate one user at a time. No simultaneous use of
the system by multiple voters, administrators, or a combination thereof shall be
allowed.

The steps involved to perform the implementation of voting database are as listed below.

A) E-R DIAGRAM
The E-R Diagram constitutes a technique for representing the logical structure of a database
in a pictorial manner. This analysis is then used to organize data as a relation, normalizing
relation and finally obtaining a relation database.

• ENTITIES: Which specify distinct real-world items in an application.


• PROPERTIES/ATTRIBUTES: Which specify properties of an entity and
relationships.

• RELATIONSHIPS: Which connect entities and represent meaningful dependencies


between them.

B) NORMALIZATION:
The basic objective of normalization is to reduce redundancy which means that information
is to be stored only once. Storing information several times leads to wastage of storage space
and increase in the total size of the data stored.
If a database is not properly designed it can give rise to modification anomalies.
Normalization is the process of breaking down a table into smaller tables. So that each table
deals with a single theme.

4.2 Safety Requirements

• To prevent data loss in the event of a system failure, the results of the votes are cast
until then you should be saved in the database.

• If the Admin finds any security issues in the system, it should be able to shut down
shut down the system and block all server communication immediately to save votes
have already been cast.

• The system must warn Admin users of system malfunctions.


4.3 Security Requirements
• To prevent attack the system should generate random words and ask the user to insert
well to try more.
• All passwords generated or received must be stored in a database at
encrypted form
• Client data transactions between the client and the server must be encrypted using SSL
technology.

4.4 Software Quality Attributes


• AVAILABILITY: Favorable candidate or correct answer must be there in the options.
• FLEXIBILITY: The software will be flexible to users.
• CORRECTNESS: The software must count the votes correctly and it should provide a
correct percentage distributer.
• MAINTAINABILITY: The admin must maintain the system according to the dates.
• USABILITY: The software should be used by maximum no. of candidates for voting.
1. A voter may only cast a ballot if they are eligible to vote.
2. A voter may only cast one (1) ballot per election.
• PORTABILTY: Since its, an online voting system, it is portable i.e. voters can cast
their vote from any place.
• SUPPORTABILITY: The “Electronic Voting System” software shall have a clear and
easily maintainable interface for managing election specific updates
5. Analysis Models
5.1 Use-Case Diagram
5.2 Class Diagram

6. Implementation Screenshots/ Result


SOURCE CODE:

DAO (Data Access Object) class:


package myproject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DAO {


private Connection con;

public DAO() {
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3305/polling_system", "root", "root");
System.out.println("connected");

} catch (SQLException ex) {


Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("loaded");
} catch (ClassNotFoundException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

public void insertVoter(String fname,String lname,String gender,String pno,String prn,String password) throws VoteException
{
try {
int id = 0;
Statement st = con.createStatement();
String q= "SELECT * FROM registration ORDER BY id DESC LIMIT 1";
ResultSet rs = st.executeQuery(q);
if(rs.next()) {
id = rs.getInt("id");
id++;
}
String query = "INSERT INTO registration VALUES(?,?,?,?,?,?,?)";
PreparedStatement ps1 = con.prepareStatement(query);
ps1.setInt(1, id);
ps1.setString(2, fname);
ps1.setString(3, lname);
ps1.setString(4, gender);
ps1.setString(5, pno);
ps1.setString(6, prn);
ps1.setString(7, password);

ps1.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
throw new VoteException();
} finally {
try {

con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public void selectUser(String prn,String password) throws VoteException {


try {

String query = "SELECT * FROM registration WHERE prn=? AND password=?";


PreparedStatement ps1 = con.prepareStatement(query);
Statement st = con.createStatement();
ps1.setString(1, prn);
ps1.setString(2, password);
ResultSet rs = ps1.executeQuery();
if(!rs.next()) {
throw new VoteException();
}
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
throw new VoteException();
} finally {
try {

con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public int selectAdmin(String prn,String password) throws VoteException {


try {
String query = "SELECT * FROM admin WHERE username=? AND password=?";
PreparedStatement ps1 = con.prepareStatement(query);
ps1.setString(1, prn);
ps1.setString(2, password);
ResultSet rs = ps1.executeQuery();
if(!rs.next()) {
return 0;
}
return 1;
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
return 0;
} finally {
try {
con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void insertVote(int vote) throws VoteException {

try {

String query = "INSERT INTO votes(optid) VALUES(?)";


PreparedStatement ps1 = con.prepareStatement(query);
//String query1 = "SELECT * FROM registration WHERE id=?";
//PreparedStatement ps2 = con.prepareStatement(query1);
ps1.setInt(1,vote);
//ps1.setString(2,query1);
ps1.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
throw new VoteException();
} finally {
try {

con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public int getVotes(int opt_id)
{
try{
String query = "SELECT COUNT(*) FROM VOTES WHERE optid="+opt_id;
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
int nvotes= rs.getInt(1);
return nvotes;
}
catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
return 0;
//throw new VoteException();
} finally {
try {

con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}

public String getWinner()


{
try{
String query = "SELECT * FROM votes GROUP BY optid ORDER BY count(*) DESC LIMIT 1";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
int woptid= rs.getInt(1);
String query1 = "SELECT * FROM options WHERE optid = " + woptid;
ResultSet rs1 = st.executeQuery(query1);
rs1.next();

return rs1.getString("optname");

}
catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
return null;
//throw new VoteException();
} finally {
try {

con.close();
} catch (SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

Myproject class(main class):


package myproject;

public class Myproject {

public static void main(String[] args) {


java.awt.EventQueue.invokeLater(Myproject::run);
}

private static void run() {


new WelcomeFrame().setVisible(true);
}
}

WelcomeFrame class:
package myproject;

import javax.swing.JOptionPane;

public class WelcomeFrame extends javax.swing.JFrame {

// Creates new form java


public WelcomeFrame() {
initComponents();
}

private void initComponents() {

username_label = new javax.swing.JLabel();


username_textfield = new javax.swing.JTextField();
password_label = new javax.swing.JLabel();
submit_button = new javax.swing.JButton();
jPasswordField1 = new javax.swing.JPasswordField();
signin_button = new javax.swing.JButton();
signin_label = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

username_label.setText("Username");

password_label.setText("Password");

submit_button.setText("Submit");
submit_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submit_buttonActionPerformed(evt);
}
});

signin_button.setText("Sign Up");
signin_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
signin_buttonActionPerformed(evt);
}
});

signin_label.setText("New Registration");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(submit_button)
.addGap(150, 150, 150))
.addGroup(layout.createSequentialGroup()
.addGap(66, 66, 66)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(username_label)
.addComponent(password_label))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
.addComponent(username_textfield))
.addGap(141, 141, 141))
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(signin_button))
.addComponent(signin_label))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(username_label)
.addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(password_label)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addComponent(submit_button)
.addGap(20, 20, 20)
.addComponent(signin_label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(signin_button)
.addContainerGap(43, Short.MAX_VALUE))
);

pack();
}//initComponents

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


//event_submit_buttonActionPerformed
String username = username_textfield.getText();
String password = new String(this.jPasswordField1.getPassword());
if(new RegisterService().validateVoter(username, password))

if(new RegisterService().validateAdmin(username, password))


new AminFrame().setVisible(true);
else
new VoteFrame().setVisible(true);
else
JOptionPane.showMessageDialog(this, "Inavalid username or password");
}//event_submit_buttonActionPerformed
private void signin_buttonActionPerformed(java.awt.event.ActionEvent evt) {
//event_signin_buttonActionPerformed
new RegisterationFrame().setVisible(true);
}
//event_signin_buttonActionPerformed

private javax.swing.JPasswordField jPasswordField1;


private javax.swing.JLabel password_label;
private javax.swing.JButton signin_button;
private javax.swing.JLabel signin_label;
private javax.swing.JButton submit_button;
private javax.swing.JLabel username_label;
private javax.swing.JTextField username_textfield;
// End of variables declaration
}

Admin class (AminFrame) :


package myproject;

import javax.swing.*;

public class AminFrame extends javax.swing.JFrame {

//Creates new form java


public AminFrame() {
initComponents();
}
private void initComponents() {

JLabel vote_label = new JLabel();


buttonGroup1 = new javax.swing.ButtonGroup();
yes_button = new javax.swing.JRadioButton();
no_button = new javax.swing.JRadioButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

vote_label.setText("---ADMIN---");

buttonGroup1.add(yes_button);
yes_button.setText("Cast your vote now");
yes_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
yes_buttonActionPerformed(evt);
}
});

buttonGroup1.add(no_button);
no_button.setText("Check Result");
no_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
no_buttonActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(vote_label)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(100, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(yes_button)
.addComponent(no_button))
.addGap(161, 161, 161))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(vote_label)
.addGap(96, 96, 96)
.addComponent(yes_button)
.addGap(34, 34, 34)
.addComponent(no_button)
.addContainerGap(120, Short.MAX_VALUE))
);

pack();
}

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


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VoteFrame().setVisible(true);
}
});

}//event_yes_buttonActionPerformed

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


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Result().setVisible(true);
}
});
}//event_no_buttonActionPerformed

public static void main(String args[]) {


try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

//Create and display the form


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AminFrame().setVisible(true);
}
});
}

// Variables declaration
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JRadioButton no_button;
private javax.swing.JRadioButton yes_button;
}

RegistrationFrame class:
package myproject;
import javax.swing.JOptionPane;

public class RegisterationFrame extends javax.swing.JFrame {

//Creates new form java


public RegisterationFrame() {
initComponents();
}

private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();


jTree1 = new javax.swing.JTree();
jSpinner1 = new javax.swing.JSpinner();
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
Fname_label = new javax.swing.JLabel();
Fname_textfield = new javax.swing.JTextField();
Lname_label = new javax.swing.JLabel();
Lname_textfield = new javax.swing.JTextField();
Gender_label = new javax.swing.JLabel();
Male_button = new javax.swing.JRadioButton();
Female_button = new javax.swing.JRadioButton();
other_button = new javax.swing.JRadioButton();
Pno_label = new javax.swing.JLabel();
Pno_textfield = new javax.swing.JTextField();
prn_label = new javax.swing.JLabel();
prn_textfield = new javax.swing.JTextField();
regsubmit_button = new javax.swing.JButton();
username_label = new javax.swing.JLabel();
username_textfield = new javax.swing.JTextField();
password_label = new javax.swing.JLabel();
cpassword_label = new javax.swing.JLabel();
cpassword_textfield = new javax.swing.JTextField();
password_textfield = new javax.swing.JPasswordField();

jScrollPane1.setViewportView(jTree1);

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

Fname_label.setText("First Name");

Fname_textfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Fname_textfieldActionPerformed(evt);
}
});

Lname_label.setText("Last Name");

Gender_label.setText("Gender");

buttonGroup1.add(Male_button);
Male_button.setSelected(true);
Male_button.setText("Male");
Male_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Male_buttonActionPerformed(evt);
}
});
buttonGroup1.add(Female_button);
Female_button.setText("Female");

buttonGroup1.add(other_button);
other_button.setText("other");

Pno_label.setText("Phone No.");

Pno_textfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Pno_textfieldActionPerformed(evt);
}
});

prn_label.setText("PRN");

prn_textfield.addInputMethodListener(new java.awt.event.InputMethodListener() {
public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
}
public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
prn_textfieldInputMethodTextChanged(evt);
}
});
prn_textfield.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
prn_textfieldKeyReleased(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
prn_textfieldKeyTyped(evt);
}
});

regsubmit_button.setText("Submit");
regsubmit_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
regsubmit_buttonActionPerformed(evt);
}
});

username_label.setText("Username");

username_textfield.setEditable(false);

password_label.setText("Password");

cpassword_label.setText("Confirm password");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Lname_label)
.addComponent(Gender_label)
.addComponent(Pno_label)
.addComponent(prn_label)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(password_label)
.addComponent(username_label)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Pno_textfield, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
.addComponent(prn_textfield, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
.addComponent(username_textfield)
.addComponent(password_textfield))
.addGroup(layout.createSequentialGroup()
.addComponent(Male_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Female_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(other_button))
.addComponent(Lname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 102,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(99, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Fname_label)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Fname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(cpassword_label)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(regsubmit_button)
.addComponent(cpassword_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 135,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Fname_label)
.addComponent(Fname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Lname_label)
.addComponent(Lname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Gender_label)
.addComponent(Male_button)
.addComponent(Female_button)
.addComponent(other_button))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Pno_label, javax.swing.GroupLayout.PREFERRED_SIZE, 16,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Pno_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(prn_label)
.addComponent(prn_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(username_label)
.addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(password_label)
.addComponent(password_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cpassword_label)
.addComponent(cpassword_textfield, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addComponent(regsubmit_button)
.addContainerGap(252, Short.MAX_VALUE))
);

pack();
}

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


}//event_Fname_textfieldActionPerformed

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


//event_regsubmit_buttonActionPerformed
String fname=Fname_textfield.getText();
String lname=Lname_textfield.getText();

String pno= Pno_textfield.getText();


String prn =prn_textfield.getText();

String password =new String(password_textfield.getPassword());


String cpassword =cpassword_textfield.getText();

String gender="male";

if(Female_button.isSelected())
gender="female";
else if(other_button.isSelected())
gender="other";

boolean added=new RegisterService().addVoter(fname, lname, gender, pno, prn, password);

if(true)
{
Fname_textfield.setText("");
Lname_textfield.setText("");

Pno_textfield.setText("");
prn_textfield.setText("");

username_textfield.setText("");
password_textfield.setText("");

if(password.equals(cpassword)==false)
JOptionPane.showMessageDialog(this, "Add correct password");

else{
JOptionPane.showMessageDialog(this, "Added successfully!");
dispose();

}
}

else{
JOptionPane.showMessageDialog(this,"Something went wrong");
}

}//event_regsubmit_buttonActionPerformed

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


}//event_Male_buttonActionPerformed

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


}//event_Pno_textfieldActionPerformed

private void prn_textfieldInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {


username_textfield.setText(prn_textfield.getText());
}//event_prn_textfieldInputMethodTextChanged

private void prn_textfieldKeyTyped(java.awt.event.KeyEvent evt) {


}//event_prn_textfieldKeyTyped

private void prn_textfieldKeyReleased(java.awt.event.KeyEvent evt) {


username_textfield.setText(prn_textfield.getText());
}//event_prn_textfieldKeyReleased

public static void main(String args[]) {


try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break; }
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

//Create and display the form


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RegisterationFrame().setVisible(true);
}
});
}

// Variables declaration
private javax.swing.JRadioButton Female_button;
private javax.swing.JLabel Fname_label;
private javax.swing.JTextField Fname_textfield;
private javax.swing.JLabel Gender_label;
private javax.swing.JLabel Lname_label;
private javax.swing.JTextField Lname_textfield;
private javax.swing.JRadioButton Male_button;
private javax.swing.JLabel Pno_label;
private javax.swing.JTextField Pno_textfield;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JLabel cpassword_label;
private javax.swing.JTextField cpassword_textfield;
private javax.swing.JLabel prn_label;
private javax.swing.JTextField prn_textfield;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JTree jTree1;
private javax.swing.JRadioButton other_button;
private javax.swing.JLabel password_label;
private javax.swing.JPasswordField password_textfield;
private javax.swing.JButton regsubmit_button;
private javax.swing.JLabel username_label;
private javax.swing.JTextField username_textfield;
}

RegisterService class:
package myproject;

public class RegisterService {

public boolean addVoter(String fname,String lname,String gender,String pno,String prn,String password)


{
fname=fname.toLowerCase();
lname=lname.toLowerCase();
try{
new DAO().insertVoter(fname, lname, gender,pno, prn, password);
return true;
}
catch (VoteException ex) {
return false;
}
}

public boolean validateAdmin(String username, String password) {


try {
username = username.toLowerCase();
int a=new DAO().selectAdmin(username, password);
if(a==1)
return true;
else
return false;
}
catch (VoteException ex) {
return false;
}
}

public boolean validateVoter(String username, String password) {


try {
username = username.toLowerCase();
new DAO().selectUser(username, password);
return true;
}
catch (VoteException ex) {
return false;
}
}
}

VoteFrame class:
package myproject;

public class VoteFrame extends javax.swing.JFrame {

// Creates new form java


public VoteFrame() {
initComponents();
}

@SuppressWarnings("unchecked")
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
vote_label = new javax.swing.JLabel();
vote1_button = new javax.swing.JRadioButton();
vote2_button = new javax.swing.JRadioButton();
vote3_button = new javax.swing.JRadioButton();
vote4_button = new javax.swing.JRadioButton();
vote5_button = new javax.swing.JRadioButton();
vote6_button = new javax.swing.JRadioButton();
submitvote_button = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

vote_label.setText("Choose from the given Options: ");

buttonGroup1.add(vote1_button);
vote1_button.setText("Option 1");
vote1_button.setName("1");
vote1_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote1_buttonActionPerformed(evt);
}
});

buttonGroup1.add(vote2_button);
vote2_button.setText("Option 2");
vote2_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote2_buttonActionPerformed(evt);
}
});

buttonGroup1.add(vote3_button);
vote3_button.setText("Option 3");
vote3_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote3_buttonActionPerformed(evt);
}
});

buttonGroup1.add(vote4_button);
vote4_button.setText("Option 4");
vote4_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote4_buttonActionPerformed(evt);
}
});

buttonGroup1.add(vote5_button);
vote5_button.setText("Option 5");
vote5_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote5_buttonActionPerformed(evt);
}
});

buttonGroup1.add(vote6_button);
vote6_button.setText("None of the above");
vote6_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
vote6_buttonActionPerformed(evt);
}
});

submitvote_button.setText("Submit");
submitvote_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitvote_buttonActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(vote_label)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(74, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(vote6_button, javax.swing.GroupLayout.PREFERRED_SIZE, 150,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(vote5_button, javax.swing.GroupLayout.PREFERRED_SIZE, 173,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(vote4_button, javax.swing.GroupLayout.PREFERRED_SIZE, 251,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(vote3_button, javax.swing.GroupLayout.PREFERRED_SIZE, 119,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(vote2_button, javax.swing.GroupLayout.PREFERRED_SIZE, 193,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(submitvote_button)
.addGap(147, 147, 147))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(vote1_button, javax.swing.GroupLayout.PREFERRED_SIZE, 211,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48)))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(vote_label)
.addGap(21, 21, 21)
.addComponent(vote1_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(vote2_button, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(vote3_button, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(vote4_button, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(vote5_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(vote6_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
.addComponent(submitvote_button)
.addContainerGap())
);

pack();
}

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


}//event_vote5_buttonActionPerformed

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


}//event_vote6_buttonActionPerformed

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


}//event_vote1_buttonActionPerformed

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


}//event_vote2_buttonActionPerformed

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


}//event_vote3_buttonActionPerformed

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


}//event_vote4_buttonActionPerformed

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

int vote;
// If condition to check if jRadioButton2 is selected.
if (vote1_button.isSelected()) {

vote = 1;
}

else if (vote2_button.isSelected()) {

vote = 2;
}
else if(vote3_button.isSelected()){

vote = 3;
}
else if(vote4_button.isSelected()){

vote = 4;
}
else if(vote5_button.isSelected()){

vote = 5;
}

else
{
vote=6;
}

new VoteService().addVote(vote);

// MessageDialog to show information selected radion buttons.


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ExitFrame().setVisible(true);
}
});

}//event_submitvote_buttonActionPerformed

// Variables declaration
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton submitvote_button;
private javax.swing.JRadioButton vote1_button;
private javax.swing.JRadioButton vote2_button;
private javax.swing.JRadioButton vote3_button;
private javax.swing.JRadioButton vote4_button;
private javax.swing.JRadioButton vote5_button;
private javax.swing.JRadioButton vote6_button;
private javax.swing.JLabel vote_label;
}

VoteService class:
package myproject;

import java.util.logging.Level;
import java.util.logging.Logger;

public class VoteService {

public void addVote(int vote)


{
try {
new DAO().insertVote(vote);
}
catch (VoteException ex) {
Logger.getLogger(VoteService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

VoteException class;
package myproject;
public class VoteException extends Exception {

public VoteException() {
}

public VoteException(String message)


{
super(message);
}
}

ResultService class:
package myproject;
public class ResultService {

public int retVotes(int opt_id)


{
int novotes = new DAO().getVotes(opt_id);
return novotes;
}
public String retWinner(){
String w_opt=new DAO().getWinner();
return w_opt;
}
}

Result class:
package myproject;

public class Result extends javax.swing.JFrame {


public Result() {
initComponents();
}
private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("RESULT");

jLabel2.setText("PARTY NAME");

jLabel3.setText("NO. OF VOTES");

jLabel4.setText("Option 1");

jLabel5.setText("Option 2");

jLabel6.setText("Option 3");

jLabel7.setText("Option 4");

jLabel8.setText("Option 5");

jLabel9.setText("NOTA");

jLabel10.setText("STATISTICS");

jLabel11.setText("Maximum Votes: ");

jButton1.setText("EXIT");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
int nov1= new ResultService().retVotes(1);
int nov2= new ResultService().retVotes(2);
int nov3= new ResultService().retVotes(3);
int nov4= new ResultService().retVotes(4);
int nov5= new ResultService().retVotes(5);
int nov6= new ResultService().retVotes(6);
String win= new ResultService().retWinner();

jLabel12.setText("\t"+String.valueOf(nov1));
jLabel13.setText("\t"+String.valueOf(nov2));
jLabel14.setText("\t"+String.valueOf(nov3));
jLabel15.setText("\t"+String.valueOf(nov4));
jLabel16.setText("\t"+String.valueOf(nov5));
jLabel17.setText("\t"+String.valueOf(nov6));
jLabel18.setText((win));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 48,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))))
.addContainerGap(76, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 125,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 79,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(118, 118, 118)
.addComponent(jLabel10))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(81, 81, 81)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(131, 131, 131)
.addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 138,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 108,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(148, 148, 148)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 67,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3)
.addGap(62, 62, 62))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1)
.addGap(45, 45, 45)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jLabel12))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jLabel13))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jLabel14))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 16,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel15))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jLabel16))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jLabel17))
.addGap(47, 47, 47)
.addComponent(jLabel10)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(jLabel18))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(45, 45, 45))
);

pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WelcomeFrame().setVisible(true);
}
});
}//event_jButton1ActionPerformed

public static void main(String args[]) {


try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

//Create and display the form


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Result().setVisible(true);
}
});
}
// Variables declaration
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
}

ExitFrame class:
package myproject;

public class ExitFrame extends javax.swing.JFrame {

public ExitFrame() {

initComponents();
}
private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText(" !!! Voting done successfully !!!");

jButton1.setText("Exit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 217,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(97, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(169, 169, 169))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(60, 60, 60)
.addComponent(jLabel1)
.addGap(56, 56, 56)
.addComponent(jButton1)
.addContainerGap(143, Short.MAX_VALUE))
);

pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
java.eawt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WelcomeFrame().setVisible(true);
}
});

}//event_jButton1ActionPerformed

public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

//Create and display the form


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ExitFrame().setVisible(true);
}
});
}

// Variables declaration
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
}
APPLICATION OUTPUTS:
Welcome page/
sign in page:

Registration Page:
Registering new
user
successfully!
Login in to Vote!

Voting Process!
Voting Successful:

Admin Login:
Admin “Voting”:

Voting Process for admin:


Voting Successful for Admin:

Admin “Check Result”:


Result page: (after 2 votes)

Logging in with incorrect password:


Result page (before any votes):

Unmatched passwords in Registration form:


7. Project Outcomes
We have successfully created a Java application of a working and functional
Polling system project in which :
1. There’s a Registration page for users, a Login Page for user and admin login,
an Error page if the username/password is incorrect, a Voting page for the
users, an Admin page in which the admin can either vote or check the
results. At last, there’s a Results page which will display the final result (max
no. of votes).
2. All the votes are being stored in a table in database and are being calculated
accurately to display the option with maximum number of votes.
3. Implementation of Java Database Connectivity has been done efficiently. All
the data is stored in a SQL database which can be accessed any time.
4. This project was based on GUI i.e., Graphical User Interface and we have
successfully implemented it.

8. Conclusion and Future Scope:


“College Polling System” application satisfies all the needs of the administrator and
voter. This application successfully provides accurate votes given by users without
any loss of time. It provides an easy way for users to choose an option.

Future Scope: Currently, our project is a Java application which will run on a single
device only, but in future it can be improved by using java servlets and thus making
it a web based application.
The coding style can be improved and the code can be made more efficient. Images
and other graphics could be used in GUI for a better display of outputs.
Future development focused to design a system which can be easy to use and will
provide security and privacy of votes on acceptable level by proper authentication
and processing section.

To conclude, Polling Systems have many advantages over the traditional voting
system. Some of these advantages are less cost, faster generation results, easy
accessibility, accuracy, and low risk of human and mechanical errors. It is easy to
use and it is less time consuming. It is very easy to debug.
Submitted by:
Somaay Maheshwari - 19070122170
Vidhi Khatwani - 19070122194

You might also like