java投票管理系统代码 java投票管理系统代码查询

java编写一个简易单机投票管理器 我想知道如何实现 选中复选框选项后点击投票实现票数加一并显示定义三个变量记录每个人的投票数 。点击投票按钮后,根据checkbox的勾选情况将三个变量累加 。点击查看按钮时展示这三个变量
用java做一个简单的投票系统,有三名表演者,代号,1.2.3 。观众依次投票 , 已数字0结束,然后还import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Vote {
public static void main(String args[]) {
try {
String[] persons = new String[]{"1","2","3"};
Integer[] votes = new Integer[]{0,0,0};
BufferedReader sin = new BufferedReader(new InputStreamReader(
System.in));
String readline;
System.out.println("================投票开始===============");
System.out.println("请按1,2 , 3投票 , Enter确认");
System.out.println("按0--Enter结束投票 , 公布结果\n");
readline = sin.readLine(); // 从系统标准输入读入一字符串
while (!readline.equals("0")) {
String voteStr = readline;
if(persons[0].equals(voteStr)){
votes[0] +=1;
}else if(persons[1].equals(voteStr)){
votes[1] +=1;
}else if(persons[2].equals(voteStr)){
votes[2] +=1;
}else{
System.out.println("无效的投票!");
}
readline = sin.readLine(); // 从系统标准输入读入一字符串
} // 继续循环
System.out.println("================投票结束===============");
System.out.println("================结果公布===============");
System.out.println(persons[0]+"================"+persons[1]+"==============="+persons[2]);
System.out.println(votes[0]+"================"+votes[1]+"==============="+votes[2]);
} catch (Exception e) {
System.out.println("Error" + e); // 出错,则打印出错信息
}
}
}
用jsp做网上投票系统 代码我之前做过类似的投票小项目,在这里把源码发给你 。你自己好好的参考一下 。--------------------------package com.tv.bean;public class TVBean {
private String tvName;
private int tvCount;
public String getTvName() {
return tvName;
}
public void setTvName(String tvName) {
this.tvName = tvName;
}
public int getTvCount() {
return tvCount;
}
public void setTvCount(int tvCount) {
this.tvCount = tvCount;
}
}------------------------------package com.tv.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;import com.tv.bean.TVBean;
public class DBUtil {
private Connection con;
private PreparedStatement ps = null;
private ResultSet rs;
public void getCon(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=TV","sa","");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeCon(){
try {
if(rs !=null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ArrayList getAll(){
ArrayList al = new ArrayList();
this.getCon();
String sql = "select * from TVInfo order by tvCount desc";
try {
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
TVBean tb = new TVBean();
tb.setTvName(rs.getString(1));
tb.setTvCount(rs.getInt(2));
al.add(tb);
}
} catch (SQLException e) {

推荐阅读