I created a java program with swing ui. firstly, i have a problem when i click in a button i cant click to another. i ought to wait that this one finish his task. so i created a global variable thread and in the action event the thread execute the method. as mintioned in the code below
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        t = new Thread() {
            private int postion;
            public void run() {
                InstallApk installapk = new InstallApk();
                int position = 0;
                String fileName = directory;
                String shellCommand = fileName;
                // for (int position =0; postion < 105;position +5) {
                jProgressBar1.setValue(InstallApk.value);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                }
                position += 5;
                // }
                jProgressBar1.setIndeterminate(true);
                installapk.execShellCmd(shellCommand);
                System.out.println("la valeur d'execution " + InstallApk.value);
                if (InstallApk.value > 3) {
                    jProgressBar1.setIndeterminate(false);
                }
            }
        };
        pid = t.getId();
        t.start();
    } 
i would like to stop the execution of this thread, by using an other button. I tried t.stop(); t.destroy(); kill pid but all the time the some result i can't stop the execution. in the implementation of my metod execShellCmd i used a swing worker but my probleme still how to stop the execution.
public static void execShellCmd(String cmd) {
        if (runningProcess != null) {
            // TODO print some suitable warning about process already running
            return;
        }
        try {
            //testPath = getPath();
            System.out.println("le chemin de travail.." +testPath);
            System.out.println(cmd);
            Runtime runtime = Runtime.getRuntime();
            process = runtime.exec(new String[] { "sh",
                    testPath + "/install.sh", cmd });
            new SwingWorker<Integer, Void>() {
                protected Integer doInBackground() {
                    // read process output first
                    BufferedReader buf = new BufferedReader(
                            new InputStreamReader(process.getInputStream()));
                    String line = "";
                    try {
                        while ((line = buf.readLine()) != null) {
                            System.out.println("exec response: " + line);
                            log = line;
                            writeToFile(line);
                            value ++;
                        }
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                     System.out.println("la valeur d'execution "+InstallApk.value);
                    // only once we've run out of output can we call waitFor
                    while (true) {
                        try {
                            return runningProcess.waitFor();
                        } catch (InterruptedException e) {
                            // do nothing, wait again
                        } finally {
                            Thread.interrupted();
                        }
                    }
                }
                protected void done() {
                    runningProcess = null;
                }
            }.execute();
        } catch (Exception e) {
            System.out.println(e);
        }
    }