We are currently doing a game project using Eclipse. We started the project on my friend's Mac and the code worked how it should. If we start the program on any other windows device it doesn't work properly anymore. The idea behind the code is, that the Window always has the same resolution so the pictures and everything don't get distorted.
frmwidth
and frmheight
are the starting values for the height and the width of the window.
Don't get distracted by the 27, it's because the aspect ratio isn't perfectly 16:9.
Does someone have an idea why it doesn't work on windows?
public void componentResized(ComponentEvent e) {
int height = ((JFrame)e.getSource()).getHeight();
int width = ((JFrame)e.getSource()).getWidth();
if(height != frmheight && width != frmwidth){
((JFrame)e.getSource()).setSize(frmwidth, frmheight);
}else if(height != frmheight) {
frmwidth = ((height - 27) / 9) * 16;
frmheight = height;
((JFrame)e.getSource()).setSize(frmwidth, frmheight);
Hintergrund.anpassen(frmheight, frmwidth);
}else {
frmwidth = width;
frmheight = ((width / 16) * 9) + 27;
((JFrame)e.getSource()).setSize(frmwidth, frmheight);
Hintergrund.anpassen(frmheight, frmwidth);
}
((JFrame)e.getSource()).setSize(frmwidth, frmheight);
}