java中双缓冲,Java双缓冲

我正在开发一个项目,我已经尽可能多地阅读了java中的双缓冲技术。我想要做的是添加一个组件或面板或东西到我的JFrame包含双缓冲表面绘制。如果可能,我想使用硬件加速,否则使用常规软件渲染器。我的代码看起来像这样到目前为止:

public class JFrameGame extends Game {

protected final JFrame frame;

protected final GamePanel panel;

protected Graphics2D g2;

public class GamePanel extends JPanel {

public GamePanel() {

super(true);

}

@Override

public void paintComponent(Graphics g) {

g2 = (Graphics2D)g;

g2.clearRect(0, 0, getWidth(), getHeight());

}

}

public JFrameGame() {

super();

gameLoop = new FixedGameLoop();

frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

panel = new GamePanel();

panel.setIgnoreRepaint(true);

frame.add(panel);

panel.setVisible(true);

frame.setVisible(true);

}

@Override

protected void Draw() {

panel.repaint(); // aquire the graphics - can I acquire the graphics another way?

super.Draw(); // draw components

// draw stuff here

// is the buffer automatically swapped?

}

@Override

public void run() {

super.run();

}

}我创建了一个抽象游戏类和一个调用Update和Draw的游戏循环。现在,如果您看到我的意见,那是我主要关心的问题。有没有办法获得图形一次,而不是通过重绘和paintComponent,然后分配每个重绘变量?此外,该硬件是否默认加速?如果不是,我应该怎么做才能使硬件加速?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值