In the following code I am creating a class which creates a folder in the computer and also adds a jPanel with different options, what happens is that when you press the START button you should open the folder, but I tried several ways without getting results.
public class Carpeta extends JPanel implements ActionListener {
private String direccion = "C:\Users\capri\Privados\";
private String user;
private String nombre;
private JLabel etiqueta;
private JCheckBox ocultar;
private JCheckBox visible;
private JButton start;
public Carpeta(String user, String nombre, String estados) {
setSize(400,100);
this.setLayout(new GridLayout(1,5));
this.etiqueta = new JLabel(nombre);
this.user = user;
this.nombre = nombre;
ocultar = new JCheckBox("OCULTO");
visible = new JCheckBox("VISIBLE");
if(estados.charAt(0)==1){
ocultar.setSelected(true);
}
if(estados.charAt(1)==1){
visible.setSelected(true);
}
start = new JButton("INICIAR");
start.addActionListener(this);
visible.addActionListener(this);
ocultar.addActionListener(this);
add(etiqueta);
add(new JSeparator());
add(start);
add(ocultar);
add(visible);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object ejec = e.getSource();
***en esta parte****************************************
if(ejec == start){
String urlm = direccion+nombre;
ProcessBuilder p = new ProcessBuilder();
p.command("cmd.exe ","\c",urlm);
}
*************************************************************
if(visible.isSelected()){
try{
Runtime.getRuntime().exec("attrib -s -h "+direccion+nombre);
}catch(IOException ex){}
ocultar.setSelected(false);
}else{
ocultar.setSelected(true);
}
if(ocultar.isSelected()){
try{
Runtime.getRuntime().exec("attrib +s +h "+direccion+nombre);
}catch(IOException ex){}
visible.setSelected(false);
}else{
visible.setSelected(true);
}
}
}
I have also used the following, but even so I can not open the folder
if(ejec == start){
try{
Runtime.getRuntime().exec("start "+direccion+nombre);
}catch(IOException ex){}
}
if someone could help me and at the same time explain to me what is the reason why my code does not work.