├── Java Classes ├── AminFrame.java ├── DAO.java ├── ExitFrame.java ├── Myproject.java ├── RegisterService.java ├── RegisterationFrame.java ├── Result.java ├── ResultService.java ├── VoteException.java ├── VoteFrame.java ├── VoteService.java └── WelcomeFrame.java ├── Polling System - Final Report.pdf └── README.md /Java Classes/AminFrame.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | import javax.swing.*; 4 | 5 | public class AminFrame extends javax.swing.JFrame { 6 | 7 | //Creates new form java 8 | public AminFrame() { 9 | initComponents(); 10 | } 11 | private void initComponents() { 12 | 13 | JLabel vote_label = new JLabel(); 14 | buttonGroup1 = new javax.swing.ButtonGroup(); 15 | yes_button = new javax.swing.JRadioButton(); 16 | no_button = new javax.swing.JRadioButton(); 17 | 18 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 19 | 20 | vote_label.setText("---ADMIN---"); 21 | 22 | buttonGroup1.add(yes_button); 23 | yes_button.setText("Cast your vote now"); 24 | yes_button.addActionListener(new java.awt.event.ActionListener() { 25 | public void actionPerformed(java.awt.event.ActionEvent evt) { 26 | yes_buttonActionPerformed(evt); 27 | } 28 | }); 29 | 30 | buttonGroup1.add(no_button); 31 | no_button.setText("Check Result"); 32 | no_button.addActionListener(new java.awt.event.ActionListener() { 33 | public void actionPerformed(java.awt.event.ActionEvent evt) { 34 | no_buttonActionPerformed(evt); 35 | } 36 | }); 37 | 38 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 39 | getContentPane().setLayout(layout); 40 | layout.setHorizontalGroup( 41 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 42 | .addGroup(layout.createSequentialGroup() 43 | .addGap(120, 120, 120) 44 | .addComponent(vote_label) 45 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 46 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 47 | .addContainerGap(100, Short.MAX_VALUE) 48 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 49 | .addComponent(yes_button) 50 | .addComponent(no_button)) 51 | .addGap(161, 161, 161)) 52 | ); 53 | layout.setVerticalGroup( 54 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 55 | .addGroup(layout.createSequentialGroup() 56 | .addGap(21, 21, 21) 57 | .addComponent(vote_label) 58 | .addGap(96, 96, 96) 59 | .addComponent(yes_button) 60 | .addGap(34, 34, 34) 61 | .addComponent(no_button) 62 | .addContainerGap(120, Short.MAX_VALUE)) 63 | ); 64 | 65 | pack(); 66 | } 67 | 68 | private void yes_buttonActionPerformed(java.awt.event.ActionEvent evt) { //opening voting options for admin 69 | java.awt.EventQueue.invokeLater(new Runnable() { 70 | public void run() { 71 | new VoteFrame().setVisible(true); 72 | } 73 | }); 74 | 75 | }//event_yes_buttonActionPerformed 76 | 77 | private void no_buttonActionPerformed(java.awt.event.ActionEvent evt) { //opeing result 78 | java.awt.EventQueue.invokeLater(new Runnable() { 79 | public void run() { 80 | new Result().setVisible(true); 81 | } 82 | }); 83 | }//event_no_buttonActionPerformed 84 | 85 | 86 | public static void main(String args[]) { 87 | try { 88 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 89 | if ("Nimbus".equals(info.getName())) { 90 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 91 | break; 92 | } 93 | } 94 | } catch (ClassNotFoundException ex) { 95 | java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 96 | } catch (InstantiationException ex) { 97 | java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 98 | } catch (IllegalAccessException ex) { 99 | java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 100 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 101 | java.util.logging.Logger.getLogger(AminFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 102 | } 103 | 104 | //Create and display the form 105 | java.awt.EventQueue.invokeLater(new Runnable() { 106 | public void run() { 107 | new AminFrame().setVisible(true); 108 | } 109 | }); 110 | } 111 | 112 | // Variables declaration 113 | private javax.swing.ButtonGroup buttonGroup1; 114 | private javax.swing.JRadioButton no_button; 115 | private javax.swing.JRadioButton yes_button; 116 | } 117 | -------------------------------------------------------------------------------- /Java Classes/DAO.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | //connection w database 13 | public class DAO { 14 | private Connection con; //connection object 15 | 16 | public DAO() { 17 | try { 18 | con = DriverManager.getConnection("jdbc:mysql://localhost:3305/polling_system", "root", "root"); 19 | System.out.println("connected"); 20 | 21 | } catch (SQLException ex) { 22 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); // throws nullPointerException 23 | } 24 | } 25 | 26 | static { 27 | try { 28 | Class.forName("com.mysql.cj.jdbc.Driver"); 29 | System.out.println("loaded"); 30 | } catch (ClassNotFoundException ex) { 31 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 32 | } 33 | } 34 | 35 | public void insertVoter(String fname,String lname,String gender,String pno,String prn,String password) throws VoteException { 36 | try { //registerService 37 | int id = 0; 38 | Statement st = con.createStatement(); 39 | String q= "SELECT * FROM registration ORDER BY id DESC LIMIT 1"; //retrieving id of last voter 40 | ResultSet rs = st.executeQuery(q); 41 | if(rs.next()) { 42 | id = rs.getInt("id"); 43 | id++; 44 | } 45 | String query = "INSERT INTO registration VALUES(?,?,?,?,?,?,?)"; // inserting details of new voter in database 46 | PreparedStatement ps1 = con.prepareStatement(query); 47 | ps1.setInt(1, id); 48 | ps1.setString(2, fname); 49 | ps1.setString(3, lname); 50 | ps1.setString(4, gender); 51 | ps1.setString(5, pno); 52 | ps1.setString(6, prn); 53 | ps1.setString(7, password); 54 | 55 | ps1.executeUpdate(); 56 | 57 | } catch (SQLException ex) { 58 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 59 | throw new VoteException(); 60 | } 61 | finally { 62 | try { 63 | con.close(); 64 | } catch (SQLException ex) { 65 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 66 | } 67 | } 68 | } 69 | 70 | public void selectUser(String prn,String password) throws VoteException { //RegisterService class 71 | try { //searching login details according to user input 72 | 73 | String query = "SELECT * FROM registration WHERE prn=? AND password=?"; 74 | PreparedStatement ps1 = con.prepareStatement(query); 75 | Statement st = con.createStatement(); 76 | ps1.setString(1, prn); 77 | ps1.setString(2, password); 78 | ResultSet rs = ps1.executeQuery(); 79 | if(!rs.next()) { //if record not present 80 | throw new VoteException(); 81 | } 82 | } catch (SQLException ex) { 83 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 84 | throw new VoteException(); 85 | } finally { 86 | try { 87 | 88 | con.close(); 89 | } catch (SQLException ex) { 90 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 91 | } 92 | } 93 | } 94 | 95 | public int selectAdmin(String prn,String password) throws VoteException { 96 | try { //check id password of admin in admin table 97 | String query = "SELECT * FROM admin WHERE username=? AND password=?"; 98 | PreparedStatement ps1 = con.prepareStatement(query); 99 | ps1.setString(1, prn); 100 | ps1.setString(2, password); 101 | ResultSet rs = ps1.executeQuery(); 102 | if(!rs.next()) { // if admin not found 103 | return 0; 104 | } 105 | return 1; 106 | } catch (SQLException ex) { 107 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 108 | return 0; 109 | } finally { 110 | try { 111 | con.close(); 112 | } catch (SQLException ex) { 113 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 114 | } 115 | } 116 | } 117 | public void insertVote(int vote) throws VoteException { //VoteService 118 | try { // inserting votes in vote table 119 | 120 | String query = "INSERT INTO votes(optid) VALUES(?)"; 121 | PreparedStatement ps1 = con.prepareStatement(query); 122 | //String query1 = "SELECT * FROM registration WHERE id=?"; 123 | //PreparedStatement ps2 = con.prepareStatement(query1); 124 | ps1.setInt(1,vote); 125 | //ps1.setString(2,query1); 126 | ps1.executeUpdate(); 127 | } catch (SQLException ex) { 128 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 129 | throw new VoteException(); 130 | } finally { 131 | try { 132 | 133 | con.close(); 134 | } catch (SQLException ex) { 135 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 136 | } 137 | } 138 | } 139 | public int getVotes(int opt_id) //ResultService class 140 | { 141 | try{ 142 | String query = "SELECT COUNT(*) FROM VOTES WHERE optid="+opt_id; //adding the votes for each option 143 | Statement st = con.createStatement(); 144 | ResultSet rs = st.executeQuery(query); 145 | rs.next(); 146 | int nvotes= rs.getInt(1); 147 | return nvotes; 148 | } 149 | catch (SQLException ex) { 150 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 151 | return 0; 152 | //throw new VoteException(); 153 | } finally { 154 | try { 155 | con.close(); 156 | } catch (SQLException ex) { 157 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 158 | } 159 | } 160 | 161 | } 162 | 163 | public String getWinner() //ResultService 164 | { 165 | try{ 166 | String query = "SELECT * FROM votes GROUP BY optid ORDER BY count(*) DESC LIMIT 1"; //getting id with max votes 167 | Statement st = con.createStatement(); 168 | ResultSet rs = st.executeQuery(query); 169 | rs.next(); 170 | int woptid= rs.getInt(1); 171 | String query1 = "SELECT * FROM options WHERE optid = " + woptid; //retrieving the option name with max votes 172 | ResultSet rs1 = st.executeQuery(query1); 173 | rs1.next(); 174 | 175 | return rs1.getString("optname"); 176 | 177 | } 178 | catch (SQLException ex) { 179 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 180 | return null; 181 | //throw new VoteException(); 182 | } finally { 183 | try { 184 | 185 | con.close(); 186 | } catch (SQLException ex) { 187 | Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); 188 | } 189 | } 190 | 191 | } 192 | } 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /Java Classes/ExitFrame.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class ExitFrame extends javax.swing.JFrame { 4 | 5 | public ExitFrame() { 6 | 7 | initComponents(); 8 | } 9 | 10 | private void initComponents() { 11 | 12 | jLabel1 = new javax.swing.JLabel(); 13 | jButton1 = new javax.swing.JButton(); 14 | 15 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 16 | 17 | jLabel1.setText(" Your vote was succesfully recorded!"); 18 | 19 | jButton1.setText("Exit"); 20 | jButton1.addActionListener(new java.awt.event.ActionListener() { 21 | public void actionPerformed(java.awt.event.ActionEvent evt) { 22 | jButton1ActionPerformed(evt); 23 | } 24 | }); 25 | 26 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 27 | getContentPane().setLayout(layout); 28 | layout.setHorizontalGroup( 29 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 30 | .addGroup(layout.createSequentialGroup() 31 | .addGap(86, 86, 86) 32 | .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE) 33 | .addContainerGap(97, Short.MAX_VALUE)) 34 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 35 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 36 | .addComponent(jButton1) 37 | .addGap(169, 169, 169)) 38 | ); 39 | layout.setVerticalGroup( 40 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 41 | .addGroup(layout.createSequentialGroup() 42 | .addGap(60, 60, 60) 43 | .addComponent(jLabel1) 44 | .addGap(56, 56, 56) 45 | .addComponent(jButton1) 46 | .addContainerGap(143, Short.MAX_VALUE)) 47 | ); 48 | 49 | pack(); 50 | } 51 | 52 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 53 | java.awt.EventQueue.invokeLater(new Runnable() { 54 | public void run() { 55 | new WelcomeFrame().setVisible(true); 56 | } 57 | }); 58 | 59 | }//event_jButton1ActionPerformed 60 | 61 | public static void main(String args[]) { 62 | 63 | try { 64 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 65 | if ("Nimbus".equals(info.getName())) { 66 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 67 | break; 68 | } 69 | } 70 | } catch (ClassNotFoundException ex) { 71 | java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 72 | } catch (InstantiationException ex) { 73 | java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 74 | } catch (IllegalAccessException ex) { 75 | java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 76 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 77 | java.util.logging.Logger.getLogger(ExitFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 78 | } 79 | 80 | 81 | //Create and display the form 82 | java.awt.EventQueue.invokeLater(new Runnable() { 83 | public void run() { 84 | new ExitFrame().setVisible(true); 85 | } 86 | }); 87 | } 88 | 89 | // Variables declaration 90 | private javax.swing.JButton jButton1; 91 | private javax.swing.JLabel jLabel1; 92 | } 93 | -------------------------------------------------------------------------------- /Java Classes/Myproject.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class Myproject { 4 | 5 | public static void main(String[] args) { 6 | java.awt.EventQueue.invokeLater(Myproject::run); 7 | } 8 | private static void run() { 9 | new WelcomeFrame().setVisible(true); 10 | } 11 | } -------------------------------------------------------------------------------- /Java Classes/RegisterService.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class RegisterService { 4 | 5 | public boolean addVoter(String fname,String lname,String gender,String pno,String prn,String password) //RegistrationFrame 6 | { 7 | fname=fname.toLowerCase(); //getting parameters from Rframe and 8 | lname=lname.toLowerCase(); //using them in insertVoter function 9 | try{ 10 | new DAO().insertVoter(fname, lname, gender,pno, prn, password); // DAO called 11 | return true; 12 | } 13 | catch (VoteException ex) { 14 | return false; 15 | } 16 | } 17 | 18 | public boolean validateAdmin(String username, String password) { //getting parameters from Rframe and 19 | try { //using them to check whether the 20 | username = username.toLowerCase(); //details are correct or not 21 | int a=new DAO().selectAdmin(username, password); //selectAdmin function in DAO 22 | if(a==1) 23 | return true; 24 | else 25 | return false; 26 | } 27 | catch (VoteException ex) { 28 | return false; 29 | } 30 | } 31 | 32 | public boolean validateVoter(String username, String password) { //user log in details are checked 33 | try { 34 | username = username.toLowerCase(); 35 | new DAO().selectUser(username, password); //selectUser function in DAO 36 | return true; 37 | } 38 | catch (VoteException ex) { 39 | return false; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Java Classes/RegisterationFrame.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | import javax.swing.JOptionPane; 3 | 4 | public class RegisterationFrame extends javax.swing.JFrame { 5 | 6 | //Creates new form java 7 | public RegisterationFrame() { 8 | initComponents(); 9 | } 10 | 11 | private void initComponents() { 12 | 13 | jScrollPane1 = new javax.swing.JScrollPane(); 14 | jTree1 = new javax.swing.JTree(); 15 | jSpinner1 = new javax.swing.JSpinner(); 16 | buttonGroup1 = new javax.swing.ButtonGroup(); 17 | buttonGroup2 = new javax.swing.ButtonGroup(); 18 | Fname_label = new javax.swing.JLabel(); 19 | Fname_textfield = new javax.swing.JTextField(); 20 | Lname_label = new javax.swing.JLabel(); 21 | Lname_textfield = new javax.swing.JTextField(); 22 | Gender_label = new javax.swing.JLabel(); 23 | Male_button = new javax.swing.JRadioButton(); 24 | Female_button = new javax.swing.JRadioButton(); 25 | other_button = new javax.swing.JRadioButton(); 26 | Pno_label = new javax.swing.JLabel(); 27 | Pno_textfield = new javax.swing.JTextField(); 28 | prn_label = new javax.swing.JLabel(); 29 | prn_textfield = new javax.swing.JTextField(); 30 | regsubmit_button = new javax.swing.JButton(); 31 | username_label = new javax.swing.JLabel(); 32 | username_textfield = new javax.swing.JTextField(); 33 | password_label = new javax.swing.JLabel(); 34 | cpassword_label = new javax.swing.JLabel(); 35 | cpassword_textfield = new javax.swing.JTextField(); 36 | password_textfield = new javax.swing.JPasswordField(); 37 | 38 | jScrollPane1.setViewportView(jTree1); 39 | 40 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 41 | 42 | Fname_label.setText("First Name"); 43 | 44 | Fname_textfield.addActionListener(new java.awt.event.ActionListener() { 45 | public void actionPerformed(java.awt.event.ActionEvent evt) { 46 | Fname_textfieldActionPerformed(evt); 47 | } 48 | }); 49 | 50 | Lname_label.setText("Last Name"); 51 | 52 | Gender_label.setText("Gender"); 53 | 54 | buttonGroup1.add(Male_button); 55 | Male_button.setSelected(true); 56 | Male_button.setText("Male"); 57 | Male_button.addActionListener(new java.awt.event.ActionListener() { 58 | public void actionPerformed(java.awt.event.ActionEvent evt) { 59 | Male_buttonActionPerformed(evt); 60 | } 61 | }); 62 | 63 | buttonGroup1.add(Female_button); 64 | Female_button.setText("Female"); 65 | 66 | buttonGroup1.add(other_button); 67 | other_button.setText("other"); 68 | 69 | Pno_label.setText("Phone No."); 70 | 71 | Pno_textfield.addActionListener(new java.awt.event.ActionListener() { 72 | public void actionPerformed(java.awt.event.ActionEvent evt) { 73 | Pno_textfieldActionPerformed(evt); 74 | } 75 | }); 76 | 77 | prn_label.setText("PRN"); 78 | 79 | prn_textfield.addInputMethodListener(new java.awt.event.InputMethodListener() { 80 | public void caretPositionChanged(java.awt.event.InputMethodEvent evt) { 81 | } 82 | public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) { 83 | prn_textfieldInputMethodTextChanged(evt); 84 | } 85 | }); 86 | prn_textfield.addKeyListener(new java.awt.event.KeyAdapter() { 87 | public void keyReleased(java.awt.event.KeyEvent evt) { 88 | prn_textfieldKeyReleased(evt); 89 | } 90 | public void keyTyped(java.awt.event.KeyEvent evt) { 91 | prn_textfieldKeyTyped(evt); 92 | } 93 | }); 94 | 95 | regsubmit_button.setText("Submit"); 96 | regsubmit_button.addActionListener(new java.awt.event.ActionListener() { 97 | public void actionPerformed(java.awt.event.ActionEvent evt) { 98 | regsubmit_buttonActionPerformed(evt); 99 | } 100 | }); 101 | 102 | username_label.setText("Username"); 103 | 104 | username_textfield.setEditable(false); 105 | 106 | password_label.setText("Password"); 107 | 108 | cpassword_label.setText("Confirm password"); 109 | 110 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 111 | getContentPane().setLayout(layout); 112 | layout.setHorizontalGroup( 113 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 114 | .addGroup(layout.createSequentialGroup() 115 | .addGap(40, 40, 40) 116 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 117 | .addGroup(layout.createSequentialGroup() 118 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 119 | .addComponent(Lname_label) 120 | .addComponent(Gender_label) 121 | .addComponent(Pno_label) 122 | .addComponent(prn_label) 123 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 124 | .addComponent(password_label) 125 | .addComponent(username_label))) 126 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 127 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 128 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 129 | .addComponent(Pno_textfield, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE) 130 | .addComponent(prn_textfield, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE) 131 | .addComponent(username_textfield) 132 | .addComponent(password_textfield)) 133 | .addGroup(layout.createSequentialGroup() 134 | .addComponent(Male_button) 135 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 136 | .addComponent(Female_button) 137 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 138 | .addComponent(other_button)) 139 | .addComponent(Lname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)) 140 | .addContainerGap(99, Short.MAX_VALUE)) 141 | .addGroup(layout.createSequentialGroup() 142 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 143 | .addGroup(layout.createSequentialGroup() 144 | .addComponent(Fname_label) 145 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 146 | .addComponent(Fname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) 147 | .addGroup(layout.createSequentialGroup() 148 | .addComponent(cpassword_label) 149 | .addGap(18, 18, 18) 150 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 151 | .addComponent(regsubmit_button) 152 | .addComponent(cpassword_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))) 153 | .addGap(0, 0, Short.MAX_VALUE)))) 154 | ); 155 | layout.setVerticalGroup( 156 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 157 | .addGroup(layout.createSequentialGroup() 158 | .addGap(19, 19, 19) 159 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 160 | .addComponent(Fname_label) 161 | .addComponent(Fname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 162 | .addGap(18, 18, 18) 163 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 164 | .addComponent(Lname_label) 165 | .addComponent(Lname_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 166 | .addGap(24, 24, 24) 167 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 168 | .addComponent(Gender_label) 169 | .addComponent(Male_button) 170 | .addComponent(Female_button) 171 | .addComponent(other_button)) 172 | .addGap(18, 18, 18) 173 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 174 | .addComponent(Pno_label, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) 175 | .addComponent(Pno_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 176 | .addGap(25, 25, 25) 177 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 178 | .addComponent(prn_label) 179 | .addComponent(prn_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 180 | .addGap(24, 24, 24) 181 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 182 | .addComponent(username_label) 183 | .addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 184 | .addGap(28, 28, 28) 185 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 186 | .addComponent(password_label) 187 | .addComponent(password_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 188 | .addGap(25, 25, 25) 189 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 190 | .addComponent(cpassword_label) 191 | .addComponent(cpassword_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 192 | .addGap(40, 40, 40) 193 | .addComponent(regsubmit_button) 194 | .addContainerGap(252, Short.MAX_VALUE)) 195 | ); 196 | 197 | pack(); 198 | } 199 | 200 | private void Fname_textfieldActionPerformed(java.awt.event.ActionEvent evt) { 201 | }//event_Fname_textfieldActionPerformed 202 | 203 | private void regsubmit_buttonActionPerformed(java.awt.event.ActionEvent evt) { 204 | //event_regsubmit_buttonActionPerformed 205 | String fname=Fname_textfield.getText(); 206 | String lname=Lname_textfield.getText(); 207 | 208 | 209 | String pno= Pno_textfield.getText(); 210 | String prn =prn_textfield.getText(); 211 | 212 | 213 | String password =new String(password_textfield.getPassword()); 214 | String cpassword =cpassword_textfield.getText(); 215 | 216 | 217 | String gender="male"; 218 | 219 | if(Female_button.isSelected()) 220 | gender="female"; 221 | else if(other_button.isSelected()) 222 | gender="other"; 223 | 224 | boolean added=new RegisterService().addVoter(fname, lname, gender, pno, prn, password); //adding user inputs by addVoter 225 | //function in RegisterService class 226 | if(true) 227 | { 228 | Fname_textfield.setText(""); 229 | Lname_textfield.setText(""); 230 | 231 | Pno_textfield.setText(""); 232 | prn_textfield.setText(""); 233 | 234 | username_textfield.setText(""); 235 | password_textfield.setText(""); 236 | 237 | if(password.equals(cpassword)==false) //password do not match 238 | JOptionPane.showMessageDialog(this, "Add correct password"); 239 | 240 | else{ 241 | JOptionPane.showMessageDialog(this, "Added successfully!"); //successfully registered 242 | dispose(); 243 | 244 | } 245 | } 246 | 247 | else{ 248 | JOptionPane.showMessageDialog(this,"Something went wrong"); 249 | } //error handling 250 | 251 | }//event_regsubmit_buttonActionPerformed 252 | 253 | private void Male_buttonActionPerformed(java.awt.event.ActionEvent evt) { 254 | }//event_Male_buttonActionPerformed 255 | 256 | private void Pno_textfieldActionPerformed(java.awt.event.ActionEvent evt) { 257 | }//event_Pno_textfieldActionPerformed 258 | 259 | private void prn_textfieldInputMethodTextChanged(java.awt.event.InputMethodEvent evt) { 260 | username_textfield.setText(prn_textfield.getText()); 261 | }//event_prn_textfieldInputMethodTextChanged 262 | 263 | private void prn_textfieldKeyTyped(java.awt.event.KeyEvent evt) { 264 | }//event_prn_textfieldKeyTyped 265 | 266 | private void prn_textfieldKeyReleased(java.awt.event.KeyEvent evt) { 267 | username_textfield.setText(prn_textfield.getText()); 268 | }//event_prn_textfieldKeyReleased 269 | 270 | public static void main(String args[]) { 271 | try { 272 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 273 | if ("Nimbus".equals(info.getName())) { 274 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 275 | break; 276 | } 277 | } 278 | } catch (ClassNotFoundException ex) { 279 | java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 280 | } catch (InstantiationException ex) { 281 | java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 282 | } catch (IllegalAccessException ex) { 283 | java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 284 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 285 | java.util.logging.Logger.getLogger(RegisterationFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 286 | } 287 | 288 | //Create and display the form 289 | java.awt.EventQueue.invokeLater(new Runnable() { 290 | public void run() { 291 | new RegisterationFrame().setVisible(true); 292 | } 293 | }); 294 | } 295 | 296 | // Variables declaration 297 | private javax.swing.JRadioButton Female_button; 298 | private javax.swing.JLabel Fname_label; 299 | private javax.swing.JTextField Fname_textfield; 300 | private javax.swing.JLabel Gender_label; 301 | private javax.swing.JLabel Lname_label; 302 | private javax.swing.JTextField Lname_textfield; 303 | private javax.swing.JRadioButton Male_button; 304 | private javax.swing.JLabel Pno_label; 305 | private javax.swing.JTextField Pno_textfield; 306 | private javax.swing.ButtonGroup buttonGroup1; 307 | private javax.swing.ButtonGroup buttonGroup2; 308 | private javax.swing.JLabel cpassword_label; 309 | private javax.swing.JTextField cpassword_textfield; 310 | private javax.swing.JLabel prn_label; 311 | private javax.swing.JTextField prn_textfield; 312 | private javax.swing.JScrollPane jScrollPane1; 313 | private javax.swing.JSpinner jSpinner1; 314 | private javax.swing.JTree jTree1; 315 | private javax.swing.JRadioButton other_button; 316 | private javax.swing.JLabel password_label; 317 | private javax.swing.JPasswordField password_textfield; 318 | private javax.swing.JButton regsubmit_button; 319 | private javax.swing.JLabel username_label; 320 | private javax.swing.JTextField username_textfield; 321 | } 322 | -------------------------------------------------------------------------------- /Java Classes/Result.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class Result extends javax.swing.JFrame { 4 | 5 | public Result() { 6 | initComponents(); 7 | } 8 | private void initComponents() { 9 | 10 | jLabel1 = new javax.swing.JLabel(); 11 | jLabel2 = new javax.swing.JLabel(); 12 | jLabel3 = new javax.swing.JLabel(); 13 | jLabel4 = new javax.swing.JLabel(); 14 | jLabel5 = new javax.swing.JLabel(); 15 | jLabel6 = new javax.swing.JLabel(); 16 | jLabel7 = new javax.swing.JLabel(); 17 | jLabel8 = new javax.swing.JLabel(); 18 | jLabel9 = new javax.swing.JLabel(); 19 | jLabel10 = new javax.swing.JLabel(); 20 | jLabel11 = new javax.swing.JLabel(); 21 | jButton1 = new javax.swing.JButton(); 22 | jLabel12 = new javax.swing.JLabel(); 23 | jLabel13 = new javax.swing.JLabel(); 24 | jLabel14 = new javax.swing.JLabel(); 25 | jLabel15 = new javax.swing.JLabel(); 26 | jLabel16 = new javax.swing.JLabel(); 27 | jLabel17 = new javax.swing.JLabel(); 28 | jLabel18 = new javax.swing.JLabel(); 29 | 30 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 31 | 32 | jLabel1.setText("RESULT"); 33 | 34 | jLabel2.setText("PARTY NAME"); 35 | 36 | jLabel3.setText("NO. OF VOTES"); 37 | 38 | jLabel4.setText("Option 1"); 39 | 40 | jLabel5.setText("Option 2"); 41 | 42 | jLabel6.setText("Option 3"); 43 | 44 | jLabel7.setText("Option 4"); 45 | 46 | jLabel8.setText("Option 5"); 47 | 48 | jLabel9.setText("NOTA"); 49 | 50 | jLabel10.setText("STATISTICS"); 51 | 52 | jLabel11.setText("Maximum Votes: "); 53 | 54 | jButton1.setText("EXIT"); 55 | jButton1.addActionListener(new java.awt.event.ActionListener() { 56 | public void actionPerformed(java.awt.event.ActionEvent evt) { 57 | jButton1ActionPerformed(evt); 58 | } 59 | }); //retreiving no of votes for each 60 | int nov1= new ResultService().retVotes(1); //option id using retVotes function 61 | int nov2= new ResultService().retVotes(2); // in ResultService class 62 | int nov3= new ResultService().retVotes(3); 63 | int nov4= new ResultService().retVotes(4); 64 | int nov5= new ResultService().retVotes(5); 65 | int nov6= new ResultService().retVotes(6); 66 | String win= new ResultService().retWinner(); //getting the option with max votes 67 | //using retWinner function 68 | jLabel12.setText("\t"+String.valueOf(nov1)); 69 | jLabel13.setText("\t"+String.valueOf(nov2)); 70 | jLabel14.setText("\t"+String.valueOf(nov3)); 71 | jLabel15.setText("\t"+String.valueOf(nov4)); 72 | jLabel16.setText("\t"+String.valueOf(nov5)); 73 | jLabel17.setText("\t"+String.valueOf(nov6)); 74 | jLabel18.setText((win)); 75 | 76 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 77 | getContentPane().setLayout(layout); 78 | layout.setHorizontalGroup( 79 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 80 | .addGroup(layout.createSequentialGroup() 81 | .addGap(26, 26, 26) 82 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 83 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 84 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 85 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 86 | .addGroup(layout.createSequentialGroup() 87 | .addGap(270, 270, 270) 88 | .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) 89 | .addGroup(layout.createSequentialGroup() 90 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 91 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 92 | .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 93 | .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 94 | .addComponent(jLabel7)) 95 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 96 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 97 | .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 98 | .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 99 | .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 100 | .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 101 | .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)))) 102 | .addContainerGap(76, Short.MAX_VALUE)) 103 | .addGroup(layout.createSequentialGroup() 104 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 105 | .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) 106 | .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) 107 | .addGroup(layout.createSequentialGroup() 108 | .addGap(118, 118, 118) 109 | .addComponent(jLabel10)) 110 | .addGroup(layout.createSequentialGroup() 111 | .addComponent(jLabel11) 112 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 113 | .addGroup(layout.createSequentialGroup() 114 | .addGap(81, 81, 81) 115 | .addComponent(jButton1)) 116 | .addGroup(layout.createSequentialGroup() 117 | .addGap(131, 131, 131) 118 | .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))) 119 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 120 | .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))) 121 | .addGroup(layout.createSequentialGroup() 122 | .addGap(148, 148, 148) 123 | .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) 124 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 125 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 126 | .addGap(40, 40, 40) 127 | .addComponent(jLabel2) 128 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 129 | .addComponent(jLabel3) 130 | .addGap(62, 62, 62)) 131 | ); 132 | layout.setVerticalGroup( 133 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 134 | .addGroup(layout.createSequentialGroup() 135 | .addGap(21, 21, 21) 136 | .addComponent(jLabel1) 137 | .addGap(45, 45, 45) 138 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 139 | .addComponent(jLabel2) 140 | .addComponent(jLabel3)) 141 | .addGap(32, 32, 32) 142 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 143 | .addComponent(jLabel4) 144 | .addComponent(jLabel12)) 145 | .addGap(18, 18, 18) 146 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 147 | .addComponent(jLabel5) 148 | .addComponent(jLabel13)) 149 | .addGap(18, 18, 18) 150 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 151 | .addComponent(jLabel6) 152 | .addComponent(jLabel14)) 153 | .addGap(18, 18, 18) 154 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 155 | .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) 156 | .addComponent(jLabel15)) 157 | .addGap(18, 18, 18) 158 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 159 | .addComponent(jLabel8) 160 | .addComponent(jLabel16)) 161 | .addGap(18, 18, 18) 162 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 163 | .addComponent(jLabel9) 164 | .addComponent(jLabel17)) 165 | .addGap(47, 47, 47) 166 | .addComponent(jLabel10) 167 | .addGap(27, 27, 27) 168 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 169 | .addComponent(jLabel11) 170 | .addComponent(jLabel18)) 171 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE) 172 | .addComponent(jButton1) 173 | .addGap(45, 45, 45)) 174 | ); 175 | 176 | pack(); 177 | } 178 | 179 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 180 | java.awt.EventQueue.invokeLater(new Runnable() { 181 | public void run() { 182 | new WelcomeFrame().setVisible(true); //exit button leading to welcomeframe 183 | } // i.e. login page 184 | }); 185 | }//event_jButton1ActionPerformed 186 | 187 | public static void main(String args[]) { 188 | try { 189 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 190 | if ("Nimbus".equals(info.getName())) { 191 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 192 | break; 193 | } 194 | } 195 | } catch (ClassNotFoundException ex) { 196 | java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 197 | } catch (InstantiationException ex) { 198 | java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 199 | } catch (IllegalAccessException ex) { 200 | java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 201 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 202 | java.util.logging.Logger.getLogger(Result.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 203 | } 204 | 205 | 206 | //Create and display the form 207 | java.awt.EventQueue.invokeLater(new Runnable() { 208 | public void run() { 209 | new Result().setVisible(true); 210 | } 211 | }); 212 | } 213 | 214 | // Variables declaration 215 | private javax.swing.JButton jButton1; 216 | private javax.swing.JLabel jLabel1; 217 | private javax.swing.JLabel jLabel10; 218 | private javax.swing.JLabel jLabel11; 219 | private javax.swing.JLabel jLabel12; 220 | private javax.swing.JLabel jLabel13; 221 | private javax.swing.JLabel jLabel14; 222 | private javax.swing.JLabel jLabel15; 223 | private javax.swing.JLabel jLabel16; 224 | private javax.swing.JLabel jLabel17; 225 | private javax.swing.JLabel jLabel18; 226 | private javax.swing.JLabel jLabel2; 227 | private javax.swing.JLabel jLabel3; 228 | private javax.swing.JLabel jLabel4; 229 | private javax.swing.JLabel jLabel5; 230 | private javax.swing.JLabel jLabel6; 231 | private javax.swing.JLabel jLabel7; 232 | private javax.swing.JLabel jLabel8; 233 | private javax.swing.JLabel jLabel9; 234 | } 235 | -------------------------------------------------------------------------------- /Java Classes/ResultService.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class ResultService { 4 | 5 | public int retVotes(int opt_id) //retreiving votes 6 | { 7 | int novotes = new DAO().getVotes(opt_id); 8 | return novotes; 9 | } 10 | public String retWinner(){ //retreiving opt name with max votes 11 | String w_opt=new DAO().getWinner(); 12 | return w_opt; 13 | } 14 | } -------------------------------------------------------------------------------- /Java Classes/VoteException.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | import java.lang.Exception; 3 | 4 | public class VoteException extends Exception { 5 | 6 | public VoteException() { 7 | } 8 | 9 | public VoteException(String message) 10 | { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java Classes/VoteFrame.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | public class VoteFrame extends javax.swing.JFrame { 4 | 5 | // Creates new form java 6 | public VoteFrame() { 7 | initComponents(); 8 | } 9 | 10 | @SuppressWarnings("unchecked") 11 | private void initComponents() { 12 | 13 | buttonGroup1 = new javax.swing.ButtonGroup(); 14 | vote_label = new javax.swing.JLabel(); 15 | vote1_button = new javax.swing.JRadioButton(); 16 | vote2_button = new javax.swing.JRadioButton(); 17 | vote3_button = new javax.swing.JRadioButton(); 18 | vote4_button = new javax.swing.JRadioButton(); 19 | vote5_button = new javax.swing.JRadioButton(); 20 | vote6_button = new javax.swing.JRadioButton(); 21 | submitvote_button = new javax.swing.JButton(); 22 | 23 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 24 | 25 | vote_label.setText("Choose from the given Options: "); 26 | 27 | buttonGroup1.add(vote1_button); 28 | vote1_button.setText("Option 1"); 29 | vote1_button.setName("1"); 30 | vote1_button.addActionListener(new java.awt.event.ActionListener() { 31 | public void actionPerformed(java.awt.event.ActionEvent evt) { 32 | vote1_buttonActionPerformed(evt); 33 | } 34 | }); 35 | 36 | buttonGroup1.add(vote2_button); 37 | vote2_button.setText("Option 2"); 38 | vote2_button.addActionListener(new java.awt.event.ActionListener() { 39 | public void actionPerformed(java.awt.event.ActionEvent evt) { 40 | vote2_buttonActionPerformed(evt); 41 | } 42 | }); 43 | 44 | buttonGroup1.add(vote3_button); 45 | vote3_button.setText("Option 3"); 46 | vote3_button.addActionListener(new java.awt.event.ActionListener() { 47 | public void actionPerformed(java.awt.event.ActionEvent evt) { 48 | vote3_buttonActionPerformed(evt); 49 | } 50 | }); 51 | 52 | buttonGroup1.add(vote4_button); 53 | vote4_button.setText("Option 4"); 54 | vote4_button.addActionListener(new java.awt.event.ActionListener() { 55 | public void actionPerformed(java.awt.event.ActionEvent evt) { 56 | vote4_buttonActionPerformed(evt); 57 | } 58 | }); 59 | 60 | buttonGroup1.add(vote5_button); 61 | vote5_button.setText("Option 5"); 62 | vote5_button.addActionListener(new java.awt.event.ActionListener() { 63 | public void actionPerformed(java.awt.event.ActionEvent evt) { 64 | vote5_buttonActionPerformed(evt); 65 | } 66 | }); 67 | 68 | buttonGroup1.add(vote6_button); 69 | vote6_button.setText("None of the above"); 70 | vote6_button.addActionListener(new java.awt.event.ActionListener() { 71 | public void actionPerformed(java.awt.event.ActionEvent evt) { 72 | vote6_buttonActionPerformed(evt); 73 | } 74 | }); 75 | 76 | submitvote_button.setText("Submit"); 77 | submitvote_button.addActionListener(new java.awt.event.ActionListener() { 78 | public void actionPerformed(java.awt.event.ActionEvent evt) { 79 | submitvote_buttonActionPerformed(evt); 80 | } 81 | }); 82 | 83 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 84 | getContentPane().setLayout(layout); 85 | layout.setHorizontalGroup( 86 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 87 | .addGroup(layout.createSequentialGroup() 88 | .addGap(120, 120, 120) 89 | .addComponent(vote_label) 90 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 91 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 92 | .addContainerGap(74, Short.MAX_VALUE) 93 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 94 | .addComponent(vote6_button, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) 95 | .addComponent(vote5_button, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE) 96 | .addComponent(vote4_button, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE) 97 | .addComponent(vote3_button, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE) 98 | .addComponent(vote2_button, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) 99 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 100 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 101 | .addComponent(submitvote_button) 102 | .addGap(147, 147, 147)) 103 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 104 | .addComponent(vote1_button, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE) 105 | .addGap(48, 48, 48))))) 106 | ); 107 | layout.setVerticalGroup( 108 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 109 | .addGroup(layout.createSequentialGroup() 110 | .addGap(21, 21, 21) 111 | .addComponent(vote_label) 112 | .addGap(21, 21, 21) 113 | .addComponent(vote1_button) 114 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 115 | .addComponent(vote2_button, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) 116 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 117 | .addComponent(vote3_button, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) 118 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 119 | .addComponent(vote4_button, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 120 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 121 | .addComponent(vote5_button) 122 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 123 | .addComponent(vote6_button) 124 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE) 125 | .addComponent(submitvote_button) 126 | .addContainerGap()) 127 | ); 128 | 129 | pack(); 130 | } 131 | 132 | private void vote5_buttonActionPerformed(java.awt.event.ActionEvent evt) { 133 | }//event_vote5_buttonActionPerformed 134 | 135 | private void vote6_buttonActionPerformed(java.awt.event.ActionEvent evt) { 136 | }//event_vote6_buttonActionPerformed 137 | 138 | private void vote1_buttonActionPerformed(java.awt.event.ActionEvent evt) { 139 | }//event_vote1_buttonActionPerformed 140 | 141 | private void vote2_buttonActionPerformed(java.awt.event.ActionEvent evt) { 142 | }//event_vote2_buttonActionPerformed 143 | 144 | private void vote3_buttonActionPerformed(java.awt.event.ActionEvent evt) { 145 | }//event_vote3_buttonActionPerformed 146 | 147 | private void vote4_buttonActionPerformed(java.awt.event.ActionEvent evt) { 148 | }//event_vote4_buttonActionPerformed 149 | 150 | private void submitvote_buttonActionPerformed(java.awt.event.ActionEvent evt) { 151 | 152 | int vote; // to check which option has been 153 | if (vote1_button.isSelected()) { //selected by the user 154 | 155 | vote = 1; 156 | } 157 | 158 | else if (vote2_button.isSelected()) { 159 | 160 | vote = 2; 161 | } 162 | else if(vote3_button.isSelected()){ 163 | 164 | vote = 3; 165 | } 166 | else if(vote4_button.isSelected()){ 167 | 168 | vote = 4; 169 | } 170 | else if(vote5_button.isSelected()){ 171 | 172 | vote = 5; 173 | } 174 | 175 | else 176 | { 177 | vote=6; 178 | } 179 | 180 | new VoteService().addVote(vote); //adding the selected option id in 181 | //in the database, votes table 182 | // MessageDialog to show information selected radion buttons. 183 | java.awt.EventQueue.invokeLater(new Runnable() { 184 | public void run() { 185 | new ExitFrame().setVisible(true); 186 | } 187 | }); 188 | 189 | }//event_submitvote_buttonActionPerformed 190 | 191 | // Variables declaration 192 | private javax.swing.ButtonGroup buttonGroup1; 193 | private javax.swing.JButton submitvote_button; 194 | private javax.swing.JRadioButton vote1_button; 195 | private javax.swing.JRadioButton vote2_button; 196 | private javax.swing.JRadioButton vote3_button; 197 | private javax.swing.JRadioButton vote4_button; 198 | private javax.swing.JRadioButton vote5_button; 199 | private javax.swing.JRadioButton vote6_button; 200 | private javax.swing.JLabel vote_label; 201 | } 202 | -------------------------------------------------------------------------------- /Java Classes/VoteService.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | 6 | public class VoteService { 7 | 8 | public void addVote(int vote) //adding votes given by user 9 | { //in the database 10 | try { //through DAO class using .insertVote 11 | new DAO().insertVote(vote); 12 | } 13 | catch (VoteException ex) { 14 | Logger.getLogger(VoteService.class.getName()).log(Level.SEVERE, null, ex); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java Classes/WelcomeFrame.java: -------------------------------------------------------------------------------- 1 | package myproject; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | public class WelcomeFrame extends javax.swing.JFrame { 6 | 7 | // Creates new form java 8 | public WelcomeFrame() { 9 | initComponents(); 10 | } 11 | 12 | private void initComponents() { 13 | 14 | username_label = new javax.swing.JLabel(); 15 | username_textfield = new javax.swing.JTextField(); 16 | password_label = new javax.swing.JLabel(); 17 | submit_button = new javax.swing.JButton(); 18 | jPasswordField1 = new javax.swing.JPasswordField(); 19 | signin_button = new javax.swing.JButton(); 20 | signin_label = new javax.swing.JLabel(); 21 | 22 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 23 | 24 | username_label.setText("Username"); 25 | 26 | password_label.setText("Password"); 27 | 28 | submit_button.setText("Submit"); 29 | submit_button.addActionListener(new java.awt.event.ActionListener() { 30 | public void actionPerformed(java.awt.event.ActionEvent evt) { 31 | submit_buttonActionPerformed(evt); 32 | } 33 | }); 34 | 35 | signin_button.setText("Sign Up"); 36 | signin_button.addActionListener(new java.awt.event.ActionListener() { 37 | public void actionPerformed(java.awt.event.ActionEvent evt) { 38 | signin_buttonActionPerformed(evt); 39 | } 40 | }); 41 | 42 | signin_label.setText("New Registration"); 43 | 44 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 45 | getContentPane().setLayout(layout); 46 | layout.setHorizontalGroup( 47 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 48 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 49 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 50 | .addComponent(submit_button) 51 | .addGap(150, 150, 150)) 52 | .addGroup(layout.createSequentialGroup() 53 | .addGap(66, 66, 66) 54 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 55 | .addComponent(username_label) 56 | .addComponent(password_label)) 57 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 58 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 59 | .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE) 60 | .addComponent(username_textfield)) 61 | .addGap(141, 141, 141)) 62 | .addGroup(layout.createSequentialGroup() 63 | .addGap(58, 58, 58) 64 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 65 | .addGroup(layout.createSequentialGroup() 66 | .addGap(10, 10, 10) 67 | .addComponent(signin_button)) 68 | .addComponent(signin_label)) 69 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 70 | ); 71 | layout.setVerticalGroup( 72 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 73 | .addGroup(layout.createSequentialGroup() 74 | .addGap(63, 63, 63) 75 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 76 | .addComponent(username_label) 77 | .addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 78 | .addGap(24, 24, 24) 79 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 80 | .addComponent(password_label) 81 | .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 82 | .addGap(27, 27, 27) 83 | .addComponent(submit_button) 84 | .addGap(20, 20, 20) 85 | .addComponent(signin_label) 86 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 87 | .addComponent(signin_button) 88 | .addContainerGap(43, Short.MAX_VALUE)) 89 | ); 90 | 91 | pack(); 92 | }//initComponents 93 | 94 | private void submit_buttonActionPerformed(java.awt.event.ActionEvent evt) { 95 | //event_submit_buttonActionPerformed 96 | String username = username_textfield.getText(); 97 | String password = new String(this.jPasswordField1.getPassword()); 98 | if(new RegisterService().validateVoter(username, password)) //checking the validation of username 99 | //and password, i.e. if it is present 100 | if(new RegisterService().validateAdmin(username, password)) //in out database 101 | new AminFrame().setVisible(true); 102 | else 103 | new VoteFrame().setVisible(true); 104 | else 105 | JOptionPane.showMessageDialog(this, "Invalid username or password"); 106 | }//event_submit_buttonActionPerformed 107 | 108 | private void signin_buttonActionPerformed(java.awt.event.ActionEvent evt) { //new registration, signup option 109 | //event_signin_buttonActionPerformed 110 | new RegisterationFrame().setVisible(true); 111 | } 112 | //event_signin_buttonActionPerformed 113 | 114 | private javax.swing.JPasswordField jPasswordField1; 115 | private javax.swing.JLabel password_label; 116 | private javax.swing.JButton signin_button; 117 | private javax.swing.JLabel signin_label; 118 | private javax.swing.JButton submit_button; 119 | private javax.swing.JLabel username_label; 120 | private javax.swing.JTextField username_textfield; 121 | // End of variables declaration 122 | } 123 | -------------------------------------------------------------------------------- /Polling System - Final Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vidhikhatwani/Polling-System-Java-Application/c87d6f8367917885318d8bec67793ac9ef680855/Polling System - Final Report.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Polling-System-Java-Application 2 | 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. 3 | In this project, we will provide an online tool to vote on various questions submitted by the administrator/organizer. 4 | 5 | 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. 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. 6 | 7 | Prerequisite: MySQL connector for java must be downloaded in the same folders as the project. 8 | --------------------------------------------------------------------------------