离线网页制作器(beta1.0)

 package hhuarongdao;
/*
*使用方法: 先选择保存路径,然后输入相应的网址,
*然后会得到那个网页的离线版的 内容
* */
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField; public class stu {
public static void main(String args []){
setBjing mybe= new setBjing();
}
} class mywndow extends JFrame
{
mywndow(String title){
setTitle(title);
setBounds(200,100 ,400,300);
this.setResizable(false);
}
}
//设置一个背景
class setBjing implements ActionListener
{
URL url;
look it=new look();
Thread readurl;
Container com;
JButton button,button1 ;
JTextField text,mytext ;
setBjing(){
mywndow hehe =new mywndow("离线网页制作器1.bate");
com=hehe.getContentPane();
com.setLayout(new FlowLayout());
mytext =new JTextField(20);
mytext.setEditable(false); //设置成为不能
mytext.setFont(new Font("Arial",Font.BOLD,22));
button1 = new JButton("选择路径");
button1.addActionListener(this);
button = new JButton("Submitt");
button.addActionListener(this);
text = new JTextField(20);
text.addActionListener(this);
JLabel label = new JLabel("输入网址,如:http://www.baidu.com");
com.add(label);
com.add(text);
com.add(button);
com.add(button1);
com.add(mytext);
hehe.setVisible(true);
hehe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//text.setText("输入网址,例如:http://www.baidu.com");
}
public void work(String ss){
try {
url = new URL(ss);
it.setURL(url);
readurl = new Thread(it);
readurl.start();
}
catch (Exception exp)
{
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(text,exp,"离线网页制作器1.bate",JOptionPane.ERROR_MESSAGE);
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==button){
String ss=text.getText().toString().trim();
work(ss);
text.setText(null);
}
else if(e.getSource()==button1){
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("D:/")); //默认路径为D盘
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//文件选择模式,只读
int index = chooser.showDialog(null, "确定");
if(index==chooser.APPROVE_OPTION){
it.setPath(chooser.getSelectedFile().getAbsolutePath());
mytext.setText(chooser.getSelectedFile().getAbsolutePath().toString());
//validate();
}
}
}
}
class look implements Runnable
{
URL url;
public File fwrite = new File("url.html");
void setPath(String road)
{
fwrite = new File(road+".html");
}
public void setURL(URL url){
this.url=url;
}
@Override
public void run() {
// TODO Auto-generated method stub
try{
OutputStream out = new FileOutputStream(fwrite,true);
InputStream in=url.openStream();
byte [] a=new byte [1024];
int n=-1;
while( (n=in.read(a))!=-1 ){
out.write(a, 0,n);
}
out.close();
JOptionPane.showMessageDialog(null,"保存成功!","离线网页制作器1.bate",JOptionPane.ERROR_MESSAGE);
}
catch(IOException e){
JOptionPane.showMessageDialog(null,"文件保存失败!","离线网页制作器1.bate",JOptionPane.ERROR_MESSAGE);
};
}
}

离线网页制作器(beta1.0)离线网页制作器(beta1.0)

上一篇:C#中的斜变性和逆变性的详解


下一篇:QT5.1.0,QT4.8.0以及VC2010、VC2012的测试对比