In this part we will learn how to make a full screen window in Java. Playing game in a full screen window is always a different experience and Java provide a very clean way of doing so. The code below is pretty easy to understand. FullFrame class can be used as a base window for any java game you want to build.
----------------------------------------------
Code for part one
----------------------------------------------import javax.swing.*;
import java.awt.*;
class FullFrame extends JFrame{
private GraphicsDevice gd;
public FullFrame()
{
}
public void initFullScreen()
{
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment( );
gd = ge.getDefaultScreenDevice( );
setUndecorated(true);
setIgnoreRepaint(true);
setResizable(false);
if (!gd.isFullScreenSupported( ))
{
Toolkit tk = Toolkit.getDefaultToolkit( );
Dimension scrDim = tk.getScreenSize( );
setVisible(true);
setSize(scrDim);
}
gd.setFullScreenWindow(this);
}
}
----------------------------------------------
No comments:
Post a Comment