/**
* 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 classHttpBrowserDemo extends JFrame{
JTextField jtfAddress;
JButton jbGo;
JTextPane jtpShow;
JLabel jlInfo;publicHttpBrowserDemo(){
super("html");
jtfAddress=new JTextField(20);
jbGo=new JButton("转到");
jtpShow=newJTextPane();
jlInfo=newJLabel();
JPanel panel=newJPanel();
panel.add(new JLabel("地址"));
panel.add(jtfAddress);
panel.add(jbGo);
JScrollPane jsp=newJScrollPane(jtpShow);
Container container=getContentPane();
container.add(panel,BorderLayout.NORTH);
container.add(jsp,BorderLayout.CENTER);
container.add(jlInfo,BorderLayout.SOUTH);
jbGo.addActionListener(newShowHTMLListener());
jtfAddress.addActionListener(newShowHTMLListener());
setSize(350,280);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}classShowHTMLListener implements ActionListener{
@Overridepublic voidactionPerformed(ActionEvent e) {//TODO Auto-generated method stub
try{
jlInfo.setText("正在链接...");
URL address=newURL(jtfAddress.getText());
jtpShow.setPage(address);
jlInfo.setText("完成");
}catch(Exception ex){
jlInfo.setText("链接出错,请输入正确的URL地址!");
ex.printStackTrace();
}
}
}public static voidmain(String[] args) {newHttpBrowserDemo();
}
}