url = (String)history.get(historyIndex);
jEditorPane1.setPage(url);
jurl.setText(url.toString());
jEditorPane1.setEditable(false); //add by copy editor :)
jEditorPane1.revalidate ();
}
catch(Exception ex){
}
}
//全屏
else if (e.getSource() == fullscreenItem){
boolean add_button2=true;
//获得屏幕大小
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Container content = window.getContentPane();
content.add (bar,"North");
content.add (scrollPane,"Center");
//button2为点击“全屏”后的还原按钮
if(add_button2==true) {
bar.add (button2);
}
//为button2添加事件
button2.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent evt) {
WebBrowser.this.setEnabled (true);
window.remove (bar);
window.remove (toolBar);
window.remove (scrollPane);
window.setVisible (false);
scrollPane.setPreferredSize (new Dimension (100,500));
getContentPane ().add (scrollPane,BorderLayout.SOUTH);
getContentPane ().add (bar,BorderLayout.CENTER);
getContentPane ().add (toolBar,BorderLayout.NORTH);
bar.remove (button2);
pack();
}
});
window.setSize (size);
window.setVisible (true);
}
//查看源文件
else if (e.getSource() == sourceItem ||e.getSource() == picView){
url = jurl.getText ().toString ().trim ();
if(url.length ()0!url.startsWith ("http://")) {
url="http://"+url;
}
if( !url.equals ("")) {
//根据url,获得源代码
getHtmlSource (url);
//生成显示源代码的框架对象
ViewSourceFrame vsframe = new ViewSourceFrame (htmlSource);
vsframe.setBounds (0,0,800,500);
vsframe.setVisible(true);
}
else {
JOptionPane.showMessageDialog (WebBrowser.this,"请输入链接地址","网页浏览器",JOptionPane.ERROR_MESSAGE);
}
}
//刷新
else if (e.getSource() == reloadItem){
url=jurl.getText ();
if(url.length ()0url.startsWith ("http://")) {
try {
jEditorPane1.setPage (url);
jEditorPane1.setEditable(false); //add by copy editor :)
jEditorPane1.revalidate ();
}
catch(Exception ex) {
}
}
else if(url.length ()0!url.startsWith ("http://")) {
url="http://"+url;
try {
jEditorPane1.setPage (url );
jEditorPane1.setEditable(false); //add by copy editor :)
jEditorPane1.revalidate ();
}
catch(Exception ex) {
}
}
}
}
/*
**保存文件
*/
void saveFile (final String url) {
final String linesep = System.getProperty ("line.separator");
chooser1.setCurrentDirectory (new File ("."));
chooser1.setDialogType (JFileChooser.SAVE_DIALOG);
chooser1.setDialogTitle ("另存为...");
if(chooser1.showSaveDialog (this) != JFileChooser.APPROVE_OPTION)
return;
this.repaint ();
Thread thread = new Thread () {
public void run () {
try {
java.net.URL source = new URL (url);
InputStream in = new BufferedInputStream (source.openStream ());
BufferedReader br=new BufferedReader (new InputStreamReader (in));
File fileName = chooser1.getSelectedFile ();
FileWriter out = new FileWriter (fileName);
BufferedWriter bw = new BufferedWriter (out);
String line;
while((line = br.readLine ()) != null) {
bw.write (line);
bw.newLine ();
}
bw.flush ();
bw.close ();
out.close ();
String dMessage = url + " 已经被保存至"+ linesep +fileName.getAbsolutePath ();
String dTitle = "另存为";
int dType = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog ((Component) null,dMessage,dTitle,dType);
}
catch(java.net.MalformedURLException muex) {
推荐阅读
- html介绍美食网页简单代码,美食网页设计源代码
- 狐狸为什么会吃人视频,为什么狐狸吃人肝
- 手机里怎么设置小程序,手机如何设置小程序
- jquery全选获取tabletd,用jquery实现全选全不选反选
- 如何用php显示表格数据 php表格显示数据库信息
- 关于软通c语言外包是做什么的的信息
- 遭遇了网络游戏诈骗英语,网络诈骗犯的英文
- 茶行如何营销产品,茶业如何销售
- go语言自学web go语言自学多久能入职