📄 showdocument.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
public class ShowDocument extends Applet implements ActionListener
{
AppletContext appletContext;
TextField urlField;
Choice choice;
Button button;
public void init()
{
setLayout( new GridLayout(3,1) );
appletContext = getAppletContext();
Panel p1, p2, p3;
p1 = new Panel();
Label label1 = new Label("URL of document to show:", Label.RIGHT);
p1.add(label1);
urlField = new TextField("http://www.hust.edu.cn", 40);
urlField.addActionListener(this);
p1.add(urlField);
add(p1);
p2 = new Panel();
Label label2 = new Label("Window/frame to show it in:", Label.RIGHT);
p2.add(label2);
choice = new Choice();
choice.addItem("(browser's choice)"); //don't specify
choice.addItem("My Personal Window"); //a window named "My Personal Window"
choice.addItem("_blank"); //a new, unnamed window
choice.addItem("_self");
choice.addItem("_parent");
choice.addItem("_top"); //the Frame that contained this applet
p2.add(choice);
add(p2);
p3 = new Panel();
button = new Button("Show document");
button.addActionListener(this);
p3.add(button);
add(p3);
}
public void actionPerformed(ActionEvent event)
{
String urlString = urlField.getText();
URL url = null;
try
{ url = new URL(urlString);
}catch (MalformedURLException e)
{
System.err.println("Malformed URL: " + urlString);
}
if (url != null)
{
if (choice.getSelectedIndex() == 0)
{
appletContext.showDocument(url);
}
else
{
appletContext.showDocument(url, choice.getSelectedItem());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -