I am creating a pong game in Java. I originally had an undecorated JFrame with a width of 700 and a height of 400. I later changed my mind and switched to a decorated frame. The error is that the ball travels off of the screen for the top 30px or so in the decorated frame. I measured the screen, and indeed it is 700 x 400 when decorated; however, I need the area where the ball will be painted to be 700 x 400, not the entire JFrame. What can I do?
How I set the size of my frame:
this.setSize(new Dimension(WIDTH, HEIGHT));
I am happy to post all of the code needed to solve this problem upon request.
EDIT
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Tester extends JFrame {
public Tester() {
this.add(new Window());
pack();
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});
}
private void formMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("X: " + evt.getX() + ", Y: " + evt.getY());
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tester().setVisible(true);
}
});
}
public class Window extends JComponent {
@Override
public Dimension getPreferredSize() {
return new Dimension(300, 300);
}
}
}