📄 offscreen.java
字号:
package eatbean;
import java.awt.*;
//import java.awt.image.BufferedImage;
//
import eatbean.conf.*;
import eatbean.event.ScreenEvent;
import eatbean.event.ScreenListener;
public class OffScreen {
private static OffScreen instance = null;
/** 真正的客户区 */
private Container screen = null;
/** 缓冲 */
private Image offImg = null;
private Graphics offGraphics = null;
private int width, height;
private static Color bgColor = Color.black;
private ScreenListener screenListener = null;
private ScreenEvent se = new ScreenEvent(this);
private Object syncScrObj = new Object();
private OffScreen(Container c) {
screen = c;
width = SysParam.GAME_SCREEN_WIDTH;
height = SysParam.GAME_SCREEN_HEIGHT + 30;
//
//offImg = (Image)new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB);
//
offImg = c.createImage(width, height);
offGraphics = offImg.getGraphics();
offGraphics.setColor(bgColor);
offGraphics.fillRect(0, 0, width, height);
}
public int getWidth() { return width; }
public int getHeight() { return height; }
synchronized public static OffScreen getInstance(Container c) {
if(instance == null) instance = new OffScreen(c);
return instance;
}
//synchronized
public void drawImage(Image img, int x, int y) {
offGraphics.drawImage(img, x, y, null);
}
//synchronized
public void fillRect(Color color, int x, int y, int w, int h) {
Color bakColor = offGraphics.getColor();
offGraphics.setColor(color);
offGraphics.fillRect(x, y, w, h);
offGraphics.setColor(bakColor);
}
public void clearRect(int x, int y, int w, int h) {
offGraphics.setColor(bgColor);
offGraphics.fillRect(x, y, w, h);
}
public void clear() {
clearRect(0, 0, width, height);
}
public void setColor(Color c) {
offGraphics.setColor(c);
}
public void setFont(Font font) {
offGraphics.setFont(font);
}
public void drawString(String s, int x, int y) {
offGraphics.drawString(s, x, y);
}
synchronized public void flush() {
Graphics g = screen.getGraphics();
if(g != null) {
if(screenListener != null) {
screenListener.update(se);
}
offImg.flush();
g.drawImage(offImg, 0, 0, null);
}
}
public void addScreenListener(ScreenListener l) {
synchronized(syncScrObj) {
if(screenListener != null || l == null) return;
screenListener = l;
}
}
public ScreenListener removeScreenListener() {
ScreenListener result = null;
synchronized(syncScrObj) {
result = screenListener;
screenListener = null;
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -