Am coding a college council voting system for my school in netbeans and mysql saver. i have
populated jtables containing cadidates (jtable1 for president, jtable2 for vice president etc) and i have put a jbutton so that after sellecting candidents of choice one from each jtable, you click the jbutton to cast a vote for each selected candidate and submitte an update into the mysql tables showing current results for every candidate. please help me out, am required to present this project
next week. thank you very much in advance.

Recommended Answers

All 6 Replies

Exactly what help do you need?

@ JamesCherrill-I need java source code to write in the actionPerformed method of the jbutton so that if its clicked; a vote is cast for every candidate selected from the different jtables.

If you need Java code for your homework then you have to write it yourself; nobody here will do your homework for you. If you make an effort, and get stuck, post what you have done so far, and people here will help you.

so, you want us to provide you with the code you'll present as your project at college?
does the word plagiarism ring any bells?

//THIS IS PART OF WHAT I HAVE DONE TO POPULATE JTABLES WITH MYSQL DATA IN NETBEANS,(I USED ARRAYS).NOW AM STUCK ON HOW TO ENABLE A VOTE CASTE AND SUBMISSION TO THE DATABASE USING  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                         }
I HAVE SEARCHED THE INTERNET AND COULDN'T JUST FIND ANYTHING SIMILAR TO WHAT AM LOOKING FOR.I HOPE SOMEONE WILL HELP EVEN JUST WITH AN IDEA ON HOW TO GO ABOUT THIS.
//SCREEN SHOT
 ![VotePane.PNG](/attachments/large/4/b6d36c9801da9f29a155e3f6883a372d.PNG "align-center") 

//SOURCE CODE

public PopulateCandidate() {
        initComponents();
        populateJTable();
        populateJTableVP();
        populateJTableSG();
        populateJTableTG();
        populateJTableAS();
        populateJTableRS();
        populateJTableSS();
        populateJTablES();
        populateJTablCM();
    }

public void populateJTable(){
        MyQuery mq = new MyQuery();
        ArrayList<Product2> list = mq.BindTable();
        String[] columnName = {"Candidate_ID","Name","Image",};
        Object[][] rows = new Object[list.size()][6];
        for(int i = 0; i < list.size(); i++){

            rows[i][0] = list.get(i).getName();
            rows[i][1] = list.get(i).getID();


            if(list.get(i).getMyImage() != null){   
             ImageIcon image = new ImageIcon(new ImageIcon(list.get(i).getMyImage()).getImage()
             .getScaledInstance(150, 120, Image.SCALE_SMOOTH) );      
             rows[i][2] = image;
            }
            else{
                rows[i][2] = null;
           }   
        }

        TheModel model = new TheModel(rows, columnName) {};
       jTable_PG.setModel(model);
       jTable_PG.setRowHeight(120);
       jTable_PG.getColumnModel().getColumn(2).setPreferredWidth(150);
    }

public void populateJTablCM(){
        MyQuery mq = new MyQuery();
        ArrayList<Product2> list = mq.BindTable8();
        String[] columnName = {"Candidate_ID","Name","Image",};
        Object[][] rows = new Object[list.size()][6];
        for(int i = 0; i < list.size(); i++){

            rows[i][0] = list.get(i).getName();
           rows[i][1] = list.get(i).getID();

            if(list.get(i).getMyImage() != null){

             ImageIcon image = new ImageIcon(new ImageIcon(list.get(i).getMyImage()).getImage()
             .getScaledInstance(150, 120, Image.SCALE_SMOOTH) );   

            rows[i][2] = image;
            }
            else{
                rows[i][2] = null;
            }

        }

        TheModel model = new TheModel(rows, columnName) {};
     jTable_CM.setModel(model);
      jTable_CM.setRowHeight(120);
     jTable_CM.getColumnModel().getColumn(2).setPreferredWidth(150);
    }


//VOTER CASTS A VOTE FOR THEIR FAVOURITE CANDIDATES FROM EACH JTABLE

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

In your action event handler:
see which candidate they voted for
run an SQL UPDATE command to update the datbase accordingly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.