SplashScreen Sencillo en Java
El siguiente es el codigo fuente de una clase dinamica para crear los SplashScreen
Recibe tres parametros y debe existir una una imagen llamada "Splash.jpg" y otra llamada "Icon.png" en la carpeta raiz del proyecto o de la aplicacion.
Los parametros que recibe son: el titulo o nombre del programa, un mensaje cualquiera, y un vector para los mensajes de cargando...
String title, String message, String[] text
Este es el main de la Clase:
public class Main {
public static String Titulo;
public static String Mensaje;
public static String[] Texto;
static ImageIcon Img=null;
public void Run(){
try {
File miDir = new File (".");
Titulo="JPlayer Max Streaming 1.0";
Mensaje="By: José José Meza Meza \nA Player to Stream Audio";
Texto=new String[4];
Texto[0]="Java Libraries";
Texto[1]="Graphics Resources";
Texto[2]="Users Properties";
Texto[3]="Aplication";
Img=new ImageIcon(miDir.getCanonicalPath()+"\\Splash.jpg");
ShowSplash SS=new ShowSplash(Titulo,Mensaje,Texto);
SS.setVisible(true);
SS.Animate();
} catch (IOException ex) {
}
}
public static void main(String[] args) {
new Main().Run();
}
}
Codigo Fuente Principal
import com.sun.awt.AWTUtilities;
import java.awt.Image;
import java.awt.Label;
import java.awt.SplashScreen;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import org.jvnet.substance.SubstanceLookAndFeel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author JJMM
*/
public class ShowSplash extends javax.swing.JDialog {
String Title="";
String Message="";
String Text[]=null;
private String Img=null;
private File miDir = new File (".");
/**
* Creates new form ShowSplash
*/
public ShowSplash(String title, String message, String[] text) {
try {
Img=miDir.getCanonicalPath()+"\\Splash.jpg";
Title=title;
Message=message;
Text=text;
setUndecorated(true);
initComponents();
Bar.setMaximum(4);
lbTitle.setText(Title);
lbMessage.setText(Message);
AWTUtilities.setWindowOpacity(this, new Float(0.8));
//centro el frame a la pantalla
setLocationRelativeTo(null);
} catch (IOException ex) {
}
}
public JProgressBar JP(){
return Bar;
}
public JLabel LoadText(){
return LoadText;
}
public void Animate(){
Thread Hilo=new Thread(new JP(this));
Hilo.start();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
lbTitle = new javax.swing.JLabel();
lbMessage = new javax.swing.JLabel();
LoadText = new javax.swing.JLabel();
Bar = new javax.swing.JProgressBar();
Imagen = new javax.swing.JLabel();
setTitle("Splash JPlayer Max Streaming");
setAlwaysOnTop(true);
setMinimumSize(new java.awt.Dimension(400, 300));
setResizable(false);
getContentPane().setLayout(null);
lbTitle.setFont(new java.awt.Font("Arial Black", 0, 24)); // NOI18N
lbTitle.setText("Titulo:");
getContentPane().add(lbTitle);
lbTitle.setBounds(10, 121, 380, 35);
lbMessage.setFont(new java.awt.Font("Segoe UI Semibold", 1, 12)); // NOI18N
lbMessage.setText("Mensaje:");
getContentPane().add(lbMessage);
lbMessage.setBounds(10, 153, 380, 50);
LoadText.setFont(new java.awt.Font("Segoe Print", 1, 18)); // NOI18N
LoadText.setText("Cargando: JPlayer Max Streaming");
getContentPane().add(LoadText);
LoadText.setBounds(10, 200, 380, 33);
getContentPane().add(Bar);
Bar.setBounds(10, 240, 370, 16);
Imagen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon.png"))); // NOI18N
Imagen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Imagen.setMaximumSize(new java.awt.Dimension(300, 400));
Imagen.setMinimumSize(new java.awt.Dimension(300, 400));
getContentPane().add(Imagen);
Imagen.setBounds(0, 0, 400, 300);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JProgressBar Bar;
private javax.swing.JLabel Imagen;
private javax.swing.JLabel LoadText;
private javax.swing.JLabel lbMessage;
private javax.swing.JLabel lbTitle;
// End of variables declaration
}
class JP implements Runnable{
ShowSplash SS=null;
public JP(ShowSplash ss){
SS=ss;
}
public void run() {
try {
Aplicacion Ap=new Aplicacion(); //Aqui llamas a tu aplicacion, como se llame
for(int i=0;i<SS.Text.length;i++){
SS.LoadText().setText("Cargando: "+SS.Text[i]+"...");
SS.JP().setValue(i+1);
Thread.sleep(600);
}
if(SS.JP().getValue()==SS.Text.length){
Ap.setVisible(true);
if(Ap.isVisible()==true){
SS.dispose();
}
}
} catch (Exception ex) {
System.exit(0);
}
}
}
El siguiente es el codigo fuente de una clase dinamica para crear los SplashScreen
Recibe tres parametros y debe existir una una imagen llamada "Splash.jpg" y otra llamada "Icon.png" en la carpeta raiz del proyecto o de la aplicacion.
Los parametros que recibe son: el titulo o nombre del programa, un mensaje cualquiera, y un vector para los mensajes de cargando...
String title, String message, String[] text
Este es el main de la Clase:
public class Main {
public static String Titulo;
public static String Mensaje;
public static String[] Texto;
static ImageIcon Img=null;
public void Run(){
try {
File miDir = new File (".");
Titulo="JPlayer Max Streaming 1.0";
Mensaje="By: José José Meza Meza \nA Player to Stream Audio";
Texto=new String[4];
Texto[0]="Java Libraries";
Texto[1]="Graphics Resources";
Texto[2]="Users Properties";
Texto[3]="Aplication";
Img=new ImageIcon(miDir.getCanonicalPath()+"\\Splash.jpg");
ShowSplash SS=new ShowSplash(Titulo,Mensaje,Texto);
SS.setVisible(true);
SS.Animate();
} catch (IOException ex) {
}
}
public static void main(String[] args) {
new Main().Run();
}
}
Codigo Fuente Principal
import com.sun.awt.AWTUtilities;
import java.awt.Image;
import java.awt.Label;
import java.awt.SplashScreen;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import org.jvnet.substance.SubstanceLookAndFeel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author JJMM
*/
public class ShowSplash extends javax.swing.JDialog {
String Title="";
String Message="";
String Text[]=null;
private String Img=null;
private File miDir = new File (".");
/**
* Creates new form ShowSplash
*/
public ShowSplash(String title, String message, String[] text) {
try {
Img=miDir.getCanonicalPath()+"\\Splash.jpg";
Title=title;
Message=message;
Text=text;
setUndecorated(true);
initComponents();
Bar.setMaximum(4);
lbTitle.setText(Title);
lbMessage.setText(Message);
AWTUtilities.setWindowOpacity(this, new Float(0.8));
//centro el frame a la pantalla
setLocationRelativeTo(null);
} catch (IOException ex) {
}
}
public JProgressBar JP(){
return Bar;
}
public JLabel LoadText(){
return LoadText;
}
public void Animate(){
Thread Hilo=new Thread(new JP(this));
Hilo.start();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
lbTitle = new javax.swing.JLabel();
lbMessage = new javax.swing.JLabel();
LoadText = new javax.swing.JLabel();
Bar = new javax.swing.JProgressBar();
Imagen = new javax.swing.JLabel();
setTitle("Splash JPlayer Max Streaming");
setAlwaysOnTop(true);
setMinimumSize(new java.awt.Dimension(400, 300));
setResizable(false);
getContentPane().setLayout(null);
lbTitle.setFont(new java.awt.Font("Arial Black", 0, 24)); // NOI18N
lbTitle.setText("Titulo:");
getContentPane().add(lbTitle);
lbTitle.setBounds(10, 121, 380, 35);
lbMessage.setFont(new java.awt.Font("Segoe UI Semibold", 1, 12)); // NOI18N
lbMessage.setText("Mensaje:");
getContentPane().add(lbMessage);
lbMessage.setBounds(10, 153, 380, 50);
LoadText.setFont(new java.awt.Font("Segoe Print", 1, 18)); // NOI18N
LoadText.setText("Cargando: JPlayer Max Streaming");
getContentPane().add(LoadText);
LoadText.setBounds(10, 200, 380, 33);
getContentPane().add(Bar);
Bar.setBounds(10, 240, 370, 16);
Imagen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon.png"))); // NOI18N
Imagen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Imagen.setMaximumSize(new java.awt.Dimension(300, 400));
Imagen.setMinimumSize(new java.awt.Dimension(300, 400));
getContentPane().add(Imagen);
Imagen.setBounds(0, 0, 400, 300);
pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JProgressBar Bar;
private javax.swing.JLabel Imagen;
private javax.swing.JLabel LoadText;
private javax.swing.JLabel lbMessage;
private javax.swing.JLabel lbTitle;
// End of variables declaration
}
class JP implements Runnable{
ShowSplash SS=null;
public JP(ShowSplash ss){
SS=ss;
}
public void run() {
try {
Aplicacion Ap=new Aplicacion(); //Aqui llamas a tu aplicacion, como se llame
for(int i=0;i<SS.Text.length;i++){
SS.LoadText().setText("Cargando: "+SS.Text[i]+"...");
SS.JP().setValue(i+1);
Thread.sleep(600);
}
if(SS.JP().getValue()==SS.Text.length){
Ap.setVisible(true);
if(Ap.isVisible()==true){
SS.dispose();
}
}
} catch (Exception ex) {
System.exit(0);
}
}
}
excelente. que tema tan atractivo !
ResponderBorrar