RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>Java>列表

网页源文件查看器

来源: 作者: 时间:2007-09-29 点击:

output.setText(null);
while (br.ready()) {
time = System.currentTimeMillis();
temp = br.readLine();
if (isCanceled) {
return;
}
output.append(temp + "\r\n");
}
System.out.println("读到底了");
isCanceled = true;
jpb.setIndeterminate(false);
jpb.setVisible(false);
} else {
//如果知道长度多长,就可以显示一个进度条,等所有的字节都读完再显示
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int data = -1;
while ((data = is.read()) != -1) {
if (isCanceled) {
return;
}
time = System.currentTimeMillis();
if (length > 0) {
done++;
jpb.setValue(done);
int rate = done * 100 / length;
jpb.setString("" + rate + "%");
}
bout.write(data);
//如果长度不为-1,并且已经读了这么多长度以后,就要断线了
if (done == length) {
String text = null;
byte[] b = bout.toByteArray();
if (encoding == null) {
text = new String(b);
} else {
text = new String(b, encoding);
}
if (!isCanceled) {
output.setText(text);
}
isCanceled = true;
jpb.setVisible(false);
return;
}
}
}
} catch (IOException ex) {
Logger.getLogger(Test4.class.getName()).log(Level.SEVERE, null, ex);
if (isCanceled) {
return;
} else {
JOptionPane.showMessageDialog(Test4.this, "打开网页失败!!");
}
} catch (Exception exe) {
if (isCanceled) {
return;
} else {
JOptionPane.showMessageDialog(Test4.this, "打开网页失败!!");
}
} finally {
try {
if (is != null) {
is.close();
}
jpb.setVisible(false);
} catch (IOException ex) {
Logger.getLogger(Test4.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

public void cancel() {
isCanceled = true;
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new Test4().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField input;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JProgressBar jpb;
private javax.swing.JTextArea output;
// End of variables declaration
}

  我是用NetBeans写的,程序部份都有注释,界面部份是拖出来的,以前我很不喜欢拖控件的,所有的界面都是自己手写代码,后来发现NetBeans的拖控件功能确实很强,应该说是JAVA IDE里面最强的了.

共4页: 上一页 [1] [2] [3] 4 下一页
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
Google Adsense
相关文章