我正在使用Java和Swing制作一个非常简单的游戏,但是坐标(包括宽度和高度)偏移很小(在3到30个像素之间)。
这是我的代码
public class GraphicsWindow extends JFrame {
public GraphicsWindow(int x,int y) {
this.setTitle("To Be updated");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(x,y);
this.setVisible(true);
}
@Override
public void paint(Graphics gr) {
Graphics2D g = (Graphics2D)gr;
g.drawLine(0,0); //should draw one pixel in the top-left
g.drawLine(40,40,40); //draws correctly,but not at 40,40
g.dispose();
}
}
我有一个假设,那就是在坐标中包含标题栏和边框,但是我不确定这是否正确,即使是这样,标题栏也取决于系统,因此我不能只对常量进行编程来解决这个问题。
谢谢。
P.S我愿意接受标题建议。