Java SwingWorker传递参数并返回

时间:2012-03-12 20:49:23

标签: java multithreading swing swingworker

我想传递String s, ArrayList<String> als并返回 ArrayList<String> als

Run.java

class Run extends SwingWorker<String, Void>
{
    private ArrayList<String> als;
    private String s;


    public Run(String s, ArrayList<String> als) {
       this.s = s;
       this.als = als;
    }

    public String doInBackground()
    {
        return AnotherClass.doSomething(s, als);
    }

    public void done()
    {
        try 
        { 
        } 
        catch (Exception ignore) 
        {
        }
    }
}

AnotherClass.java

public class AnotherClass{
    public static String doSomething(String ipRange, ArrayList<String> nmapPorts) {
        //do some stuff with the strings
        try{
            ProcessBuilder builder = new ProcessBuilder("someexe", "flag", cmds,
            "&cd");
            builder.redirectErrorStream(true);
            Process pr = builder.start();
            //do some stuff with the stream.
            return aString;
        }catch (IOException e){}
    }
}

0 个答案:

没有答案