📄 example9_9.java
字号:
/*
* Example9_9.java
*
* Created on 2006年10月19日, 下午12:17
*/
package example9_9;
import java.awt.*;
/**
* @author Administrator
*/
public class Example9_9 extends java.applet.Applet implements Runnable{
/** Initializes the applet Example9_9 */
/* public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}*/
int frame;int delay;Thread animator;
// 初始化界面,定义帧刷新频率
public void init() {
String str = getParameter("fps");
int fps = (str!=null) ? Integer.parseInt(str) : 10; // fps表示每秒的帧数
delay = (fps>0) ? (1000 / fps) : 100;
}
// 创建一个新线程并使之开始运行
public void start() {
animator = new Thread(this); animator.start();
}
// 在run方法中实现主要的动画循环
public void run() {
long tm = System.currentTimeMillis();
while (Thread.currentThread() == animator) {
repaint(); // 显示下一帧
try {
tm += delay; // 等待一定的时间
Thread.sleep(Math.max(0,tm -System.currentTimeMillis()));
}
catch(InterruptedException e) {break;}
frame ++; // 切换到下一帧
}
}
// 当applet不再可见时停止操作
public void stop() {animator = null;}
//画图
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawString("Frame" + frame, 0 , 30);
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(new java.awt.BorderLayout());
}
// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -