2016-08-16 226 views
0

屏幕閃爍黑屏,然後單獨打開JFrame。全屏幕不工作

public Game() { 
    myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
    JFrame frame = new JFrame(); 
    // frame.setExtendedState(JFrame.MAXIMIZED_BOTH); 
    frame.setVisible(true); 
    frame.add(this); 

    myDevice.setFullScreenWindow(frame); 
    try { 
    } finally { 
     myDevice.setFullScreenWindow(null); 
    } 

    time = 0; 
    level = new LevelOne(this); 
    this.requestFocus(); 
    try { 
     bgImg = ImageIO.read(new File("Space.png")); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    if (this.getBufferStrategy() == null) 
     this.createBufferStrategy(2); 
    bs = this.getBufferStrategy(); 
    timer.schedule(new TimerTask() { 

     public void run() { 
     calc(); 
     MobMover.calc(); 
     render(); 
     time++; 
     } 

    }, 0L, 40L); 
} 

我沒有看到這個問題...:'(

+1

你有一個try'-block,它帶有一個單獨的'finally'子句,它將全屏設置爲null。請記住finally代碼塊總是會執行。甚至這個代碼塊的目的是什麼? – Jokab

回答

0

的代碼塊將其設置爲null

try { 
    } finally { 
     myDevice.setFullScreenWindow(null); 
    } 

所以刪除,它應該工作

+0

謝謝你是stup id xD 但是現在我有一個黑色條,其中任務欄通常爲 – Crudellor

+0

嘗試添加以下任一項或兩項:frame.setExtendedState(Frame.MAXIMIZED_BOTH)/ frame.setUndecorated(true) – notyou