[英]Java: JFrame Layout for Only Drawing?
I'm wanting to draw my components on a JFrame based on coordinates. 我想基于坐标在JFrame上绘制组件。 I don't want a layout to rearrange the components. 我不希望布局重新排列组件。 My project isn't a GUI, it's a game where the images being drawn don't need to be laid out into a UI pattern. 我的项目不是GUI,而是一个游戏,无需将绘制的图像布置为UI模式。
Is there a layout (or a layout of null) that allows you to draw components onto the JFrame without them being rearranged? 是否有一种布局(或null布局),可让您在不重新排列组件的情况下将组件绘制到JFrame上?
The soulution I was looking for was to have my Game class inherit from JFrame and then draw everything in JFrame's paint method. 我要寻找的解决方案是让我的Game类从JFrame继承,然后在JFrame的paint方法中绘制所有内容。
public class Game extends JFrame
{
...
public void paint (Graphics g){
//Graphics2D g2 = (Graphics2D) g;
board.paintComponent(g);
board.getPieceAt(0,0).paintComponent(g);
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.