请教各位高人:
我建立了一个property文件:里面的字段如下:
xxx.name=xxx
xxx.sex=m
xxx.age=20
xxx.group=1
bbb.name=bbb
bbb.sex=f
bbb.age=20
bbb.group=2
等等
现在是我想要让上面的信息显示在JFrame上 输出格式如下:
姓名 年龄 性别 所属组
xxx 20 m 1
bbb 20 f 2
. . . .
. . . .
请问一下 我该怎么做?老师只说了要用什么枚举 我不太懂 谁能告诉我。谢谢
我建立了一个property文件:里面的字段如下:
xxx.name=xxx
xxx.sex=m
xxx.age=20
xxx.group=1
bbb.name=bbb
bbb.sex=f
bbb.age=20
bbb.group=2
等等
现在是我想要让上面的信息显示在JFrame上 输出格式如下:
姓名 年龄 性别 所属组
xxx 20 m 1
bbb 20 f 2
. . . .
. . . .
请问一下 我该怎么做?老师只说了要用什么枚举 我不太懂 谁能告诉我。谢谢
解决方案 »
- 请问,java源代码中 @Override、@Nullable 什么意思,我从网上没搜到
- 谁知道用Java怎么实现Yahoo Finance里边的那种效果??
- 两个frame窗体,如何确定程序显示时只显示其中一个?
- 求助~
- 为什么sina的页面是以.shtml结尾的后缀名?
- 我遇到的奇怪问题!!!
- 狂急,如何从字符串取出相应的字段 StringTokenizer st = new StringTokenizer(record,",");
- 一个菜问题
- 请问用VISUAL AGE FOR JAVA做应用程序那里有学习的资料,我找一个BUTTON的CLICK事件都很难呀
- 配置ini文件的一个正则表达式的问题
- Java se6为什么要实现动态脚本支持?
- javamail的两个问题,求助指点
pro.load( new FileInputStream(xxx) ) ;
private static final String fileName = "../../../personInfo.property";
public ArrayList readPro(){
Properties prop = new Properties();
ArrayList list = new ArrayList();
InputStream is = getClass().getResourceAsStream(ReadPro.fileWidthName);
prop.load(is);
String name = prop.getProperty("xxx.name");
int age = Integer.parseInt(prop.getProperty("xxx.age"));
Person p = new Person();//事先构造Person对象
p.setName(name);
p.setAge(age);
list.add(p);
return list;
}
}
最后把list绑定到JTable里
用Properties来读取信息,固定的还可以。
万一再来个
cc.name=bbb
cc.sex=f
cc.age=20
cc.group=2
或者
dd.name=bbb
dd.sex=f
dd.age=20
dd.group=2
那就头大了。
<Persons>
<Person name="" sex="" age="" group="">
</Person>
.....
</Persons>可以添加、删除、修改,任何重名的都可以添加。
wwb = Workbook.createWorkbook(targetF);
//Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
WritableSheet ws = wwb.createSheet("sheet1", 1);
// System.out.println("已经成功了创建一个可写入的工作表" + wwb);
jxl.write.WritableFont wf = new jxl.write.WritableFont(WritableFont.TIMES, 20, WritableFont.BOLD, false);
WritableCellFormat MainCellFormat = new WritableCellFormat(wf);
MainCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //设置 border 格式
MainCellFormat.setAlignment(jxl.format.Alignment.CENTRE);
MainCellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
MainCellFormat.setWrap(true); ws.mergeCells(0, 0, 5, 0);
Label labela = new Label(0, 0, "部门评价统计", MainCellFormat);
ws.addCell(labela);
String[] headers = new String[]{"部 门", "人 员", "非常满意次数", "基本满意次数", "其他各类评价次数", "好评率"}; //定义第一行
setDataLabelFormat(1, headers, ws, labela); com.xjj.sf.util.SfxzspClient client = new com.xjj.sf.util.SfxzspClient();
List orglist = client.getAllDepartMentInfo(com.xjj.util.SfConstants.getString("GROUPID")); //service的引入
CactResultService cactResultSvr = (CactResultService) SpringContext.getBean("cactResultSvr");
int[] alluserIds = null;
if (request.getParameter("orgId") != null && request.getParameter("orgId").length() > 0) {
String orgId = request.getParameter("orgId");
alluserIds = OaUtil.getUserIdByOrgId(Integer.parseInt(orgId));
} else
{
//alluserIds = OaUtil.getALLUserId();
List list = new ArrayList();
for(int i=0;i<orglist.size();i++){
TreeItem orgs = (TreeItem)orglist.get(i);
int[] userIds = OaUtil.getUserIdByOrgId(Integer.parseInt(orgs.getId()));
for(int j=0;j<userIds.length;j++) list.add(userIds[j]+"");
}
alluserIds = new int[list.size()];
for(int i=0;i<list.size();i++){
alluserIds[i] = Integer.parseInt((String)list.get(i));
}
}
// Map map = new Hashtable();
// List userlist = new ArrayList();
int position = 2; //【Excel的坐标是从0开始---注意咯 这里2 <--> 指的是第三行】
for (int i = 0; i < alluserIds.length; i++) {
int userId = alluserIds[i];
String userName = OaUtil.getUserNameById(userId); //人员
String orgName = OaUtil.getOrgNameById(OaUtil.getOrgIdByUser(userId)); //部门
find.setUserId(userId);
//非常满意数 Appri_Good
find.setResult(CactResult.Appri_Good);
int good = cactResultSvr.countUserResult(find);
//基本满意数 Appri_Gene
find.setResult(CactResult.Appri_Gene);
int gene = cactResultSvr.countUserResult(find);
//态度不好数 Appri_1
find.setResult(CactResult.Appri_1);
int appri1 = cactResultSvr.countUserResult(find);
//时间太长数 Appri_2
find.setResult(CactResult.Appri_2);
int appri2 = cactResultSvr.countUserResult(find);
//业务不熟数 Appri_3
find.setResult(CactResult.Appri_3);
int appri3 = cactResultSvr.countUserResult(find);
//有待改进 Appri_4
find.setResult(CactResult.Appri_4);
int appri4 = cactResultSvr.countUserResult(find);
//其他评价次数(态度不好数,时间太长数,业务不熟数,有待改进)
int atotal = appri1 + appri2 + appri3 + appri4;
//总评价数
int total = good + gene + appri1 + appri2 + appri3 + appri4;
//好评率
float myl = total == 0 ? 0f : ((float) (good + gene) / total) * 100; //第三行开始 进行数据的插入操作
String[] str = new String[]{orgName, userName, good + "", gene + "", atotal + "", SfUtil.showNumber(myl, null) + "%"};
setDataLabelFormat(position, str, ws, labela);
position++;
}
//从内存中写入文件中
wwb.write();
//关闭资源,释放内存
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
private void setDataLabelFormat(int position, String[] obj, WritableSheet targetExcelSheet, Label label) throws WriteException {
label = new Label(0, position, obj[0]);
targetExcelSheet.addCell(label);
label = new Label(1, position, obj[1]);
targetExcelSheet.addCell(label);
label = new Label(2, position, obj[2]);
targetExcelSheet.addCell(label);
label = new Label(3, position, obj[3]);
targetExcelSheet.addCell(label);
label = new Label(4, position, obj[4]);
targetExcelSheet.addCell(label);
label = new Label(5, position, obj[5]);
targetExcelSheet.addCell(label);
WritableCellFormat BodyCellFormat = new WritableCellFormat();
BodyCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); //设置 border 格式
BodyCellFormat.setAlignment(jxl.format.Alignment.CENTRE);
BodyCellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
BodyCellFormat.setWrap(true); targetExcelSheet.getWritableCell(0, position).setCellFormat(BodyCellFormat);
targetExcelSheet.getWritableCell(1, position).setCellFormat(BodyCellFormat);
targetExcelSheet.getWritableCell(2, position).setCellFormat(BodyCellFormat);
targetExcelSheet.getWritableCell(3, position).setCellFormat(BodyCellFormat);
targetExcelSheet.getWritableCell(4, position).setCellFormat(BodyCellFormat);
targetExcelSheet.getWritableCell(5, position).setCellFormat(BodyCellFormat); }