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

网页源文件查看器

来源: 作者: 时间:2007-09-29 点击:
  有些网页是屏蔽了鼠标右键的,不让我们查看它的源代码或者不让我们点击鼠标右键,在此我们可以写一个程序,让它获得这个网页的流,然后我们不就什么都能看到了吗?此程序就是这样写的,先获得网页的输入流,然后得到这个输入流的一些参数,比如这个流的长度,这个流所使用的编码.然后根据这些参数来进行获取,并根据不同的情况提供不同的进度条,比如有些网页它的长度返回的是-1,这个时候就用一个无状态的进度条来表示,如果长度大于0的话,那就用可以实时显示目前读取网页的进度.正好借这个机会又把swing复习了一下.呵呵.

  运行时的图片如下:

下面是代码.

/*
* Test4.java
*
* Created on 2007年9月27日, 下午3:05
*/

package test2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author hadeslee
*/
public class Test4 extends javax.swing.JFrame {

private Task task; //只存在的一个方法

/** Creates new form Test4 */
public Test4() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exe) {
exe.printStackTrace();
}
initComponents();
jpb.setStringPainted(true);
jpb.setVisible(false);
this.setLocationRelativeTo(null);
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
input = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
output = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jpb = new javax.swing.JProgressBar();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("查看网页源文件");
setResizable(false);

jLabel1.setForeground(new java.awt.Color(51, 51, 255));
jLabel1.setText("地址");

input.setForeground(new java.awt.Color(51, 51, 255));
input.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inputActionPerformed(evt);
}
});

jButton1.setForeground(new java.awt.Color(51, 51, 255));
jButton1.setText("查看");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("源文件"));

output.setColumns(20);
output.setEditable(false);
output.setLineWrap(true);
output.setRows(5);
output.setWrapStyleWord(true);
jScrollPane1.setViewportView(output);

jButton2.setText("保存");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("退出");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

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