/**
* Created by Admin on 2017/3/27.
*/
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane; public class HttpBrowserDemo extends JFrame{
JTextField jtfAddress;
JButton jbGo;
JTextPane jtpShow;
JLabel jlInfo; public HttpBrowserDemo(){
super("html");
jtfAddress=new JTextField();
jbGo=new JButton("转到");
jtpShow=new JTextPane();
jlInfo=new JLabel(); JPanel panel=new JPanel();
panel.add(new JLabel("地址"));
panel.add(jtfAddress);
panel.add(jbGo);
JScrollPane jsp=new JScrollPane(jtpShow);
Container container = getContentPane();
container.add(panel,BorderLayout.NORTH);
container.add(jsp,BorderLayout.CENTER);
container.add(jlInfo,BorderLayout.SOUTH); jbGo.addActionListener(new ShowHTMLListener());
jtfAddress.addActionListener(new ShowHTMLListener()); setSize(,);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} class ShowHTMLListener implements ActionListener{ @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try{
jlInfo.setText("正在链接...");
URL address=new URL(jtfAddress.getText());
jtpShow.setPage(address);
jlInfo.setText("完成");
}
catch(Exception ex){
jlInfo.setText("链接出错,请输入正确的URL地址!");
ex.printStackTrace();
}
} } public static void main(String[] args) {
new HttpBrowserDemo();
}
}