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. Django 模板语言 for循环

    Django 模板语言 for 循环 ******  for 循环字典 ********** USER_DICT = { 'k1':'root1', 'k2':'root2', 'k3':'root3 ...

  2. Windows server 2012 显示“我的电脑”

    Windows server 2012 桌面上默认没有显示“我的电脑”的快捷方式, 如果要显示,可以输入一行命令: rundll32.exe shell32.dll,Control_RunDLL de ...

  3. Electron学习入门

    1.安装electron,不建议全局安装,这样每个app可以使用不同的electron版本了 2.配置package.json中的script下的start属性的值为electron . Electr ...

  4. 40、js技巧(持续更新。。。)

    1.深拷贝对象: const a={name:'aaa',age:11} const b=JSON.parse(JSON.stringify(a)) 2.获取数组极值: let list = [1, ...

  5. Vue -- 项目报错整理(2):IE报错 - ‘SyntaxError:strict 模式下不允许一个属性有多个定义‘ ,基于vue element-ui页面跳转坑的解决

  6. ES10(2019)有哪些更新和新特性?

    ES10新特性(2019) 行分隔符(U + 2028)和段分隔符(U + 2029)符号现在允许在字符串文字中,与JSON匹配 更加友好的 JSON.stringify 新增了Array的flat( ...

  7. Golang: 接收GET和POST参数

    GET 和 POST 是我们最常用的两种请求方式,今天结合前端 axios 请求库来讲一讲,如何在 golang 服务中,正确接收这两种请求的参数信息. 一.搭建一个简单的服务 首先,我们来创建一个最 ...

  8. 【GitHub】源代码管理工具初识

    软件工程综合实践第四次个人作业 作业要求:通过搜索资料和自学,了解源代码管理工具——GitHub 前言: GitHub,读音 /git·hʌb/ ,让社会化编程成为现实,其于2018年6月4日被微软收 ...

  9. 【OS_Windows】Win10应用商店闪退和点击Cortana搜索框闪退的解决方法

    Windows10用户遇到了打开应用商店时闪退和点击Cortana小娜搜索框闪退的问题,并且在微软社区求助,得到了一种可行的解决方法,那就是查看Network List Service(网络列表服务) ...

  10. springboot2.1.3 本地加载jar包+打包载入本地jar

    项目已springboot为主,有时候我们需要引入的jar包并非maven公共库中存在(这里不谈私自搭建私库),那我们能否像普通的工程一样,导入自己手动添加的jar包文件呢? 答案是肯定的,来,一起往 ...