当前位置:主页 > 行业指南 >

网页源文件查看器

发布时间:19-12-06 阅读:877

有些网页是樊篱了鼠标右键的,不让我们查看它的源代码或者不让我们点击鼠标右键,在此我们可以写一个法度榜样,让它得到这个网页的流,然后我们不就什么都能看到了吗?此法度榜样便是这样写的,先得到网页的输入流,然后获得这个输入流的一些参数,比如这个流的长度,这个流所应用的编码.然后根据这些参数来进行获取,并根据不合的环境供给不合的进度条,比如有些网页它的长度返回的是-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) {



上一篇:刘晓庆帅气干练:上围丰满身姿挺拔,刘晓庆年轻
下一篇:没有了