51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> java >> 文章正文

JEditorPane类实现显示URL资源中的HTML文件

更新时间:2012-3-17:  来源:51代码网

下面的程序通过JEditorPane类,显示URL资源中的HTML文件,当我运行程序时,窗口没有显示带滚动条的容

器ScrollPane scroll,当在text中输入百度网址http://www.751com.cn/,容器中没有任何反应,这儿出了

什么问题????
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class JEditorNet
{
public static void main(String[] args) 
  {new Win();

  }
}
class Win extends Frame implements ActionListener,Runnable
{ Button button ;
  URL url;
  TextField text;
  JEditorPane editPane;
  byte b[]=new byte[1024];
  Thread thread;
 public Win()
  { text=new TextField(20);
  editPane=new JEditorPane();
  editPane.setEditable(false);
button=new Button("确定");
button.addActionListener(this);
thread=new Thread(this);  
Panel p=new Panel();
p.add(new Label("输入网址:"));
p.add(text);
p.add(button);
ScrollPane scroll=new ScrollPane();
add(scroll,BorderLayout.CENTER);
add(p,BorderLayout.NORTH);
setBounds(160,60,360,300);
setVisible(true);
validate();
addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }
  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
  { editPane.setText(null);
url=new URL(text.getText().trim());
editPane.setPage(url);
  }
  catch(Exception el){text.setText(""+el);return;}      }}建议swing开发,都是用javax.swing.*中的组件,不要再用java.awt.*中的组件了。javax.swing.*中是轻量级的,平台无关的(除顶层容器外)。

赞助商链接
推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |