swing载入HTML,Swing使用JEditorPane显示HTML内容

鲁华皓
2023-12-01

5. 加载HTML内容

/**

*

* @param type

* @param string

* @return

*/

private String buildDataListStr(String type, String prefix){

String strHtml = "";

//1.判断不需要返回内容的情况

if(!mapList.containsKey(type))

return strHtml;

List itemList = mapList.get(type);

if(itemList.size() < 1)

return strHtml;

//2.填充内容行

int index = 0;

//合计金额

double sum = 0;

//内容行

String strContentLine = "";

for (AccountSnapItemData itemData : itemList) {

if(itemData.getSum() == 0)

continue;

strContentLine += "

"

+"

"+(++index)+""

+ "

"+itemData.getAccountTitle()+""

+ "

"+itemData.getMember()+""

+ "

"+itemData.getSum()+""

+"

";

sum += itemData.getSum();

}

if(strContentLine.isEmpty())

return strHtml;

//3.返回拼凑内容

strHtml += "

"+prefix+type+"(合计:"+DataFormater.getDecimalFormat().format(sum)+"元)"+"

";

strHtml += "

strHtml += "

"

+"

序号"

+"

账户名称"

+"

家庭成员"

+"

余额"

+"

";

strHtml += strContentLine;

strHtml += "

";

return strHtml;

}

/**

* 构建html字符串

* @return

*/

private String generateHTML(String dateLabel) {

String strSnapTime = null;

try {

if(dateLabel.equals("最新")){

this.loadCurrentItemList();

strSnapTime = DataFormater.getDateTimeFormat().format(Calendar.getInstance().getTime());

}

else{

this.loadHistoryItemList(dateLabel);

if(mapList.size()<1)

return "

对应快照数据为空!

";

for( String item : mapList.keySet()) {

List snapList = mapList.get(item);

for (AccountSnapItemData snapItem : snapList) {

strSnapTime = snapItem.getSnapTime();

break;

}

if(strSnapTime != null)

break;

}

}

} catch (NormalException e) {

e.printStackTrace();

}

String strHtml = "

财务概况

";

strHtml += "

" ;

strHtml += buildDataListStr("储蓄账户","1.  ");

strHtml += buildDataListStr("信用账户","2.  ");

strHtml += buildDataListStr("理财账户","3.  ");

strHtml += buildDataListStr("社保账户","4.  ");

strHtml += buildDataListStr("公积金","5.  ");

strHtml += buildDataListStr("消费卡/券","6.  ");

strHtml += "

";

if(strSnapTime != null){

strHtml += "

统计时间:" + strSnapTime

+ "

";

}

if (dateLabel.equals("最新")) {

strHtml += "

";

}

return strHtml;

}

【发表评论0条 】

 类似资料: