📄 appletiedemo.java
字号:
package applet;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
public class AppletIEDemo extends Applet {
JButton jButton1 = new JButton();
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setText("显示Java官方网站");
//为按钮加入动作接收器
jButton1.addActionListener(new AppletIEDemo_jButton1_actionAdapter(this));
//为Applet加入按钮
this.add(jButton1, null);
}
//按钮的动作事件
void jButton1_actionPerformed(ActionEvent e) {
//获取Applet的AppletContext接口
AppletContext appletContext = this.getAppletContext();
//在新的窗口显示java网站
try {
appletContext.showDocument(new URL("http://java.sun.com"), "_blank");
}
catch (Exception el) {}
}
}
//创建动作接收器类
class AppletIEDemo_jButton1_actionAdapter implements java.awt.event.ActionListener {
AppletIEDemo adaptee;
AppletIEDemo_jButton1_actionAdapter(AppletIEDemo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -