投票管理系统范本模板文档格式.docx
《投票管理系统范本模板文档格式.docx》由会员分享,可在线阅读,更多相关《投票管理系统范本模板文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
//是否中选
Candidate(Stringname,intid);
//Candidate的构造方法
publicStringgetName();
publicvoidsetName(Stringname);
publicintgetId();
publicvoidsetId(intid);
publicintgetNum();
publicvoidsetNum(intnum);
publicdoublegetVoteResult();
publicvoidsetVoteResult(doublevoteResult);
publicbooleanisVote();
publicvoidsetVote(booleanisVote);
}
2、管理类:
Manager类
publicclassManager{
publicintcandidates;
//候选人的数量
publicintpercentage;
//当选标准(百分比)
publicintvoters=0;
//投票人数量
List〈Candidate>
listc;
//装载候选者的容器
publicstaticvoidmain(String[]args);
publicvoidcalculateResult();
//计算结果
}
3、窗口的操作类UserInterface
publicclassUserInterfaceextendsJFrame{
privatestaticfinallongserialVersionUID=1L;
publicContainercontentPanel;
//当前界面控制器
publicManagermanager;
//利于数据通信,主要包括:
候选人数量、当选标准、投票者数量
publicJPanelp1;
//输入信息的面板
publicJPanelp2;
//投票面板
publicJPanelp3;
//显示投票结果的面板
publicList〈JTextField>
list_textfield;
//装载候选人姓名的容器
publicList<
JRadioButton>
list_jradiobutton;
//投票
publicUserInterface(Managerm);
publicvoidupdate();
//窗口中增删组建后立即更新
publicvoidaddCandi(intnum);
//panel1输入侯选者姓名完成后,生成候选者对象
2.2.4、输入面板类:
MainGraph
publicclassMainGraph{
privateUserInterfaceuserInterface;
//与主面板的通信
publicMainGraph(UserInterfaceuserInterface);
//MainGraph的构造函数
publicvoidlaunchMainGraph();
//加载主面板
}
2.2.5、投票面板类:
VoteGraph
publicclassVoteGraph{
privateUserInterfaceuserInterface;
//与主面板的通信
publicVoteGraph(UserInterfaceuserInterface);
//构造函数
publicvoidlaunchVoteGraph();
//加载投票面板
2.6、显示结果类:
ResultGraph
publicclassResultGraph{
publicResultGraph(UserInterfaceuserInterface);
//构造函数
publicvoidlaunchResultGraph();
//加载显示结果的面板
3功能实现
3。
1窗口显示
点击运行后弹出一个窗口(Panel1),要求用户输入候选人的个数(1—12)以及当选标准(若为50%,只需输入50即可)
假若依次输入12,50.点击确定后,窗口中会提示输入侯选人的姓名,候选人的编号是从小到大依次生成的.
依次输入12人的姓名点击提交后,就会弹出投票的窗口
假若共有7名投票人参与投票(每次投票完点击提交即为完成依次投票)投票过程如下:
投票者1:
1号:
吴红岩3号:
邵芳9号:
李丹11号:
李四
投票者2:
2号:
刘莉莉3号:
邵芳4号:
尹聪敏6号:
王小丽
8号:
王永霞
投票者3:
1号:
吴红岩2号:
刘莉莉4号:
尹聪敏5号:
张三
7号:
李泽9号:
李丹
投票者4:
吴红岩7号:
李泽12号:
王龙贺
投票者5:
3号:
尹聪敏5号:
张三7号:
李泽
10号:
王小慧
投票者6:
10号:
王小慧11号:
李四12号:
王龙贺
投票者7:
吴红岩2号:
尹聪敏
7号:
最终的投票结果如下图所示:
3.2功能1
整个系统的UML时序图如下图所示:
附录:
程序源代码
1、Candidate的详细代码:
privateintid;
privateintnum;
Candidate(Stringname,intid){
this.name=name;
this.id=id;
this。
num=0;
this.voteResult=0;
this.isVote=false;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
name=name;
publicintgetId(){
returnid;
publicvoidsetId(intid){
id=id;
publicintgetNum(){
returnnum;
publicvoidsetNum(intnum){
num=num;
publicdoublegetVoteResult(){
returnvoteResult;
publicvoidsetVoteResult(doublevoteResult){
voteResult=voteResult;
publicbooleanisVote(){
returnisVote;
publicvoidsetVote(booleanisVote){
isVote=isVote;
publicStringtoString(){
returnthis.name;
45、Manager类的详细代码
importjava.util.ArrayList;
importjava.util.List;
publicclassManager{
publicintpercentage;
List〈Candidate〉listc=newArrayList〈Candidate〉();
publicstaticvoidmain(String[]args){
Managerm=newManager();
UserInterfaceui=newUserInterface(m);
MainGraphmainGraph=newMainGraph(ui);
mainGraph.launchMainGraph();
publicvoidcalculateResult(){
doubled;
for(inti=0;
i<
candidates;
i++){
Candidatec=listc.get(i);
d=(double)c。
getNum()/voters;
c.setVoteResult((double)Math.round(d*10000)/100);
if(d〉=percentage*0。
01){
c。
setVote(true);
}
}
46、UserInterface类的详细代码:
importjava.awt.Color;
importjava。
awt.Container;
awt。
Font;
awt.event。
ActionEvent;
awt.event.ActionListener;
importjava.util。
ArrayList;
Iterator;
util。
List;
Vector;
importjavax。
swing。
JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing。
JPanel;
JRadioButton;
JScrollPane;
importjavax.swing.JTable;
JTextField;
swing.SwingConstants;
importjavax.swing.table.DefaultTableCellRenderer;
/**
*
*@authorwhy
*
*/
privatestaticfinallongserialVersionUID=1L;
publicContainercontentPanel;
publicManagermanager;
//利于数据通信,主要包括:
publicJPanelp1;
JTextField>
list_textfield=newArrayList〈JTextField>
();
publicList〈JRadioButton>
list_jradiobutton=newArrayList<
JRadioButton〉();
publicUserInterface(Managerm){
super("
欢迎来到投票管理系统”);
this.manager=m;
setVisible(true);
this.setBounds(150,30,700,700);
setDefaultCloseOperation(JFrame。
EXIT_ON_CLOSE);
this.setResizable(false);
setBackground(Color.black);
contentPanel=this.getContentPane();
publicvoidupdate(){
this.repaint();
publicvoidaddCandi(intnum){
JTextFieldtext_name;
JLabellabel_name;
JButtonsubmit=newJButton("
提交"
);
Stringss="
"
;
intx1=80,x2=200,y=150,w=150,h=20;
intyy=y;
for(inti=1;
=num;
i++){
if(y>
=this.getHeight()-250){
y=yy;
x1=x1+300;
x2=x2+300;
y+=50;
text_name=newJTextField();
//新建输入姓名的文本框
label_name=newJLabel(ss);
label_name.setText(”候选人"
+i+”的姓名:
);
label_name。
setBounds(x1,y,w,h);
text_name。
setBounds(x2,y,w,h);
list_textfield。
add(text_name);
//把输入姓名的文本框加入到list中
p1.add(label_name);
p1。
this。
update();
}
submit.setBounds(this.getWidth()/3,this。
getHeight()-150,100,20);
submit。
addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
for(inti=0;
list_textfield.size();
Stringname=list_textfield.get(i)。
getText();
//得到文本框中输入的候选者姓名
Candidatecandi=newCandidate(name,i+1);
//根据输入的姓名生成一个候选者
manager.listc。
add(candi);
//把候选者加入到list中
}
VoteGraphvoteGraph=newVoteGraph(UserInterface.this);
voteGraph。
launchVoteGraph();
//加载投票面板(Panel2)
}
});
p1.add(submit);
}
47、MainGraph类的详细代码:
awt.Color;
importjava.awt.Container;
importjava.awt。
awt.HeadlessException;
event。
ActionListener;
JButton;
JLabel;
swing.JPanel;
swing.JTextField;
/**
*系统的主界面,接受候选者人数,以及当选的标准
*@authorwhy
*
*/
publicMainGraph(UserInterfaceuserInterface){
super();
this.userInterface=userInterface;
publicvoidlaunchMainGraph(){
userInterface。
p1=newJPanel();
userInterface.p1.setLayout(null);
p1。
setBackground(Color。
orange);
userInterface.contentPanel。
add(userInterface。
p1);
JLabellab=newJLabel(”请输入投票信息”);
lab.setBounds(200,30,250,50);
intsize=25;
lab。
setFont(newFont("
Serif"
,Font.PLAIN,size));
JLabellabel=newJLabel("
请输入候选人的个数(1-12):
finalJTextFieldtext=newJTextField();
//输入候选人的个数
JLabellabelp=newJLabel("
请输当选标准(百分比):
finalJTextFieldpertage=newJTextField();
//输入当选百分比
JButtonb=newJButton("
确定"
//对候选人个数与百分比进行计较的按钮
label。
setBounds(80,100,170,20);
labelp.setBounds(80,130,150,20);
text。
setBounds(240,100,150,20);
pertage.setBounds(240,130,150,20);
b。
setBounds(500,130,70,20);
b.addActionListener(newActionListener(){
userInterface。
manager。
candidates=Integer。
parseInt(text。
getText());
//得到候选者的个数
addCandi(userInterface。
manager.candidates);
userInterface.manager.percentage=Integer.parseInt(pertage.getText());
//得到当选百分比
});
add(label);
p1.add(lab);
add(text);
p1.add(b);
add(labelp);
userInterface.p1.add(pertage);
userInterface.update();
48、VoteGraph类的详细代码:
importjava.awt.Font;
ActionEvent;
event.ActionListener;
swing.JButton;
swing.JLabel;
importjavax.swing.JRadioButton;
publicclassVoteGraph{
publicVoteGraph(UserInterfaceuserInterface){
user