繁体   English   中英

Java中的JFileChooser

[英]JFileChooser in 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;
    }

}

由于扫描仪的缘故,只有在您向扫描仪提供一些输入(按Enter键)后,第二个窗口才会打开。 我尝试了两次,然后两次喂入扫描仪,然后打开了第二个对话框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM