package 投票管理;
import java.io.*;
import java.awt.*;
import java.util.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class vote extends Applet implements ActionListener{
AudioClip music;//播放音乐
Label hint,result,notice,writer;
TextField canditate;//输入候选人文本框
TextField out;//显示选举结果的文本框
Button confirm1,cancle,confirm2,refresh,sort;//分别表示确认、取消、确定、刷新、排序
Button help;//投票说明
Button save;//保存统计结果
Checkbox candidate[]=new Checkbox[10];//选择框数组,代表候选人
TextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
TextField personvote[]={t1,t2,t3,t4,t5,t6,t7,t8,t9,t10};//文本条数组,显示每个人的得票情况
String candidatelist[]=new String[10];//候选人名单
int count[]={0,0,0,0,0,0,0,0,0,0};//记录每个人的得票数
int totalvote=0;//总票数
int peoplenumble=0;//候选人个数
int count1=0,invalidatedTicket=0,abstention=0; //分别表示选的人数,废票数,弃权票数
public void init(){
music=getAudioClip(getCodeBase(),"写给黄淮-西彬.mp3");
hint=new Label("首先输入候选人的名字(人数不超过10,名字之间用空格分隔):");
result=new Label("选举结果:");
writer=new Label("18软件工程本3班 孙泽玺");
canditate=new TextField(50);
confirm1=new Button(" 确认 ");
cancle=new Button(" 取消 ");
confirm2=new Button("确定");
refresh=new Button("刷新");
sort=new Button("排序");
confirm2.setEnabled(false);//设置控件是否可用
refresh.setEnabled(false);
sort.setEnabled(false);
help=new Button("投票说明");
save=new Button("保存结果");
save.setEnabled(false);
out=new TextField(50);
for(int i=0;i<10;i++)
personvote[i]=new TextField(80);
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
Panel p5=new Panel();
Panel p6=new Panel();
Panel p7=new Panel();
Panel pa=new Panel();
Panel pb=new Panel();
Panel pc=new Panel();
setLayout(new BorderLayout());
pa.setLayout(new GridLayout(7,1));
pb.setLayout(new BorderLayout());
p4.setLayout(new GridLayout(1,5));
p5.setLayout(new GridLayout(1,5));
p1.add(hint);
p2.add(canditate);
p2.add(help);
p3.add(confirm1);
p3.add(cancle);
p4.setBackground(Color.gray);
p5.setBackground(Color.gray);
p6.setBackground(Color.green);
for(int i=0;i<5;i++){//创建候选人选项
candidate[i]=new Checkbox(candidatelist[i]);
p4.add(candidate[i]);
}
for(int i=5;i<10;i++){//创建候选人选项
candidate[i]=new Checkbox(candidatelist[i]);
p5.add(candidate[i]);
}
for(int j=0;j<10;j++){
candidate[j].setEnabled(false);
}
p6.add(confirm2);p6.add(refresh);p6.add(sort);
p7.add(result);p7.add(out);p7.add(save);
pa.add(p1);pa.add(p2);pa.add(p3);
pa.add(p4);pa.add(p5);pa.add(p6);pa.add(p7);
p.setLayout(new GridLayout(10,1));
for(int i=0;i<10;i++){
p.add(personvote[i]);
}
ScrollPane scroll=new ScrollPane();
scroll.add(p);
pc.add(writer);
pb.add("Center",scroll);
pb.add("South",pc);
add("Center",pa);
add("South",pb);
confirm1.addActionListener(this);
cancle.addActionListener(this);
confirm2.addActionListener(this);
refresh.addActionListener(this);
sort.addActionListener(this);
help.addActionListener(this);
save.addActionListener(this);
}//面板的布局
public void start(){//循环播放音乐
music.loop();}
public void stop(){//结束播放
music.stop();}
public void actionPerformed(ActionEvent e){//注册监听
String s=e.getActionCommand();
if(s.equals(" 确认 ")){
confirm1.setEnabled(false);save.setEnabled(true);
confirm2.setEnabled(true);refresh.setEnabled(true);sort.setEnabled(true);help.setEnabled(true);
String g=canditate.getText();//获取输入的候选人
StringTokenizer st=new StringTokenizer(g);//字符串分析器
peoplenumble=st.countTokens();//统计候选人数
int i=0;
while(st.hasMoreTokens()){
candidatelist[i]=st.nextToken();
i++;}//获取语言符号(候选人名单)
for(int j=0;j<10;j++)
candidate[j].setLabel(candidatelist[j]);//将候选人名单添加到复选框里
for(int j=0;j<peoplenumble;j++)
candidate[j].setEnabled(true);
for(int j=peoplenumble;j<10;j++)
candidate[j].setVisible(false);//多余的选框设置为不可见 }
if(s.equals(" 取消 ")){//重新设置候选人,进行重新投票
confirm1.setEnabled(true);
canditate.setText("");
}
if(s.equals("确定")){
totalvote=0;
count1=0;
sort.setEnabled(true);
for(int j=0;j<10;j++){
if(candidate[j].getState())
count1++;
}//统计选了多少人
if(count1==0) abstention++;
if(count1>10) invalidatedTicket++;
if(count1<=10&&count1>0){
for(int j=0;j<peoplenumble;j++){
if(candidate[j].getState())
count[j]++;
totalvote=count[j]+totalvote; }
}//统计候选人所得票数
for(int j=0;j<10;j++)
candidate[j].setState(false);
for(int j=0;j<10;j++){
candidate[j].setState(false);
}//清空选框中的勾
out.setText("已经统计了:"+totalvote+"张选票,其中弃权票:"+abstention+"作废票:"+invalidatedTicket);//输出统计结果
for(int j=0;j<peoplenumble;j++)
personvote[j].setText(""+candidatelist[j]+"得票数:"+count[j]);//输出各个候选人得票数 }
if(s.equals("刷新")){
confirm1.setEnabled(true);
confirm2.setEnabled(false);refresh.setEnabled(false);sort.setEnabled(false);save.setEnabled(false);
totalvote=0;
peoplenumble=0;
count1=0;invalidatedTicket=0;abstention=0;
canditate.setText("");
out.setText("");
for(int j=0;j<10;j++){
candidate[j].setState(false);
}
for(int j=peoplenumble;j<10;j++)
candidate[j].setVisible(true);
for(int j=0;j<10;j++)
candidatelist[j]="";
for(int j=0;j<10;j++)
count[j]=0;
for(int j=0;j<10;j++)
candidate[j].setLabel(candidatelist[j]);
for(int j=0;j<10;j++)
personvote[j].setText(""); }
if(s.equals("排序")){
sort.setEnabled(false);
int m;String n;
for(int j=0;j<peoplenumble;j++)
for(int i=j+1;i<peoplenumble;i++)
if(count[j]<count[i]){
m=count[j];count[j]=count[i];count[i]=m;
n=candidatelist[j];candidatelist[j]=candidatelist[i];candidatelist[i]=n;
}//按得票数由多到少进行排序
for(int j=0;j<peoplenumble;j++){
personvote[j].setText(""+candidatelist[j]+"得票数:"+count[j]);
}//输出排序后各候选人的票数
out.setText("排序后统计为:"+totalvote+"张选票,其中弃权票:"+abstention+"作废票:"+invalidatedTicket);
} if(s.equals("投票说明")){
new Help();
}
if(s.equals("保存结果")){
new Save();
}
}
class Help extends Frame{//“投票说明”的弹出窗体
Panel p=new Panel();
TextField help[]=new TextField[6];
Help(){
super("投票说明");
p.setLayout(new GridLayout(6,1));
for(int i=0;i<6;i++)
help[i]=new TextField(10);
for(int i=0;i<6;i++){
p.add(help[i]);
}
ScrollPane scroll=new ScrollPane();
scroll.add(p);
add(scroll);
help[0].setText("投票说明:");
help[1].setText("1:在文本框中输入候选人名单,点击“确认”以完成候选人的设置,点击“取消”可以重新设置候选人。");
help[2].setText("2:对候选人进行投票,点击下面的“确定”以确认选票。(注意:每点一次确定将产生一张选票!)");
help[3].setText("3:确定选票后,会自动统计结果,点击“排序”可以对候选人所得的票数由高到低进行排序。");
help[4].setText("4:点击“刷新”可以重新设置候选人,并开始新的一轮投票");
help[5].setText("5:在任何时候可以点击“使用说明”来查看帮助,点击“保存结果”,可以将统计以文本的形式显示出来。");
setSize(600,200);
setVisible(true);
addWindowListener(new closeWin());
}
class closeWin extends WindowAdapter{
public void windowClosing(WindowEvent e){
Window w=e.getWindow();
w.dispose();
}
}
}
class Save extends Frame{//“保存结果”的弹出窗体
TextArea save;
Save(){
super("统计结果");
save=new TextArea(11,1);
add(save);
save.setText(out.getText()+'\n'+personvote[0].getText()+'\n'+personvote[1].getText()+'\n'+
personvote[2].getText()+'\n'+personvote[3].getText()+'\n'
+personvote[4].getText()+'\n'+personvote[5].getText()+'\n'
+personvote[6].getText()+'\n'+personvote[7].getText()+'\n'
+personvote[8].getText()+'\n'+personvote[9].getText()+'\n');
setSize(300,300);
setVisible(true);
addWindowListener(new closeWin());
}
class closeWin extends WindowAdapter{
public void windowClosing(WindowEvent e){
Window w=e.getWindow();
w.dispose();
}
}
}
}

  

vote的更多相关文章

  1. BZOJ-1934 Vote 善意的投票 最大流+建图

    1934: [Shoi2007]Vote 善意的投票 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1551 Solved: 951 [Submit][S ...

  2. bzoj1934: [Shoi2007]Vote 善意的投票

    最大流..建图方式都是玄学啊.. //Dinic是O(n2m)的. #include<cstdio> #include<cstring> #include<cctype& ...

  3. 最小投票BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)

    上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下最小投票 1934: [Shoi2007]Vote 好心的投票 Time Limit: 1 Sec Memory L ...

  4. [POLITICS] S Korea lawmakers vote to impeach leader

    South Korea's Parliament has voted to impeach President Park Geun-hye. The National Assembly motion ...

  5. BZOJ 1934: [Shoi2007]Vote 善意的投票 最小割

    1934: [Shoi2007]Vote 善意的投票 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...

  6. A Linear Time Majority Vote Algorithm

    介绍一种算法,它可以在线性时间和常数空间内,在一个数组内找出出现次数超过一半的某个数字. 要解决这个问题并不难,可以使用排序或哈希,但是这两种算法都不能同时满足时间或空间的要求. 然而,该算法(A L ...

  7. 11gR2更换OCR和VOTE

    11gR2开始,OCR和VOTE它们被存储在ASM磁盘组,因此,更换OCR有两种方法,第一是使用ASM磁盘组drop disk数据重组后,另一种方法是OCR迁移到另一个磁盘组 第一种:add disk ...

  8. WeMall微商城源码投票插件Vote的主要源码

    WeMall微信商城源码投票插件Vote,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考 AdminController.class.php <?php namespace Ad ...

  9. 1934: [Shoi2007]Vote 善意的投票

    1934: [Shoi2007]Vote 善意的投票 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1174  Solved: 723[Submit][S ...

  10. Boyer-Moore Majority Vote Algorithm

    介绍算法之前, 我们来看一个场景, 假设您有一个未排序的列表.您想知道列表中是否存在一个数量占列表的总数一半以上的元素, 我们称这样一个列表元素为 Majority 元素.如果有这样一个元素, 求出它 ...

随机推荐

  1. 『正睿OI 2019SC Day6』

    动态规划 \(dp\)早就已经是经常用到的算法了,于是老师上课主要都在讲题.今天讲的主要是三类\(dp\):树形\(dp\),计数\(dp\),\(dp\)套\(dp\).其中计数\(dp\)是我很不 ...

  2. Win10应用商城删除后部分应用出错的解决方案

    出错图示 解决方案 查找完整包名:Get-AppxPackage -allusers | Select Name, PackageFullName Add-appxpackage -register ...

  3. kafka Enabling Kerberos Authentication

    CDK 2.0 and higher Powered By Apache Kafka supports Kerberos authentication, but it is supported onl ...

  4. mysql 5.7 修改root密码允许远程连接

    1.修改root密码(其他用户类似)  试过网上看的一些 在mysql数据库执行 update user set password='新密码'  where user='root' 执行说找不到字段, ...

  5. winform实现Session功能(保存用户信息)

    问题描述:在winform中想实现像BS中类似Session的功能,放上需要的信息,在程序中都可以访问到. 解决方案:由于自己很长时间没有做过winform的程序,一时间竟然手足无措起来.后来发现wi ...

  6. APS.NET MVC + EF (00)---C#基础

    命名参数 命名参数是把参数附上参数名称,这样在调用方法的时候不必按照原来的参数顺序填写参数,只需要对应好参数的名称也能完成方法调用. static void Main(string[] args) { ...

  7. MongoDB netcore

    mongodb.driver mongodb.driver.core url:  http://dl.mongodb.org/dl/win32/x86_64 ********************* ...

  8. 【MySQL】数据库事务深入分析

    一.前言 只有InnoDB引擎支持事务,下边的内容均以InnoDB引擎为默认条件 二.常见的并发问题 1.脏读 一个事务读取了另一个事务未提交的数据 2.不可重复读 一个事务对同一数据的读取结果前后不 ...

  9. CSS 精灵技术(sprite)

    一.精灵技术产生的背景 图所示为网页的请求原理图,当用户访问一个网站时,需要向服务器发送请求,网页上的每张图像都要经过一次请求才能展现给用户.  然而,一个网页中往往会应用很多小的背景图像作为修饰,当 ...

  10. HTML5 新增文本标签

    一.mark 标记文本 <mark> 标签定义带有记号的文本,表示页面中需要突出显示或高亮显示的信息. 通常在引用原文的时候使用 mark 元素,目的是引起当前用户的注意. 语法格式: & ...