Simply put, I'm trying to create a game in which I work in full screen mode.
I have the following code that I am trying to use:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
if(!gs.isFullScreenSupported()) {
System.out.println("full-screen not supported");
}
Frame frame = new Frame(gs.getDefaultConfiguration());
Window win = new Window(frame);
try {
gs.setFullScreenWindow(win);
win.validate();
}
The problem with this is that I work in a class that extends JPanel, and although I have a variable of type Frame, I don't have any Window types inside the class.
My understanding of JPanel is that it is a kind of window, but I cannot pass 'this' to gs.setFullScreenWindow (Window win) ... How do I do this?
Is there an easy way to call this method or a similar method using JPanel?
Is there a way to get something like Window from my JPanel?
-
EDIT: The following method changes the state of the JFrame and is called every 10 ms:
public void paintScreen()
{
Graphics g;
try{
g = this.getGraphics();
if(g == null)
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
frame.add(this);
frame.pack();
frame.setResizable(false);
frame.setTitle("Game Window");
frame.setVisible(true);
}
if((g != null) && (dbImage != null))
{
g.drawImage(dbImage, 0, 0, null);
}
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
catch (Exception e)
{
if(blockError)
{
blockError = false;
}
else
{
System.out.println("Graphics context error: " + e);
}
}
}
, if (g == null) ( frame.somethingOrOther()), ...
, - , . . , , ... , , , - , , ... .