Usar o JFilechooser dentro JApplet

2 respostas
A
package com.promosoft.Util;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JApplet;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

public class TestarFileChooser extends JApplet {
	private Component me;
	
	//Methods to load on applet initialisation
	public void init() {
		try {
			javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
				public void run() {
					guiLayout();
				}
			});

		} catch (Exception e) {
			System.err.println("guiLayout didn't successfully complete");
		}
		me = this;
	}

	public void start() {

	}

	public void stop() {

	}

	// **********************************************************
	// *														*
	// *	This method dictates the GUI Layout of the Applet 	*
	// *														*
	// **********************************************************

	public void guiLayout() {

		//Where the GUI is created:
		JPanel files_local;

		// The left panel for local file handler
		files_local = new JPanel();
		
		getContentPane().add(files_local, BorderLayout.LINE_START);
			
		final JFileChooser fc = new JFileChooser();
  	
		fc.addChoosableFileFilter(new ImageFilter());
		fc.setAcceptAllFileFilterUsed(false);
		fc.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e)
	    	{
				System.out.println("Cancelar :" + e.getActionCommand());
				String returnAction = e.getActionCommand();
	      		
	      		if (returnAction.equals(JFileChooser.APPROVE_SELECTION))
	      		{
	        		File file = fc.getSelectedFile();
	        		if (file!=null)
	        		{
	        			 System.out.println("Valor do File: "+file.getAbsolutePath());
	        		}
	      		}
	    	}
		
		});
		
		//Add custom icons for file types.
		fc.setFileView(new ImageFileView());

		//Add the preview pane.
		fc.setAccessory(new ImagePreview(fc));

		//Reset the file chooser for the next time it's shown.
		fc.setSelectedFile(null);

		files_local.add("Center", fc);
		
		fc.validate();

	}

}
[size="11"][color="red"]* Editado: Lembre-se de utilizar BBCode em seus códigos - Ratinho[/color][/size] :joia:

2 Respostas

C

O que você quer que isso faça?

J

Se você falar o que quer fica mais facil, mas já adiantando: não dá pra usar JFileChooser em um Applet sem assina-lo, questão de segurança!

Criado 25 de julho de 2006
Ultima resposta 25 de jul. de 2006
Respostas 2
Participantes 3