Foros del Web » Programación para mayores de 30 ;) » Java »

JFileChooser y .exec()

Estas en el tema de JFileChooser y .exec() en el foro de Java en Foros del Web. Hola, tengo un problema, resulta que tengo un JFileChoser que se ejecuta pulsando un boton. Y tambien tengo un Runtime.getRuntime().exec(), que ejecuta un programa (vlc.exe), ...
  #1 (permalink)  
Antiguo 31/08/2010, 00:23
 
Fecha de Ingreso: diciembre-2008
Mensajes: 4
Antigüedad: 15 años, 4 meses
Puntos: 0
JFileChooser y .exec()

Hola, tengo un problema, resulta que tengo un JFileChoser que se ejecuta pulsando un boton. Y tambien tengo un Runtime.getRuntime().exec(), que ejecuta un programa (vlc.exe), pero como puedo decirle que ejecute el archivo del JFileChooser con el programa que le he puesto, pulsando un boton?

Os pongo el codigo, ya se que hay algunas cosas que no sirven de nada, pero mas adelante me serviran con el projecto.
Gracias

Código PHP:
import java.awt.Container;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;

import javax.rmi.CORBA.Util;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

public class 
Traducir extends JFrame implements ActionListener


    private 
JTextField texto;
    private 
JButton boton;
    private 
JButton boton2;
    private 
JButton boton3;
    public 
String linea1;
    public 
String linea2;
    public 
String t;
    public 
String ruta;
    public 
File file;
    public 
File fichero;
    public 
JFileChooser dialogoArchivo ;
    
    public 
Traducir(){
        
super("Traducir");
        
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
this.setSize(400400);
        
this.setLayout(new GridBagLayout());
        
GridBagConstraints gbc = new GridBagConstraints();
        
        
texto = new JTextField(400);
        
boton = new JButton("Seleccionar");
        
boton2 = new JButton("Limpiar");
        
boton3 = new JButton("Traducir");
        
        
        
gbc.gridx 0;
        
gbc.gridy 0;
        
gbc.gridwidth 1;
        
gbc.gridheight 1;
        
gbc.weightx 1.0;
        
gbc.weighty 0.0;
        
gbc.fill GridBagConstraints.HORIZONTAL;
        
add(boton,gbc);
        
boton.addActionListener(this);
        
        
gbc.gridx 1;
        
gbc.gridy 0;
        
gbc.gridwidth 1;
        
gbc.gridheight 1;
        
gbc.weightx 1.0;
        
gbc.weighty 0.0;
        
gbc.fill GridBagConstraints.HORIZONTAL;
        
add(boton2,gbc);
        
boton2.addActionListener(this);
        
        
gbc.gridx 3;
        
gbc.gridy 0;
        
gbc.gridwidth 1;
        
gbc.gridheight 1;
        
gbc.weightx 1.0;
        
gbc.weighty 0.0;
        
gbc.fill gbc.HORIZONTAL;
        
add(boton3,gbc);
        
boton3.addActionListener(this);
        
        
gbc.gridx 0;
        
gbc.gridy 1;
        
gbc.gridwidth 4;
        
gbc.gridheight 1;
        
gbc.weightx 1.0;
        
gbc.weighty 1.0;
        
gbc.fill GridBagConstraints.HORIZONTAL;
        
add(texto,gbc);
        
texto.addActionListener(this);
        
        
this.setVisible(true);
        
        
        
    }
    public 
void actionPerformed(ActionEvent e){
        if(
e.getSource()==boton){
            
            
Container frame this;

            
JFileChooser dialogoArchivo = new JFileChooser();
            

                        
            
            
            
FileNameExtensionFilter filter = new FileNameExtensionFilter(
                    
"Avi""avi");
            
dialogoArchivo.setFileFilter(filter);
             
int returnVal dialogoArchivo.showOpenDialog(frame);
               if (
returnVal == JFileChooser.APPROVE_OPTION) {
                   
String t dialogoArchivo.getCurrentDirectory()+"\\"dialogoArchivo.getSelectedFile();
                   
String ruta dialogoArchivo.getCurrentDirectory()+"\\"dialogoArchivo.getSelectedFile();
                    
texto.setText(t); 
                    
                   
File fichero dialogoArchivo.getSelectedFile();
                  }            
                
                  
File file dialogoArchivo.getSelectedFile();
                                     
                  }
            
                    
        
        
        if(
e.getSource()==boton2){
            
String t2 "";
            
texto.setText(t2);            
        }
        if(
e.getSource()==boton3){
            
            try
            {
                
String [] linea2 = new String [];
                
String linea1 "cmd /c start C:\\Workspace\\Ventana\\src\\a.bat";
                
String linea3  "C:/Program Files (x86)/VideoLAN/VLC/vlc.exe";
                 
Process procesos Runtime.getRuntime().exec(linea3);


            }
            catch( 
Exception e1)
            {
                
e1.printStackTrace();
            }
            
        }
    }
    } 
  #2 (permalink)  
Antiguo 31/08/2010, 19:42
Avatar de HackmanC  
Fecha de Ingreso: enero-2008
Ubicación: Guatemala
Mensajes: 1.817
Antigüedad: 16 años, 3 meses
Puntos: 260
Sonrisa Respuesta: JFileChooser y .exec()

Hola,

¿Enviando parámetros?

Código:
"C:/Program Files (x86)/VideoLAN/VLC/vlc.exe" "C:\Users\Video.avi"
En Java y Windows podría ser algo así:

Código Java:
Ver original
  1. String linea3  = "\"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe\" \"" + ruta + "\"";

Además puedes buscar información sobre,
System.getProperty("path.separator") y File.pathSeparator

Saludos,

Etiquetas: exec, jfilechooser
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:39.