我想製作一個遊戲,其中角色是一個75x75的對象,並且他在屏幕上移動。然而,當我跑我的代碼,我得到的錯誤:Keyevent getID導致錯誤
java.lang.IllegalArgumentException: Invalid display mode
at sun.awt.Win32GraphicsDevice.setDisplayMode(Unknown Source)
at sylvyrfysh.Screen.setFullScreen(Screen.java:17)
at sylvyrfysh.ImageDrawer.run(ImageDrawer.java:26)
at sylvyrfysh.ImageDrawer.main(ImageDrawer.java:17)
at sylvyrfysh.Main.main(Main.java:7)
我不知道是什麼原因造成這一點,因爲我做了同樣的DISPLAYMODE論點的另一個項目,它工作得很好。 package sylvyrfysh;
import game.infos.Information;
import java.awt.*;
import javax.swing.*;
public class ImageDrawer extends JFrame{
/**
*
*/
private static final long serialVersionUID = -4278324581016693552L;
public static void main() throws InterruptedException{
DisplayMode dm=new DisplayMode(Information.sX,Information.sY,16,DisplayMode.REFRESH_RATE_UNKNOWN);
ImageDrawer i=new ImageDrawer();
i.run(dm);
}
private void loader(){
bg=new ImageIcon("src/sylvyrfysh/maze_icon.png").getImage();
chara=new ImageIcon("src/sylvyrfysh/char.png").getImage();
}
private void run(DisplayMode dm){
System.out.println("HI");
loader();
s=new Screen();
s.setFullScreen(dm,this);//error here
repaint();
while(EHandler.run){
if(rp){
repaint();
rp=false;
}
}
}
public void paint(Graphics g){
g.drawImage(bg,0,0,null);
g.drawImage(bg,360,0,null);
g.drawImage(bg,720,0,null);
g.drawImage(bg,0,480,null);
g.drawImage(bg,360,480,null);
g.drawImage(bg,720,480,null);
g.drawImage(chara,imgX,imgX,null);
}
private Image bg,chara;
Screen s;
public static int imgX=0;
public static int imgY=525;
public static Boolean rp=false;
}
任何幫助,將不勝感激。
使用顯示模式的具體原因是什麼?是否用於實現全屏窗口? – Sage