📄 appletapp.java
字号:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class AppletApp extends Applet {
// 普通应用程序需要main( )方法
public static void main(String args[]) {
// 构造一个用于放置Applet的框架
Frame frame = new Frame("Application");
// 创建本类(Applet)的一个实例
AppletApp app = new AppletApp( );
// 将Applet放到框架的中部
frame.add("Center",app);
frame.setSize(200,200);
frame.validate( );
frame.setVisible(true);
// 为窗口事件注册监听程序
frame.addWindowListener(new WindowControl(app));
// 调用Applet的方法
app.init( );
app.start( );
} // main( )方法结束
public void paint(Graphics g) {
g.drawString("Hello World", 25,25);
}
public void destroy( ) {
System.exit(0);
}
}
// 监听窗口事件的类
class WindowControl extends WindowAdapter {
Applet c;
public WindowControl (Applet c) {
this.c = c;
}
public void windowClosing(WindowEvent e) {
c.destroy( );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -