2015-09-18 64 views
2

我是法國人,所以我的英語不是很美。 我的問題是,當我啓動我的程序時,我的第二個窗口JfileChooser未打開。 我不明白爲什麼。你可以幫我嗎?java中的JFileChooser

我的主類:

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package ged; 

import java.awt.Component; 
import java.io.File; 
import java.util.Scanner; 
import javax.swing.JFileChooser; 

/** 
* 
* @author Evan 
*/ 
public class GED { 
    private static String Nom_Client; 
    private static String N_plan; 
    private static String ind; 
    private static String Reference; 
    private static String Typologie; 

    public static void main(String[] args) throws Exception { 
     // TODO code application logic here 

     System.out.println("****************** TPS Gestionnaire ******************"); 
     System.out.println(" "); 

     System.out.println("Quel fichier choisissez vous ?"); 

     JFileChooser file = new JFileChooser(); 
     file.setFileSelectionMode(JFileChooser.FILES_ONLY); 
     file.setMultiSelectionEnabled(false); 
      int retour = file.showOpenDialog(null); 
       if(retour == JFileChooser.APPROVE_OPTION) 
       { 
        File[] fichier=file.getSelectedFiles(); 
         for(int i = 1; i<fichier.length; ++i) 
         { 
         fichier[i].getName();  
         fichier[i].getAbsolutePath(); 
         } 
         System.out.println("Fichier choisi : " + file.getSelectedFile().getName()); 
       } 
       else 
       { 
        System.out.println("Aucun de fichier choisi"); 
       }  

     System.out.println (" "); 

     System.out.println("Veuillez indiquer le nom du client"); 
     Scanner name = new Scanner (System.in); 
     String Nom_Client = name.nextLine(); 
     System.out.println("L'entreprise est: " + Nom_Client.toUpperCase()); 

     System.out.println ("Dans quel sous doussier souhaitez vous mettre votre document ?"); 
     System.out.println (" "); 
     System.out.println ("1." + " PV Contrôle "); 
     System.out.println ("2." + " Plan "); 

     Scanner sr = new Scanner (System.in); 
     int i = sr.nextInt(); 
     Categorie c = new Categorie (Nom_Client.toUpperCase(),"0","0","0","0"); 
     if (i==1) 
      { 
       c.PVControle(); 
      } 
     else 
      { 
       c.Plan(); 

       System.out.println (" Veuillez choisir la nouvelle destination du fichier"); 
       System.out.println(" "); 
       Parcourir e = new Parcourir(); 
       e.Enregistrer(); 

      } 

    } 

} 

我Parcourir類:

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package ged; 

import java.io.File; 
import java.io.IOException; 
import javax.swing.JFileChooser; 

/** 
* 
* @author Evan 
*/ 
public class Parcourir { 

    public void Enregistrer() throws IOException 

     { 
       JFileChooser newdestination = new JFileChooser(); 
       newdestination.setCurrentDirectory(new File("/Users/Evan/"));//Chemin 
       newdestination.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
       newdestination.showOpenDialog(null); 

       newdestination.setMultiSelectionEnabled(false); 
       int dest = newdestination.showOpenDialog(null); 
        if(dest == JFileChooser.APPROVE_OPTION) 
        { 
        File[] fichier02=newdestination.getSelectedFiles(); 
         for(int t = 1; t<fichier02.length; ++t) 
         { 
         fichier02[t].getName();  
         fichier02[t].getAbsolutePath(); 
         } 
        System.out.println("Destination choisie : " + newdestination.getSelectedFile().getName()); 

        /*File source = file.getSelectedFile(); //Permet de récupérer le chemin du début 
        File destination = new File (newdestination.getSelectedFile() + Nom_Client.toUpperCase()+" "+ c.getN_plan()+ " " + "Ind" + " "+ c.getind().toUpperCase() +".pdf"); // Permet d'avoir la nouvelle destination avec le fichier renommé 
        source.renameTo(destination); //Pas encore corrigé 
        System.out.println(" Votre fichier à été renommé puis déplacé"); */  
        } 
        else 
        { 
        System.out.println("Aucune destination choisie"); 
        } 
     }   

} 

而且我Catégorie類:

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package ged; 

import java.awt.Component; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Scanner; 
import javax.swing.JButton; 
import javax.swing.JFileChooser; 

/** 
* 
* @author Evan 
*/ 
public class Categorie { 
    private String Nom_Client; 
    private String N_plan; 
    private String ind; 
    private String Reference; 
    private String Typologie; 


    public Categorie(String Nom_Client, String N_plan, String ind, String Reference, String Typologie) { 
     this.Nom_Client = Nom_Client; 
     this.N_plan = N_plan; 
     this.ind = ind; 
     this.Reference = Reference; 
     this.Typologie = Typologie; 
    } 


    public void PVControle() throws IOException{ 

     int t = 0; 
     System.out.println("Vous avez choisit la catégorie PV de contrôle"); 
     System.out.println("Veuillez indiquer la référence produit"); 
     Scanner ref = new Scanner (System.in); 
     this.Reference = ref.nextLine(); //Permet de demander la reference du plan 
     System.out.println("Ainsi que la typologie de production"); 
     System.out.println("1." + "TÔLES"); 
     System.out.println("2." + "BOB"); 
     Scanner typ = new Scanner (System.in); 
     this.Typologie = ref.nextLine(); //Permet de demander la typologie 

     if (t == 1) 
      { 

       System.out.println (" Vous avez choisit la typologie TÔLES "); 
       this.Typologie = "TÔLES"; 
      } 

     else 
      { 
       System.out.println(" Vous avez choisit la typologie BOB "); 
       this.Typologie = "BOB"; 
      } 

     System.out.println("Le nom du fichier est: " +Nom_Client + " " + "REF" + " " + Reference.toUpperCase() + " " + "-" + " " + Typologie);  
    } 

    public void Plan() throws IOException { 
     System.out.println("Vous avez choisit la catégorie Plan");   
     System.out.println("Veuillez indiquer le n° Plan"); 
     Scanner plan = new Scanner (System.in); 
     N_plan = plan.nextLine(); //Permet de demander le n°Plan   
     System.out.println ("Ainsi que l'IND"); 
     Scanner IND = new Scanner (System.in);//Demande de l'IND 
     ind = IND.nextLine();   
     System.out.println("Le nom du fichier est: " +Nom_Client + " " + N_plan + " " + "Ind" +" " + ind.toUpperCase());   

    } 


    public String getN_plan() 
    { 
    return N_plan; 
    } 

    public String getind() 
    { 
     return ind; 
    } 

} 
+0

你會得到任何錯誤? –

+0

快速蝸牛:不,我沒有任何錯誤 –

+0

Danio,第一個窗口在主要類的開始,第二個在Parcourir類,並在主類的末尾詢問:Parcourir e = new Parcourir(); e.Enregistrer(); –

回答

0

這是因爲你的掃描儀,第二個窗口只有在您輸入掃描儀後纔會打開(按Enter鍵)。我嘗試過,並且在喂兩次掃描儀後打開第二個對話框。

+0

你能解釋一下,因爲我不明白請 –

+0

啓動程序,選擇文件並點擊打開按鈕,輸入客戶名稱,按回車,輸入2(計劃),然後按Enter鍵,第二個對話框將打開。 –

+0

爲什麼?我需要刪除一些東西? –