Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/03/2009, 17:47
Avatar de xlugo2002
xlugo2002
 
Fecha de Ingreso: noviembre-2002
Ubicación: Puebla, México
Mensajes: 474
Antigüedad: 21 años, 5 meses
Puntos: 0
aplicacion java con mensajes de estado ?

HOla, no conozco mucho el API de Java para crear ventanas (S.O.)

Mi aplicacion es muy sencilla, es abrir un archivo .zip, descomprimirlo, despues leer un XML para de ahi generar una estructura de carpetas y archivos.

Tengo una interfaz que presenta solamente el boton de: "Seleccionar archivo....", y eso esta bien pero...........

No me muestra nada de mensajes como "lleyeno archivo", "descomprimiendo archivo .zip", "leyendo archivo XM".. etc; Se muestran solo cuando se ha acabado de ejecutar el programa.

Los mensajes estan marcados en negrita, pero se muestran unicamente hasta que el progrma termina su ejecucion y "no al vuelo"

public class Aplicacion extends JFrame
{
static private final String newline = "\n";

static String exceptionIniciaParser = "Excepcion al iniciar el parser";
static final String HECHO = " hecho.";
static final String LEYENDO_ARCHIVO_XML = "Leyendo archivo XML ...";
static final String ANALIZANDO_ARCHIVO_XML = "\nAnalizando archivo XML ...";
static final String CREANDO_DIRECTORIOS = "\nCreando la estructura de directorios y copiando archivos ...";
static final String COPIANDO_ARCHIVOS = "\nCopiando los archivos ...";

public Aplicacion()
{
super ("Restaurar contenidos");


final JTextArea log = new JTextArea (5, 20);
log.setMargin (new Insets (5, 5, 5, 5));
log.setEditable (false);
JScrollPane logScrollPane = new JScrollPane (log);


final JFileChooser fc = new JFileChooser ();


ImageIcon openIcon = new ImageIcon ();
JButton openButton = new JButton ("Seleccionar archivo ...", openIcon);
openButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
int returnVal = fc.showOpenDialog (Aplicacion.this);

if (returnVal == JFileChooser.APPROVE_OPTION)
{
String[] curso = null;
File file = fc.getSelectedFile ();
fc.getFileFilter();
//this is where a real application would open the file.
log.append ("Abriendo archivo " + file.getPath() + " ... " + HECHO + newline);


// descomprimimos el archivo .zip

try{
log.append("Descomprimiendo archivo " + file.getName());
curso = file.getName().split("_");
curso[1] = "test_002_x";
Unzip desc = new Unzip();
desc.descomprime(file.getPath(), curso[1]);
log.append( " ... " + HECHO);
}catch(Exception ex){
log.append(newline + " Error al descomprimir archivo : " + ex.getMessage());
}


// leemos el archivo xml y restauramos los contenidos

try{

Document docto = null;
Element elemento1 = null;
String archivoXML = System.getProperty("user.home") + File.separator + curso[1] + "_unzip" + File.separator + "imsmanifest.xml";
String cursoId = curso[1];

ParserB app = new ParserB();

log.append(newline + LEYENDO_ARCHIVO_XML);
docto = app.leerArchivoXML(archivoXML);
log.append(HECHO);

log.append( ANALIZANDO_ARCHIVO_XML);
elemento1 = app.analizaArchivoXML(docto);
log.append(HECHO);


log.append(CREANDO_DIRECTORIOS);
app.crearArbolRoot(elemento1, docto, curso[1] + "_unzip", curso[1] + "_backup");
log.append(HECHO);

}catch(SAXException saxEx){
log.append("SAXException " + saxEx.getMessage());
}catch(IOException ioEx){
log.append("IOException " + ioEx.getMessage());
}catch(Exception ex){
log.append("\nException " + ex.getMessage());
}



}
else
{
log.append ("Cancelado..." + newline);
}
}
}
);



JPanel buttonPanel = new JPanel ();
buttonPanel.add (openButton);

Container contentPane = getContentPane ();
contentPane.add (buttonPanel, BorderLayout.NORTH);
contentPane.add (logScrollPane, BorderLayout.CENTER);
}

protected static Image getImage(){
URL imgURL = Aplicacion.class.getResource("iconos/Drive-Backup-32x32.png");


if (imgURL != null)
return new ImageIcon(imgURL).getImage();
else
return null;


}


public static void main (String [] args)
{
JFrame frame = new Aplicacion ();

frame.addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
}
);


frame.pack ();
frame.setSize(800, 600);
frame.setVisible (true);
frame.setIconImage(getImage());
}
}