• Post Reply Bookmark Topic Watch Topic
  • New Topic

Online Voting System using Serilization

 
sanjeet kunal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please someone tell me how to count numbers of click on button and how to get final result.............this is my incomplete code



public class Voting_Machine extends JFrame implements ActionListener{
JLabel l;
JButton b1,b2,b3;

Voting_Machine()
{
l = new JLabel("Online Voting System");
    l.setForeground(Color.red);
    l.setFont(new Font("Arial", Font.BOLD, 25));

b1=new JButton("Obama");
b2=new JButton("Laalu");
b3=new JButton("View Result");
b1.setForeground(Color.red);
        b2.setForeground(Color.red);
      
       
      
       
        add(l);
        add(b1);
add(b2);
add(b3);

setVisible(true);
setLayout(new FlowLayout());
setSize(400,800);



b1.addActionListener(this);
b2.addActionListener(this);
}

public static void main(String[] args) {
}



   
public void actionPerformed(ActionEvent e) {


}
}
 
Les Morgan
Rancher
Posts: 717
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways of doing it, but probably the easiest is to assign an ActionListener to each button, then check the event in the ActionListener and see what the caption is on the parent. Make a simple comparison using a switch statement to increment each total for each of the candidates.  Please note, you will have to have the totals defined as instance variables and not locals to collect running tallies.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!