三个问题,一个100分

dongle2001 2006-07-26 02:03:26
1.我使用JTable存储一个Boolean字段,显示的时候用JCheckBox。自定义的TableModel实现了下面的两个函数。
/**
*<br>方法说明:实现这个方法使得最后一列不是显示true和false。而是使用检查盒
*<br>输入参数:
*<br>返回类型:
*/
public Class getColumnClass(int c) {
if (getValueAt(0, c) != null) {
return getValueAt(0, c).getClass();
}
else {
return new String().getClass();
}
}

/**
*<br>方法说明:单元格是否可可编辑
*<br>输入参数:rowIndex:int 行 columnIndex:int 列
*<br>返回类型:true or false
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 1) {
return true;
}
else {
return false;
}
}
当点击JCheckBox的时候,JTable会改变Boolean的值。我想把它修改后的值写回数据库应该怎么办。应该如何得到JTable自动修改的事件。
2.我使用下面的函数得到网页的字符串,并且将得到的字符串写入JDataStore数据库,然后再从数据库中取出放到Jtable中。现在的问题是如果网页编码是GB2312没问题,但是如果如果网页编码是UTF-8,显示的字符串会变成乱码,应该如何转换?
public static String getHtmlText(String strUrl) {
if (strUrl == null || strUrl.length() == 0) {
return null;
}

String strHtml = "";
String strLine = "";
try {

//链接网络得到网页源代码
URL url = new URL(strUrl);
HttpURLConnection pconn = (HttpURLConnection) url.openConnection();
pconn.addRequestProperty("User-Agent", "IcewolfHttp/1.0");
pconn.addRequestProperty("Accept",
"www/source; text/html; image/gif; */*");

pconn.connect();
//System.out.println("Connect status:"+pconn.getResponseCode());
//if(HttpURLConnection.HTTP_ACCEPTED == pconn.getResponseCode())
//InputStream in = url.openConnection();

InputStream in = pconn.getInputStream();
//System.out.println("Get status:"+pconn.getResponseCode());
BufferedInputStream buff = new BufferedInputStream(in);
Reader r = new InputStreamReader(buff);
BufferedReader br = new BufferedReader(r);

while ( (strLine = br.readLine()) != null) {
strHtml += strLine;
}
//strHtml = UnToWC(strHtml);
br.close();
buff.close();
in.close();
pconn.disconnect();
}
catch (MalformedURLException mfe) {
System.err.println("url is not a parsable URL");
}
catch (IOException ioe) {
System.err.println(ioe);
}

return strHtml;
}
3.使用JTextpane显示网页字符串(由于显示经常要更新,所以不能用setPage),如何能够响应单击链接事件,新建IE,打开网页。如果不行,有别的方法吗。
tpJtp.setContentType("text/html");
tpJtp.setText("<a href=www.csdn.net>www.csdn.net</a>");
tpJtp.repaint();
...全文
326 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongle2001 2006-08-12
  • 打赏
  • 举报
回复
都没解决问题
quanquan626 2006-07-28
  • 打赏
  • 举报
回复
up
dongle2001 2006-07-28
  • 打赏
  • 举报
回复
就剩编码问题没有解决了。
dongle2001 2006-07-28
  • 打赏
  • 举报
回复
我有开了一帖,大家可以看看。
http://community.csdn.net/Expert/TopicView.asp?id=4911773
Samuel_831 2006-07-27
  • 打赏
  • 举报
回复
第2个问题把:
Reader r = new InputStreamReader(buff);
写成:
Reader r = new InputStreamReader(buff,"UTF-8");
就OK了.我刚遇到过编码问题.如果写成:
Reader r = new InputStreamReader(buff,"gb2312");
就按gb2312的方式读取.
如果还不行,把页面点开用另存为看看下面的编码是否是你要的编码,如果还不行看看你的
工具软件的默认编码对不对,比如eclips有个edit菜单下面有个set encoding选项.
我也是新手,说错了后面的大大帮忙指出下.
super_jj 2006-07-27
  • 打赏
  • 举报
回复
太早了,高手都没来
dongle2001 2006-07-27
  • 打赏
  • 举报
回复
没人会吗
dongle2001 2006-07-26
  • 打赏
  • 举报
回复
解答出另开贴给分。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧