如何在java中以全屏独占模式处理来自键盘和鼠标的事件?在被动渲染模式下,我们可以使用KeyListener和ActionListener接口来处理来自用户的事件。在全屏模式下,正确的事件处理方法是什么?请扩展此框架,为鼠标单击和按键事件提供实现,请不要膨胀您的示例(示例启动全屏独占模式,使用Timer若要更新窗口中的图形):import java.applet.Applet;import java.awt.Color;import java.awt.DisplayMode;import java.awt.Graphics2D;import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;import java.awt.GraphicsEnvironment;import java.awt.Rectangle;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import java.awt.image.BufferStrategy;import javax.swing.JFrame;import javax.swing.Timer;
public class applet extends Applet{
Timer timer;
JFrame frame;
DisplayMode[] displayModes = new DisplayMode[] {
new DisplayMode(1280, 800, 32, 60)
};
BufferStrategy bufferStrategy;
Rectangle bounds;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param args
*/
public void init()
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); //displays, fonts, color shemes...
GraphicsDevice device = env.getDefaultScreenDevice(); //for one-display systems
setIgnoreRepaint(true);
GraphicsConfiguration gc = device.getDefaultConfiguration();
frame = new JFrame(gc);
device.setFullScreenWindow(frame);
if (device.isDisplayChangeSupported())
device.setDisplayMode(displayModes[0]);
frame.createBufferStrategy(2);
bufferStrategy = frame.getBufferStrategy();
timer = new Timer(1000 / 50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Graphics2D g = null;
try {
g = (Graphics2D) bufferStrategy.getDrawGraphics();
render(g);
} finally {
g.dispose();
}
bufferStrategy.show();
}
});
}
添加回答
举报
0/150
提交
取消