This is my JFrame code:
public static int width = 800;
public static int height = 600;
public static void main(String[]args){
JFrame frame= new JFrame("RETRO");
frame.add(new Screen());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width,height);
frame.setVisible(true);
frame.setResizable(false);
}
Basically when I want something to move to the edge of the screen, I have to add extra pixels for it work (I’m guessing because it includes the frame itself instead of just the display size? However the origins work fine (x=0, y=0)). Example:
public double getX(){
if(x<0)
x=0;
if(x+getImage().getWidth(null)>Game.width-6)
x=Game.width-6-getImage().getWidth(null);
return x;
}
public double getY(){
if(y<0)
y=0;
if(y+getImage().getHeight(null)>Game.height-26)
y=Game.height-26-getImage().getHeight(null);
return y;
}
Is there a way around this? I don’t think the JFrame would be the same size on everyone’s computer, not to mention the guesswork. Rather have it much neater and flexible by using an exiting variable from the JFrame component. Does there exist something like a frame.getDisplayWidth and Height function?
1 Answer