📄 scence.java
字号:
package like.scence2D;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import like.graphics.*;
public class Scence extends Frame
implements Runnable,KeyListener
{
protected Hashtable htPros;
protected ScenceManger sm;
protected boolean stop;
protected long zhenTime;
protected int fullWidth,fullHeight;
protected boolean ifFullScreen;
protected Thread repaint;
public Scence(ScenceManger sm)
{
this.sm = sm;
this.htPros = sm.getHtPros();
}
public Hashtable getHtpros() {return this.htPros;}
//生命周期
public void init()
{
this.fullWidth = 800;
this.fullHeight = 600;
AnimationStrip.observer = this;
this.stop = true;
this.zhenTime = 20;
this.ifFullScreen = false;
//添加事件监听
this.addKeyListener(this);
this.toFullScreen();
this.start();
}
public void start()
{
//重绘线程
repaint = new Thread(this);
repaint.start();
this.stop = false;
}
public void stop()
{
this.stop = true;
}
public void over()
{
this.stop();
this.repaint = null;
}
/**
*设置为全屏模式
*/
public void toFullScreen()
{
if(!ifFullScreen)
{
if(sm.changeMode(this,fullWidth,fullHeight)) ifFullScreen = true;
else System.out.println("您的电脑不允许全屏显示");
}
}//end method toFullScreen()
/**
*设置为窗口模式
*/
public void toWindow()
{
if(ifFullScreen)
{
sm.changeMode(this,fullWidth,fullHeight);
this.ifFullScreen = false;
}
}//end method toWindow()
/**
* Method run
*
*
*/
public void run()
{
while(Thread.currentThread()==this.repaint)
{
long str,end;
str = end = 0;
if(!stop)
{
str = System.currentTimeMillis();
//this.repaint();
this.update(this.getGraphics());
end = System.currentTimeMillis();
}
end -= str;
//if(end>zhenTime) System.out.println("刷新时间:"+end);
try
{
if(end>zhenTime)
Thread.sleep(5);
else
Thread.sleep(zhenTime-end);
}
catch(Exception e)
{e.printStackTrace();}
}
}//end method run()
public void keyTyped(KeyEvent e)
{
// TODO: 在这添加你的代码
}
public void keyPressed(KeyEvent e)
{
// TODO: 在这添加你的代码
}
public void keyReleased(KeyEvent e)
{
// TODO: 在这添加你的代码
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -