I am attempting to write a program that can draw an image in full screen. I am trying to accomplish this without a paint() method and I am not sure how to go about it. Here is the current state of my code:
package gametest;
import java.awt.*; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; public class GameTest extends JFrame { private GraphicsDevice device; public GameTest(GraphicsDevice device) { super(device.getDefaultConfiguration()); this.device = device; setTitle("Game Test"); setDefaultCloseOperation(EXIT_ON_CLOSE); } private void initComponents(Container c) { setContentPane(c); c.setLayout(new BorderLayout()); // Current DM JPanel currentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); c.add(currentPanel, BorderLayout.NORTH); } public void begin() { setUndecorated(true); setResizable(false); device.setFullScreenWindow(this); validate(); } public void render() { boolean done=false; while(!done) { Graphics g = getGraphics(); ImageIcon icon = new ImageIcon("Test.jpeg"); Image img = icon.getImage(); g.drawImage(img, 0, 0, rootPane); g.dispose(); } } public static void main(String[] args) { GraphicsEnvironment env = GraphicsEnvironment. getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices(); GameTest test = new GameTest(devices[0]); test.initComponents(test.getContentPane()); test.begin(); test.render(); } }
All I get is a full screen grey window.