//本程序前提是必须要有Tomcat服务器,打开后才能运行 //否则自己做一个服务器
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.net.*;
class MyIEGui
{
private static Frame f;
private static Button but;
private static TextField tf;
private static Dialog dl;
private static Label lab;
private static Button okbut;
private static TextArea ta;
public static void main(String[] args)
{
init();
}
private static void init()
{
f=new Frame("my window");
f.setBounds(300,200,500,400);
f.setLayout(new FlowLayout());
but=new Button("转到");
tf=new TextField(53);
ta=new TextArea(19,60);
f.add(tf);
f.add(but);
f.add(ta);
dl=new Dialog(f,"错误信息",true);
dl.setBounds(350,250,240,120);
dl.setLayout(new FlowLayout());
lab=new Label();
okbut=new Button("确定");
dl.add(lab);
dl.add(okbut);
event();
f.setVisible(true);
}
private static void event()
{
tf.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
try
{
show();
}
catch (Exception ee)
{
throw new RuntimeException("路径错误");
}
}
}
});
okbut.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
try
{
show();
}
catch (Exception es)
{
throw new RuntimeException("路径错误");
}
}
}
});
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
dl.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dl.setVisible(false);
}
} );
okbut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
dl.setVisible(false);
}
});
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try
{
show();
}
catch (Exception ex)
{
throw new RuntimeException("路径错误");
}
}
});
}
private static void show()throws Exception
{
ta.setText("");
String urlpath=tf.getText();//获取输入框信息http://127.0.0.1:8080/myweb/demo.html
URL url=new URL(urlpath);
URLConnection conn=url.openConnection();//它表示到 URL 所引用的远程对象的连接。
InputStream ins=conn.getInputStream();//获取连接读取的输入流
byte[] by=new byte[1024*1024*100];
int len=ins.read(by);
ta.append(new String(by,0,len));
}
}
|