I am creating a screensaver for my application. This is just a static BufferedImage drawn by Graphics2D, inside a JFrame with no decorations. My problem is that the window is sometimes not drawn properly, which means that it does not always contain my image, it is sometimes just gray. I tried to create a splash screen in the second thread, but that did not help. I could call splashScreen.repaint()
every line, but this is nonsense ... Here is my code:
package SeriousSteve.MapEditor; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.JFrame; public class SplashScreen extends JFrame { private BufferedImage image; public SplashScreen() { super("Splash screen"); } public void createSplashScreen(final URL imageURL) { try { image = ImageIO.read(imageURL); } catch (IOException ex) { Logger.getLogger(SplashScreen.class.getName()). log(Level.SEVERE, null, ex); } setUndecorated(true); setSize(image.getWidth(), image.getHeight()); setLocationRelativeTo(null); setVisible(true); createGraphics(); repaint(); } private void createGraphics() { Graphics2D g = (Graphics2D) getGraphics(); g.drawImage(image, 0, 0, null); } public void close() { setVisible(false); image = null; dispose(); } }
and
SplashScreen splashScreen = new SplashScreen(); splashScreen.createSplashScreen(getClass().getResource( "Img/splash.png"));
Btw., - I create my own splash screen class because I have 2 applications (a game and map editor for it) in 1 bank ... I want to show the splash screen only in the map editor, so I cannot change the manifest file.
Hi
source share