Salve ragazzi, spero che riusciate a darmi una mano.
Ho realizzato una applicazione. Al caricamento ho questa situazione ho una classe TestaFrame che estende JFrame, quesa classe la uso come contenitore per tutti i JPanel della mia applicazione.
Poichè quando avvio la prima volta il software, vengono effettuate numerose operazioni, vorrei che all'avvio venga mostrata una immagine (logo dell'applicazione) e sotto una barra di scorrimento che indichi di volta in volta ciò che sta facendo il software.
Per far questo ho trovato queste due classi.
main della classe splash screencodice:package SplashScreen; import javax.swing.*; import java.awt.*; public class SplashScreen extends JFrame { BorderLayout borderLayout1 = new BorderLayout(); JLabel imageLabel = new JLabel(); JPanel southPanel = new JPanel(); FlowLayout southPanelFlowLayout = new FlowLayout(); JProgressBar progressBar = new JProgressBar(); ImageIcon imageIcon; public SplashScreen(ImageIcon imageIcon) { this.imageIcon = imageIcon; try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } // note - this class created with JBuilder void jbInit() throws Exception { imageLabel.setIcon(imageIcon); this.getContentPane().setLayout(borderLayout1); southPanel.setLayout(southPanelFlowLayout); southPanel.setBackground(Color.BLACK); this.getContentPane().add(imageLabel, BorderLayout.CENTER); this.getContentPane().add(southPanel, BorderLayout.SOUTH); southPanel.add(progressBar, null); this.pack(); } public void setProgressMax(int maxProgress) { progressBar.setMaximum(maxProgress); } public void setProgress(int progress) { final int theProgress = progress; SwingUtilities.invokeLater(new Runnable() { public void run() { progressBar.setValue(theProgress); } }); } public void setProgress(String message, int progress) { final int theProgress = progress; final String theMessage = message; setProgress(progress); SwingUtilities.invokeLater(new Runnable() { public void run() { progressBar.setValue(theProgress); setMessage(theMessage); } }); } public void setScreenVisible(boolean b) { final boolean boo = b; SwingUtilities.invokeLater(new Runnable() { public void run() { setVisible(boo); } }); } private void setMessage(String message) { if (message==null) { message = ""; progressBar.setStringPainted(false); } else { progressBar.setStringPainted(true); } progressBar.setString(message); } }
Ora io dovrei integrare questa operazione all'interno del mio JPanel che viene caricato all'avvia nel JFrame.codice:import javax.swing.UIManager; import javax.swing.ImageIcon; public class SplashScreenMain { SplashScreen screen; public SplashScreenMain() { // initialize the splash screen splashScreenInit(); // do something here to simulate the program doing something that // is time consuming for (int i = 0; i <= 100; i++) { for (long j=0; j<50000; ++j) { String poop = " " + (j + i); } // run either of these two -- not both screen.setProgress("Yo " +i, i); // progress bar with a message // screen.setProgress(i); // progress bar with no message } splashScreenDestruct(); //System.exit(0); } private void splashScreenDestruct() { screen.setScreenVisible(false); } public void splashScreenInit() { ImageIcon myImage = new ImageIcon("immagini/concepimento-dieta-della-fertilita-coppa-di-gelato2.jpg"); screen = new SplashScreen(myImage); screen.setLocationRelativeTo(null); screen.setProgressMax(100); screen.setScreenVisible(true); } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } SplashScreenMain mainflasj = new SplashScreenMain(); } }
Posto la clase TestaFrame e JPanel1
codice:public class TestaFrame extends JFrame{ PanelIngredienti ingredienti; public TestaFrame(){ super("iGelato Versione 1.0"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // getContentPane().setPreferredSize(new Dimension(1000, 600)); /* Toolkit t = Toolkit.getDefaultToolkit(); Dimension screenSize = t.getScreenSize(); double width = screenSize.getWidth(); double height= screenSize.getHeight(); double frameWidth = width; double frameHeight = height; Dimension d2 = new Dimension(); d2.setSize(frameWidth, frameHeight);*/ this.setPreferredSize(d2); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); this.setResizable(true); //adesso attacco al frame il pannello principale che sarà il cuore del programma MainPanel mainpanel = new MainPanel(); getContentPane().add(mainpanel, BorderLayout.CENTER); getContentPane().validate(); //fine }//fine testaframe public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { TestaFrame f = new TestaFrame(); } });}//fine metodo main }}}//fine classe generale



Rispondi quotando