Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [JAVA]splashscreen

  1. #1

    [JAVA]splashscreen

    salve ragazzi, volevo sapere se qualcuno poteva postare un esempio di splashscreen, dato che non so proprio da dove iniziare. Grazie anticipatamente

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [JAVA]splashscreen

    Originariamente inviato da Reddragoon
    salve ragazzi, volevo sapere se qualcuno poteva postare un esempio di splashscreen, dato che non so proprio da dove iniziare. Grazie anticipatamente
    Ne avevo parlato qui
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    ho trovato ed abbozzato qualcosa...solo che ho dei problemi

    codice:
    import java.awt.Frame;
    import java.awt.Toolkit;
    import java.net.URL; 
    import interfacce.*;
    public class Splash {	
    	public static void main(String[] args) {		
    		Frame splashFrame = null;		
    		URL imageURL = Splash.class.getResource("C:\\images.jpg");	
    		if (imageURL != null) {			
    			System.out.println(imageURL);
    			splashFrame = SplashWindow.splash(Toolkit.getDefaultToolkit().createImage(imageURL));		
    			} 
    		else {			
    			System.err.println("Splash image not found");		
    			}		
    		try { // Change the class name to match your entry class			
    			Class.forName("mainapp").getMethod("main", new Class[] 					
    			                                                     {
    					String[].class
    					}).invoke(null, new Object[] {args});
    			} catch (Throwable e) {			
    				e.printStackTrace();			
    				System.err.flush();			
    				System.exit(10);		
    				}		
    			if (splashFrame != null) {			
    				splashFrame.dispose();		
    				}	
    			}
    	}   /*END OF CLASS*/
    codice:
    package componenti;
    
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import java.awt.Window; 
    public class SplashWindow extends Window {	
    	/**	 * 	 */	
    	private static final long serialVersionUID = 1L;	
    	private Image splashImage;	
    	private boolean paintCalled = false;	
    	public SplashWindow(Frame owner, Image splashImage) {
    		super(owner);		
    		this.splashImage = splashImage;		
    		MediaTracker mt = new MediaTracker(this);		
    		mt.addImage(splashImage,0);		
    		try 
    		{			
    			mt.waitForID(0);		
    		} 
    		catch(InterruptedException ie) 
    		{}		
    		int imgWidth = splashImage.getWidth(this);		
    		int imgHeight = splashImage.getHeight(this);  		
    		setSize(imgWidth, imgHeight);		
    		Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();		
    		setLocation( (screenDim.width - imgWidth) / 2, 				
    				(screenDim.height - imgHeight) / 2 );	} 	@Override	
    				public void update(Graphics g) {		
    					g.setColor(getForeground());		
    					paint(g);	
    					} 	@Override	
    					public void paint(Graphics g) {		
    						g.drawImage(splashImage, 0, 0, this);		
    						if (! paintCalled) {			
    							paintCalled = true;			
    							synchronized (this) { 
    								notifyAll(); 
    								}		
    							}	
    						} 	@SuppressWarnings("deprecation")	
    						public static Frame splash(Image splashImage) {
    							Frame f = new Frame();		
    							SplashWindow w = new SplashWindow(f, splashImage);		
    							w.toFront();		
    							w.show();		
    							if (! EventQueue.isDispatchThread()) {
    								synchronized (w) {				
    									while (! w.paintCalled) {					
    										try {						
    											w.wait();					} 
    										catch (InterruptedException e) {}				
    										}			
    									}		
    								}		
    							return f;	
    							}
    						}
    il problema è che non riesco ad accedere all'immagine, a meno che la posizioni nel mio workspace nella cartella bin, altrimenti in qualsiasi altra parte non la vede

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.