liulanqi

来源:互联网 发布:数据存储 概念 编辑:程序博客网 时间:2024/05/16 02:31
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class ReadServerFile extends JFrame{


private JTextField enterField;
private JEditorPane contentsArea;


public ReadServerFile()
{
super("web");
Container container=getContentPane();
enterField=new JTextField("url");
enterField.addActionListener(
new ActionListener(){


public void actionPerformed(ActionEvent event)
{
getThePage(event.getActionCommand());
   }
 }
);
container.add(enterField,BorderLayout.NORTH);


contentsArea=new JEditorPane();
contentsArea.setEditable(false);


contentsArea.addHyperlinkListener(
new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent event)
{
if(event.getEventType()==
HyperlinkEvent.EventType.ACTIVATED)
getThePage(event.getURL().toString());
}
});
container.add(new JScrollPane(contentsArea),
BorderLayout.CENTER);
setSize(900,700);
setVisible(true);
}


private void getThePage(String location)
{
setCursor(Cursor.getPredefinedCursor(
Cursor.WAIT_CURSOR));
try{
contentsArea.setPage(location);
enterField.setText(location);
}


catch (IOException ioException)
{
JOptionPane.showMessageDialog(this,"error retraiving",
"bad url",JOptionPane.ERROR_MESSAGE);
}
setCursor(Cursor.getPredefinedCursor(
Cursor.DEFAULT_CURSOR));
}
public static void main(String args[])
{
ReadServerFile application=new ReadServerFile();


application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
  }
  
原创粉丝点击