public void init() { try { this.imLogo = this.getImage("icon.png"); tracker.addImage(this.imLogo, 0); tracker.waitForID(0); } catch (InterruptedException inex) { } try { this.imHelp = this.getImage("helpphoto.png"); tracker.addImage(this.imHelp, 1); tracker.waitForID(1); } catch (InterruptedException ie) { } this.fontTitle = new Font("GB2312", Font.BOLD, 25); this.fontText = new Font("GB2312", Font.PLAIN, 18); this.setBackground(Color.BLACK); this.setForeground(Color.WHITE); this.timer = new Timer( 500, new ActionListener() { public void actionPerformed(ActionEvent ev) { world = new OSCWorld(); world.onEnter(); repaint(); timer.stop(); } }); this.timer.start(); }
/** * Create a splash screen (borderless graphic for display while other operations are taking * place). * * @param filename a class-relative path to the splash graphic * @param callingClass the class to which the graphic filename location is relative */ public SplashScreen(String filename, Class callingClass) { super(new Frame()); URL imageURL = callingClass.getResource(filename); image = Toolkit.getDefaultToolkit().createImage(imageURL); // Load the image MediaTracker mt = new MediaTracker(this); mt.addImage(image, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { } // Center the window on the screen int imgWidth = image.getWidth(this); int imgHeight = image.getHeight(this); setSize(imgWidth, imgHeight); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2); setVisible(true); repaint(); // if on a single processor machine, wait for painting (see Fast Java Splash Screen.pdf) if (!EventQueue.isDispatchThread()) { synchronized (this) { while (!this.paintCalled) { try { this.wait(); } catch (InterruptedException e) { } } } } }
public static void ensureLoaded(Image img) throws Exception { // System.err.println("In ensureloaded"); mediatracker.addImage(img, 0); try { mediatracker.waitForAll(); if (mediatracker.getErrorsAny() != null) { mediatracker.removeImage(img); throw new Exception("Error loading image"); } } catch (InterruptedException e) { e.printStackTrace(); } mediatracker.removeImage(img); // System.err.println("Out ensureloaded"); }
public static java.awt.image.BufferedImage loadBufferedImageFromResources( Component c, String filename) { try { Misc m = new Misc(); java.awt.Image img = loadImageFromResources(filename); MediaTracker mt = new MediaTracker(c); mt.addImage(img, 0); mt.waitForID(0); int width = img.getWidth(null); int height = img.getHeight(null); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics gg = bi.getGraphics(); gg.drawImage(img, 0, 0, null); gg.dispose(); return bi; } catch (Exception ex) { System.out.println(ex.toString()); } return null; }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }