I'm making a very simple game using Java and Swing, however the coordinates (including width and height) are off by a small amount (between 3 and 30 pixels).
Here is my code
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, 0, 0); //should draw one pixel in the top-left
g.drawLine(40, 40, 40, 40); //draws correctly, but not at 40, 40
g.dispose();
}
}
I have a hypothesis that that it is including the title bar and border in the coords however I'm not sure if this is correct, and even if it is, the titlebar is dependant on the system so I cannot just program constants in to account for it.
Thanks in advance.
P.S I'm open to title suggestions.