Fullscreen zum GamePanelD hinzugefügt

Über boolean fullscreen einstellbar
This commit is contained in:
andreas
2014-11-25 16:35:10 +01:00
parent 743d960e48
commit e0c72226a6
+39 -4
View File
@@ -1,8 +1,12 @@
package de.heatup.testing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Point;
@@ -29,6 +33,7 @@ public class GameLoopD extends JFrame implements Runnable {
private boolean running = false;
private static boolean pause = false;
private boolean fullscreen = true;
private Thread thread;
@@ -41,6 +46,8 @@ public class GameLoopD extends JFrame implements Runnable {
private static JPanel outerPanel;
private static JPanel statusPanel;
private static JPanel gamePanel;
private static JPanel leftPanel;
private static JPanel rightPanel;
private static JPanel actionPanel;
public GameLoopD(){
@@ -48,6 +55,11 @@ public class GameLoopD extends JFrame implements Runnable {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
// For fullscreen
if ( fullscreen) {
setResizable(false);
setUndecorated(true);
}
outerPanel = new JPanel();
outerPanel.setLayout(new BorderLayout());
@@ -61,13 +73,24 @@ public class GameLoopD extends JFrame implements Runnable {
gamePanel.setLayout(null);
gamePanel.setPreferredSize(new Dimension(800,600));
gamePanel.setFocusable(false);
gamePanel.setBackground(Color.black);
actionPanel = new JPanel();
actionPanel.setLayout(new GridLayout(1,1));
actionPanel.setPreferredSize(new Dimension(800,80));
actionPanel.setFocusable(true);
leftPanel = new JPanel();
leftPanel.setLayout(null);
leftPanel.setBackground(Color.black);
rightPanel = new JPanel();
rightPanel.setLayout(null);
rightPanel.setBackground(Color.black);
outerPanel.add(statusPanel,BorderLayout.NORTH);
outerPanel.add(leftPanel, BorderLayout.WEST);
outerPanel.add(rightPanel, BorderLayout.EAST);
outerPanel.add(gamePanel,BorderLayout.CENTER);
outerPanel.add(actionPanel,BorderLayout.SOUTH);
@@ -87,11 +110,23 @@ public class GameLoopD extends JFrame implements Runnable {
player01 = PanelBuilder.player01;
actionPanel.setVisible(true);
outerPanel.setVisible(true);
statusPanel.setVisible(true);
gamePanel.setVisible(true);
//leftPanel.setPreferredSize(new Dimension((this.getWidth()-gamePanel.getWidth()),10));
outerPanel.setVisible(true);
gamePanel.setVisible(true);
actionPanel.setVisible(true);
statusPanel.setVisible(true);
// For fullscreen
if ( fullscreen ) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
gd.setFullScreenWindow(this);
leftPanel.setPreferredSize(new Dimension(((gd.getDisplayMode().getWidth() - (int)gamePanel.getPreferredSize().getWidth())/2), 0));
rightPanel.setPreferredSize(new Dimension(((gd.getDisplayMode().getWidth() - (int)gamePanel.getPreferredSize().getWidth())/2), 0));
}
}