📄 browserframe.java
字号:
//BrowserFrame.java//The frame which contains the interface componentsimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;public class BrowserFrame extends JFrame{ //各个控件 private WebWindow ww = new WebWindow(this); private MenuBar mb = new MenuBar(this); private ToolBar tb = new ToolBar(this); private HistoryList hl = new HistoryList();//历史记录 private String sURL;//替代URL public BrowserFrame(){ //Frame和各个成员的位置 setTitle("Show");//Frame setSize(640, 480); setLocation(20, 20); getContentPane().setLayout(new BorderLayout()); setJMenuBar(mb);//MenuBar JPanel jpToolMenu = new JPanel();//the toolbar jpToolMenu.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); jpToolMenu.add(tb); getContentPane().add(jpToolMenu, BorderLayout.NORTH); getContentPane().add(ww, BorderLayout.CENTER); setCurrentURL("http://www.zsu.edu.cn"); } public void setToolBarURL(String s) {//将 url 记录在 toolbars text field tb.setTextField(s); }//***************************后退按钮******************************* public void goBack() { try { sURL = hl.getLast();//得到 previous URL ww.setCurrentURL(sURL);//显示 it setToolBarURL(sURL); //更改 toolbar text field } catch(Exception e) { new PopupDialog("错误!", e.getMessage()); } }//***************************前进按钮******************************* public void goForward() { //结构同后退按钮 try { sURL = hl.getNext(); ww.setCurrentURL(sURL); setToolBarURL(sURL); } catch(Exception e) { new PopupDialog("错误", e.getMessage()); } }//***************************刷新按钮******************************* public void refreshURL() { //结构同后退按钮 try { ww.setCurrentURL(sURL); setToolBarURL(sURL); } catch(Exception e) { new PopupDialog("错误!", e.getMessage()); } } public String getCurrentURL() {//记录当前的URL return sURL; } public void setCurrentURL(String current) {//设置当前URL if (!(current.substring(0, 7)).equals("http://")) { if(!(current.substring(0, 3)).equals("www")) current = "www."+current; current = "http://"+current;//确保URL的格式正确 } sURL = current;//使得URL为current值 try { ww.setCurrentURL(sURL);//转动该网页 hl.add(sURL); //加入历史记录 setToolBarURL(sURL);//更改toolbar text field } catch(Exception e) { new PopupDialog("错误!", e.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -