I have been working on making Pong in Java, but I can't seem to accurately set the size of the JFrame. Here is my main class:
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class Pong extends JFrame {
private final Game panel;
private final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public Pong() {
setTitle("Pong");
setSize(screenSize);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel = new Game(this);
add(panel);
}
public static void main(String[] args) {
new Pong();
}
}
When I run my program, the window takes up the whole screen, but when I try to get the dimensions of the screen, they are larger than those of the window, causing anything set at the lower extents of the window to get cut off. The only way I have found to get the true dimensions is to call this.getHeight()
, this.getWidth()
, or this.getSize()
within the panel class. How can I get the true dimensions right off the bat?