import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;public class ExampleURL {
public static void main(String[] args){
new NetOne();
}
}class NetOne extends JFrame implements ActionListener, Runnable
{
JButton button;
URL url;
JEditorPane editPane;
JTextField text;
byte b[]=new byte[118];
Thread thread;
NetOne()
{
text = new JTextField(20);
button = new JButton("确定");
button.addActionListener(this);
thread = new Thread(this); JPanel p = new JPanel();
p.add(new JLabel("请输入网址:"));
p.add(text);
p.add(button);
editPane = new JEditorPane();
editPane.setEditable(false);
Container con =getContentPane();
con.add(new JScrollPane(editPane), BorderLayout.CENTER);
con.add(p, BorderLayout.NORTH); setBounds(60,60,500,400);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editPane.addHyperlinkListener(new HypherlinkListener(){
public void hypherlinkUpdate(HypherlinkEvent e){
if(e.getEventType()==HypherlinkEvent.EventType.ACTIVATED){
try{ editPane.setPage(e.getURL);}
catch(IOException e1){editPane.setText(""+e1);}
}
}
});
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
thread = new Thread(this);
try{thread.start();}
catch (Exception ee){ text.setText("我正在读取"+url); }
}
public void run()
{
try{ int n=1;
editPane.setText(null);
url = new URL(text.getText().trim());//获取text中去空格的字符串
editPane.setPage(url);
}
catch(MalformedURLException e1){
text.setText(""+e1);
return ;
}
catch(IOException e1){
text.setText(""+e1);
return ;
}
}
}
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;public class ExampleURL {
public static void main(String[] args){
new NetOne();
}
}class NetOne extends JFrame implements ActionListener, Runnable
{
JButton button;
URL url;
JEditorPane editPane;
JTextField text;
byte b[]=new byte[118];
Thread thread;
NetOne()
{
text = new JTextField(20);
button = new JButton("确定");
button.addActionListener(this);
thread = new Thread(this); JPanel p = new JPanel();
p.add(new JLabel("请输入网址:"));
p.add(text);
p.add(button);
editPane = new JEditorPane();
editPane.setEditable(false);
Container con =getContentPane();
con.add(new JScrollPane(editPane), BorderLayout.CENTER);
con.add(p, BorderLayout.NORTH); setBounds(60,60,500,400);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editPane.addHyperlinkListener(new HypherlinkListener(){
public void hypherlinkUpdate(HypherlinkEvent e){
if(e.getEventType()==HypherlinkEvent.EventType.ACTIVATED){
try{ editPane.setPage(e.getURL);}
catch(IOException e1){editPane.setText(""+e1);}
}
}
});
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
thread = new Thread(this);
try{thread.start();}
catch (Exception ee){ text.setText("我正在读取"+url); }
}
public void run()
{
try{ int n=1;
editPane.setText(null);
url = new URL(text.getText().trim());//获取text中去空格的字符串
editPane.setPage(url);
}
catch(MalformedURLException e1){
text.setText(""+e1);
return ;
}
catch(IOException e1){
text.setText(""+e1);
return ;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货