有JFrame
持有JComponent
,每秒30
次提取BufferedImage
。绘制EventQueue.invokeLater
时,问题似乎是闪烁或闪烁效果,因为它相应地相互绘制..
此外,还有第二个问题,即Window构造函数执行得非常晚,有时当程序实际需要使用此对象时,如果应用了import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
public class Window{
private JFrame window;
private CanvasComponent component;
public Window(Input input){
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int hostMonitorWidth = gd.getDisplayMode().getWidth();
int hostMonitorHeight = gd.getDisplayMode().getHeight();
window = new JFrame();
component = new CanvasComponent(hostMonitorWidth, hostMonitorHeight);
window.setUndecorated(true);
window.setBackground(new Color(0,0,0,200));
window.setLayout(new GridLayout());
window.setSize(hostMonitorWidth, hostMonitorHeight);
window.getContentPane().add(component);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLocationRelativeTo(null);
window.setVisible(true);
window.requestFocus();
window.setFocusableWindowState(true);
window.addKeyListener(input);
}
public void draw(){
component.draw();
}
private class CanvasComponent extends JComponent{
public CanvasComponent(int hostMonitorWidth, int hostMonitorHeight){
super.setSize(hostMonitorWidth, hostMonitorHeight);
super.setBackground(new Color(0,0,0,0));
super.setDoubleBuffered(true);
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
if(GraphicsBatch == null) return;
BufferedImage image = GraphicsBatch.getImage();
g.drawImage(image,0,0,null);
}
public void draw(){
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
repaint();
}});
}
}
}
,那么将它放在那里或者让它保持原样是至关重要的是吗?
Window.draw()
<li><a data-toggle="modal" href="example.html" data-target="#example">Example</a></li>
被称为每秒30次。