?? appletbrowser.java.bak
字號:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
/**類AppletBrowser是Applet的子類,并實(shí)現(xiàn)了ActionListener接口*/
public class AppletBrowser extends Applet implements ActionListener{
TextField tfObj;
Choice choiceObj;
/**方法init()用于布置組件的大小和位置*/
public void init(){
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
Label labelObj1 = new Label("需要顯示對象的URL:",Label.RIGHT);
gridBag.setConstraints(labelObj1,c);
add(labelObj1);
//tfObj用于用戶輸入需要顯示的URL對象
tfObj = new TextField("http://www.tsinghua.edu.cn/",35);
tfObj.addActionListener(this);
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1.0;
gridBag.setConstraints(tfObj,c);
add(tfObj);
Label labelObj2 = new Label("Window/frame to show it in:",Label.RIGHT);
c.gridwidth = 1;
c.weightx = 0.0;
gridBag.setConstraints(labelObj2,c);
add(labelObj2);
/*choiceObj對象用于選擇顯示URL對象的窗口類型*/
choiceObj = new Choice();
choiceObj.addItem("(選擇瀏覽器窗口類型)");
choiceObj.addItem("_blank");
choiceObj.addItem("_self");
choiceObj.addItem("_parent");
choiceObj.addItem("_top");
c.fill = GridBagConstraints.NONE;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.WEST;
gridBag.setConstraints(choiceObj,c);
add(choiceObj);
/*按鈕button用于執(zhí)行頁面的顯示操作*/
Button button = new Button("顯示頁面");
button.addActionListener(this);
c.weighty = 1.0;
c.ipadx = 10;
c.ipady = 10;
c.insets =new Insets(5,0,0,0);
c.anchor = GridBagConstraints.SOUTH;
gridBag.setConstraints(button,c);
add(button);
}
/**方法actionPerformed用于處理界面事件*/
public void actionPerformed(ActionEvent event){
String urlString = tfObj.getText();
URL url = null;
try{
url = new URL(urlString);
}catch(MalformedURLException e){
System.err.println("Malformed URL:"+urlString);
}
/*下面的語句中通過showDocument方法顯示url對象對應(yīng)的頁面*/
if(url != null){
if(choiceObj.getSelectedIndex()==0){
getAppletContext().showDocument(url);
}else{
getAppletContext().showDocument(url,choiceObj.getSelectedItem());
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -