1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
   | public class MaClasse
{
	private static final int LARGEUR = 1024;
	private static final int HAUTEUR = 768;
 
	String nomFichierAOuvrir;
 
	public static void main(String[] args)
	{
		MaClasse window = new MaClasse();
		window.open();
	}
 
	public void open()
	{
		final Display display = new Display();
		final Shell shell = new Shell();
		shell.setText("Mon appli");
		shell.setSize(LARGEUR, HAUTEUR);
		{
			final Button button = new Button(shell, SWT.NONE);
			button.addSelectionListener(new SelectionAdapter()
			{
				public void widgetSelected(SelectionEvent e)
				{
				}
			});
			button.setBounds(420, 20, 65, 25);
			button.setText("Browse");
 
			Label lblNomFichier = new Label(shell, SWT.NONE);
			lblNomFichier.setBounds(10, 30, 100, 25);
			lblNomFichier.setText("Nom du fichier : ");
			final Text txtNomFichier = new Text(shell, SWT.BORDER);
			txtNomFichier.setBounds(110, 20, 275, 25);
			txtNomFichier.setText("");
			txtNomFichier.setSize(300, 30);
 
			button.addListener(SWT.Selection, new Listener()
			{
				public void handleEvent(Event e)
				{
					//String nomFichierAOuvrir;
					FileDialog dialog = new FileDialog(shell, SWT.OPEN);
					dialog.setFilterExtensions(new String[] { "*.txt", "*.erc" });
					nomFichierAOuvrir = dialog.open();
					if ((nomFichierAOuvrir != null) && (nomFichierAOuvrir.length() != 0))
					{
						txtNomFichier.setText(nomFichierAOuvrir);
		//Si je mets la ca marche, ca affiche le chemin du fichier choisi
		//System.out.println(nomFichierAOuvrir);						
                }
				}
			});
 
			//si je le mets ici, ca n'affiche rien !!!
			System.out.println(nomFichierAOuvrir);
                    ............... | 
Partager