resultarea.java
来自「添加侯选人,统计选票,查看选举结果,结果按选票数量从大到小排列」· Java 代码 · 共 41 行
JAVA
41 行
import java.awt.*;
public class ResultArea extends Panel
{
PersonSelected personSelected[];
TextArea text;
ResultArea(PersonSelected personSelected[])
{
this.personSelected=personSelected;
text=new TextArea(12,40);
text.setText(null);
add(text);
}
public void setPersonSelected(PersonSelected personSelected[])
{
text.setText(null);
String str[]=new String[personSelected.length];
int count[]=new int[personSelected.length];
for(int k=0;k<str.length;k++)
{
str[k]=personSelected[k].getName();
count[k]=personSelected[k].getCount();
}
for(int k=0;k<str.length;k++)
{
for(int i=k+1;i<str.length;i++)
if(count[i]>count[k])
{
String temp=str[k];
int n=count[k];
str[k]=str[i];
str[i]=temp;
count[i]=n;
}
}
for(int k=0;k<str.length;k++)
{
text.append("\n"+str[k]+"得票:"+count[k]);
}
validate();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?