📄 ch8_e8_30.java
字号:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class ch8_e8_30 extends Applet implements ActionListener
{
final String presetURL = "http://www.tsinghua.edu.cn";
TextField inputURLTfd = new TextField(20);
public void init()
{
add(inputURLTfd);
inputURLTfd.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource() == inputURLTfd)
{
String str = inputURLTfd.getText().trim();
if(str.equals(presetURL))
{
URL myURL = new URL(str);
getAppletContext().showDocument(myURL);
}
else
{
showStatus("对不起,不能访问该地址。");
}
}
}
catch(MalformedURLException murle)
{
showStatus("输入的网络资源地址有误");
inputURLTfd.setText("");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -