java - Why Event Dispatch Thread can't create new EDT? -


when creating "cnc control" program , wanted create file browser loading or saving drilling plan. made simple file browser , tested [works fine], in main class when actionlistener used construct new edt, ui/jframe freezes , main thread keeps going.

nowadays know how go around obstacle using variable(s) in main thread , execute browser them.

in short: edt thread right? why can not create event dispatch thread other thread?

edit: didn't know there can 1 edt per java application , freezing caused infinite loop inside of it. madprogrammer clearing things up.

sorry pile of text below. (my classes difficult separate)

here example if english ridiculously bad/i'm confusing you:

working main class:

import java.awt.borderlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener;  import javax.swing.jbutton; import javax.swing.jframe;  public class main { //functions: static void loadsavewhatever(){     filebrowser fb=new filebrowser();                                   //create browser class  success!     fb.createwindow(filebrowser.save,"c:\\",new string[]{".txt"});  //create browser...but it's never completed!?     while(fb.done()==false&fb.w!=null){                                 // wait 'till fb kills         system.out.println("waitting address.. plus still runing!");         if(fb.w.isvisible()==false){             break;         }try {             thread.sleep(1000);             //because of spamming , less power consuming         } catch (interruptedexception e) {             e.printstacktrace();            // never happened it's there         }     }system.out.println("target: "+fb.gettarget()); //print target file }  static boolean saveorload=false;  public static void main(string[] args) {     //set things     jframe w=new jframe();                                  //main window     jbutton b=new jbutton("open (quite old/bad/laggy) browser");//the button     boolean alive=true;     long t=0;               //auto close      //edt?     b.addactionlistener(new actionlistener(){         @override         public void actionperformed(actionevent arg0) {             saveorload=true;         }     });      //construct     w.setdefaultcloseoperation(jframe.exit_on_close);       //making sure javaw.exe dies after w closed     w.setvisible(true);                                     //...     w.getcontentpane().add(b,borderlayout.center);          //put button in jframe     w.pack();      //main loop     t=system.currenttimemillis();     while(alive){         if(system.currenttimemillis()-t>(3*60*1000)){       //close program after 3 min             alive=false;         }if(saveorload){             loadsavewhatever();             saveorload=false;         }try {             thread.sleep(1000);         } catch (interruptedexception e) {             e.printstacktrace();         }     } } }` 

freezing main class

        import java.awt.borderlayout;     import java.awt.event.actionevent;     import java.awt.event.actionlistener;      import javax.swing.jbutton;     import javax.swing.jframe;      public class main2 {         //functions:             static void loadsavewhatever(){                 filebrowser fb=new filebrowser();                                   //create browser class  success!                 fb.createwindow(filebrowser.save,"c:\\",new string[]{".txt"});  //create browser...but it's never completed!?                 while(fb.done()==false&fb.w!=null){                                 // wait 'till fb kills                     system.out.println("waitting address.. plus still runing!");                     if(fb.w.isvisible()==false){                         break;                     }try {                         thread.sleep(1000);             //because of spamming , less power consuming                     } catch (interruptedexception e) {                         e.printstacktrace();            // never happened it's there                     }                 }system.out.println("target: "+fb.gettarget()); //print target file             }              public static void main(string[] args) {                 //set things                 jframe w=new jframe();                                  //main window                 jbutton b=new jbutton("open (quite old/bad/laggy) browser");//the button                 boolean alive=true;                 long t=0;               //auto close                  //edt?                 b.addactionlistener(new actionlistener(){                     @override                     public void actionperformed(actionevent arg0) {                         loadsavewhatever();                     }                 });                  //construct                 w.setdefaultcloseoperation(jframe.exit_on_close);       //making sure javaw.exe dies after w closed                 w.setvisible(true);                                     //...                 w.getcontentpane().add(b,borderlayout.center);          //put button in jframe                 w.pack();                  //main loop                 t=system.currenttimemillis();                 while(alive){                     if(system.currenttimemillis()-t>(10*1000)){     //close program after 3 min [not work!!!!! need use kill switch]                         alive=false;                     }try {                         thread.sleep(1000);                     } catch (interruptedexception e) {                         e.printstacktrace();                     }                 }             }     } 

the filebrowser class:

    import java.awt.borderlayout;     import java.awt.dimension;     import java.awt.gridlayout;     import java.awt.event.actionevent;     import java.awt.event.actionlistener;     import java.awt.event.mouseevent;     import java.awt.event.mouselistener;     import java.io.file;     import java.io.ioexception;      import javax.swing.jbutton;     import javax.swing.jcombobox;     import javax.swing.jframe;     import javax.swing.jlist;     import javax.swing.jpanel;     import javax.swing.jscrollpane;     import javax.swing.jtextarea;     import javax.swing.jtextfield;     import javax.swing.border.titledborder;     import javax.swing.event.listselectionevent;     import javax.swing.event.listselectionlistener;      import data.dataconverter;     import file.browser;      public class filebrowser{         public volatile jframe w;         public browser brow=new browser();          private jbutton back;         private jbutton goto;         private jbutton save;         private jbutton cancel;          private jtextfield newadd;         private jtextarea folderinfo;         private jtextarea fileinfo;         private jtextfield name;         private jpanel gotobar;         private jpanel top;         private jpanel mainp;         private jpanel cenl;         private jpanel cenr;         private jpanel downrigth;         private jpanel downcen;         private jpanel downleft;         private jpanel center;         private jpanel down;         private jpanel file;         private jpanel folder;         private jpanel filei;         private jpanel folderi;          private jcombobox<string> hdp;         private jcombobox<string> format;         private jlist<string> filep;         private jlist<string> folderp;          private jscrollpane main;         private jscrollpane filepane;         private jscrollpane folderpane;          private long lastclick=0;         public static int browser=0;         public static int save=1;         public static int load=2;          private volatile string target="";     private volatile boolean tselected=false;      public synchronized boolean done(){         return tselected;     }     public synchronized string gettarget(){         return target;     }        public synchronized void updatehds(){         if(brow!=null&hdp!=null){             string[] s=brow.getharddrivesstring();             if(s!=null){                 hdp.removeallitems();                 for(int a=0;a<s.length;a++){                     hdp.additem(s[a]);                 }             }         }     }     public synchronized void updatefiles(){         if(brow!=null&hdp!=null){             if(filep!=null){                 string[] s=brow.getfilesstring(null);                 if(s!=null){                     filep.setlistdata(s);                 }else{                     filep.setlistdata(new string[1]);                 }             }         }     }     public synchronized void updatefolders(){         if(brow!=null&hdp!=null){             if(folderp!=null){                 string[] s=brow.getfoldersstring(null);                 if(s!=null){                     folderp.setlistdata(s);                 }else{                     folderp.setlistdata(new string[1]);                 }             }         }     }     public synchronized void updatetop(){         if(newadd!=null&goto!=null){             if(newadd.gettext()!=brow.getcurrentpath()+file.separator){                 newadd.settext(brow.getcurrentpath()+file.separator);             }         }     }     public synchronized void setformats(string[] s){         if(s!=null&format!=null){             format.removeallitems();             for(int a=0;a<s.length;a++){                 format.additem(s[a]);             }         }     }     public synchronized void update(){         updatefolders();         updatefiles();         updatetop();         w.pack();     }     public synchronized void destroy(){         if(w!=null){             w.dispose();             w=null;         }tselected=true;     }      public synchronized void createwindow(int windowtype,string startadd,string[] formats){         try{             w.removeall();             w.setvisible(false);         }catch(nullpointerexception e){         }if(brow==null){             brow=new browser();         }brow.setaddress(startadd);         w=null;w=new jframe();w.setdefaultcloseoperation(jframe.dispose_on_close);         mainp=null;         down=null;         hdp=null;         filep=null;         folderp=null;         main=null;          folderi=new jpanel();         filei=new jpanel();         mainp=new jpanel();         top=new jpanel();         gotobar=new jpanel();         down=new jpanel();         file=new jpanel();         folder=new jpanel();         cenl=new jpanel();         center=new jpanel();         cenr=new jpanel();         downrigth=new jpanel();         downcen=new jpanel();         downleft=new jpanel();          save=new jbutton();         cancel=new jbutton();         back=new jbutton("folder up");         goto=new jbutton("go to");           hdp=new jcombobox<string>();         format=new jcombobox<string>();          filep=new jlist<string>();         folderp=new jlist<string>();            folderinfo=new jtextarea();         fileinfo=new jtextarea();          name=new jtextfield();         newadd=new jtextfield();          updatehds();          top.setlayout(new borderlayout());         hdp.addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent ae) {                 if(brow==null){                     brow=new browser();                 }brow.setaddress(""+hdp.getselecteditem());                 update();             }         });         folderp.addlistselectionlistener(new listselectionlistener(){             @override             public void valuechanged(listselectionevent e) {                 if(folderinfo!=null){                     string[] s=brow.getinfostring(brow.getcurrentpath()+file.separator+folderp.getselectedvalue());                     folderinfo.settext(dataconverter.stringstostring(s));w.pack();                 }             }         });         folderp.addmouselistener(new mouselistener(){             @override             public void mouseclicked(mouseevent e) {                 if(e.getbutton()==1){                     if(lastclick+700>=system.currenttimemillis()){                         if(folderp.getselectedindex()>=0){                             if(brow.type==-1){                                 brow.setaddress(folderp.getselectedvalue());                             }else{                                 brow.setaddress(brow.getcurrentpath()+file.separator+folderp.getselectedvalue()+file.separator);                             }update();                         }                     }else{                         lastclick=system.currenttimemillis();                     }                 }else{                     if(e.getbutton()==3){                         if(brow.getcurrentpath()!=null){                             brow.folderup();                             update();                         }                     }                 }              }             @override             public void mouseentered(mouseevent e) {             }             @override             public void mouseexited(mouseevent e) {             }             @override             public void mousepressed(mouseevent e) {             }             @override             public void mousereleased(mouseevent e) {             }         });         filep.addlistselectionlistener(new listselectionlistener(){             @override             public void valuechanged(listselectionevent e) {                 if(fileinfo!=null){                     string[] s=brow.getinfostring(brow.getcurrentpath()+file.separator+filep.getselectedvalue());                     fileinfo.settext(dataconverter.stringstostring(s));w.pack();                 }             }         });         filep.addmouselistener(new mouselistener(){             @override             public void mouseclicked(mouseevent e) {                 if(e.getbutton()==1){                     if(lastclick+700>=system.currenttimemillis()){                         if(filep.getselectedindex()>=0){                             try {                                 runtime.getruntime().exec("rundll32 shell32.dll,shellexec_rundll "+brow.getcurrentpath()+file.separator+filep.getselectedvalue());                             } catch (ioexception e1) {                                 e1.printstacktrace();                             }                         }                     }else{                         lastclick=system.currenttimemillis();                     }                 }else{                     if(e.getbutton()==3){                         if(brow.getcurrentpath()!=null){                             brow.folderup();                             update();                         }                     }                 }              }             @override             public void mouseentered(mouseevent e) {             }             @override             public void mouseexited(mouseevent e) {             }             @override             public void mousepressed(mouseevent e) {             }             @override             public void mousereleased(mouseevent e) {             }         });         back.addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent e) {                 if(brow.getcurrentpath()!=null){                     brow.folderup();                     update();                 }             }         });         goto.addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent e) {                 if(brow!=null){                     file tf=new file(newadd.gettext());                     if(tf.exists()){                         if(tf.isdirectory()){                             brow.setaddress(newadd.gettext());                             update();                         }else{                             brow.setaddress(tf.getparent());                             update();                         }                     }                 }             }         });         cancel.addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent arg0) {                 destroy();             }         });          gotobar.setlayout(new borderlayout());         newadd.setpreferredsize(new dimension(650,20));         gotobar.add(newadd,borderlayout.west);         gotobar.add(goto,borderlayout.center);         gotobar.add(back,borderlayout.east);         top.add(gotobar);          filepane=new jscrollpane(filep);         folderpane=new jscrollpane(folderp);          folder.setlayout(new borderlayout());         folder.setborder(new titledborder("folders:"));         folder.add(folderpane);         file.setlayout(new borderlayout());         file.setborder(new titledborder("files:"));         file.add(filepane);          cenl.setlayout(new gridlayout(2,1));         cenl.setpreferredsize(new dimension(420,500));         cenl.add(folder);         cenl.add(file);          folderi.setborder(new titledborder("folder info:"));         filei.setborder(new titledborder("file info:"));          folderinfo.seteditable(false);         fileinfo.seteditable(false);          folderi.add(new jscrollpane(folderinfo));         filei.add(new jscrollpane(fileinfo));          cenr.setlayout(new gridlayout(2,1));         cenr.add(folderi);         cenr.add(filei);          center.setlayout(new borderlayout());         center.add(cenl,borderlayout.center);         center.add(cenr,borderlayout.line_end);          downleft.setlayout(new borderlayout());         downleft.setborder(new titledborder("quick"));         downleft.add(hdp);          downcen.setlayout(new gridlayout(2,1));         downcen.add(name);         downcen.add(format);          downrigth.setlayout(new gridlayout(2,2));         downrigth.add(save);         downrigth.add(cancel);          down.setlayout(new borderlayout());         down.add(downleft,borderlayout.line_start);         down.add(downcen,borderlayout.center);         down.add(downrigth,borderlayout.line_end);          mainp.setlayout(new borderlayout());         mainp.add(top,borderlayout.north);         mainp.add(center,borderlayout.center);         mainp.add(down,borderlayout.south);          update();         main=new jscrollpane(mainp);          switch(windowtype){         default:             w.settitle("file browser module v2.0");             save.settext("[unavailable]");             tselected=true;             cancel.settext("close");             break;         case 1:             w.settitle("save [whatever] to..");             save.settext("save");              save.addactionlistener(new actionlistener(){                 @override                 public void actionperformed(actionevent arg0) {                     if(brow.type!=-1){                         if(name.gettext().length()>0){                             target=brow.getcurrentpath()+file.separator+name.gettext()+format.getselecteditem();                             tselected=true;                             destroy();                         }                     }                 }             });             cancel.settext("cancel");             break;         case 2:             w.settitle("load [whateverlongasiacceptit] from...");             save.settext("open");             save.addactionlistener(new actionlistener(){                 @override                 public void actionperformed(actionevent arg0) {                     if(brow.type!=-1){                         if(filep.getselectedindex()>=0){                             target=brow.getcurrentpath()+file.separator+filep.getselectedvalue();                             tselected=true;                             destroy();                         }                     }                 }             });             cancel.settext("cancel");                 break;             }w.getcontentpane().add(main);             setformats(formats);             w.pack();             w.setvisible(true);             w.setautorequestfocus(true);         }        } 

dataconverter class

        public class dataconverter {         public static int int=1;         public static int char=2;         public static int string=3;         public static int intlist=4;         public static int charlist=5;         public static int stringlist=6;          public static string chartostring(char c){             return (""+c);         }         public static string charstostring(char[] c){             string s="";             if(c!=null){                 if(c.length>0){                     for(int a=0;a<c.length;a++){                         s=s+(""+c[a]);                     }return s;                 }             }return null;         }         public static int chartoint(char c){             return ((int)c);         }         public static int[] charstoints(char[] c){             int[] i;             if(c!=null){                 if(c.length>0){                     i=new int[c.length];                     for(int a=0;a<c.length;a++){                         i[a]=((int)c[a]);                     }return i;                 }             }return null;         }         public static char stringtochar(string s){             if(s!=null){                 if(s.length()>0){                     return s.charat(0);                 }             }return 0;         }         public static char[] stringtochars(string s){             if(s!=null){                 if(s.length()>0){                     char[] c=new char[s.length()];                     for(int a=0;a<c.length;a++){                         c[a]=s.charat(a);                     }return c;                 }             }return null;         }         public static int stringtoint(string s){             if(s!=null){                 if(s.length()>0){                     return ((int)s.charat(0));                 }             }             return 0;         }         public static int[] stringtoints(string s){             if(s!=null){                 if(s.length()>0){                     int[] i=new int[s.length()];                     for(int a=0;a<i.length;a++){                         i[a]=((int)s.charat(a));                     }return i;                 }             }return null;         }         public static char inttochar(int i){             return ((char)i);         }         public static char[] intstochars(int[] i){             if(i!=null){                 if(i.length>0){                     char[] c=new char[i.length];                     for(int a=0;a<i.length;a++){                         c[a]=((char)i[a]);                     }return c;                 }             }return null;         }         public static string inttostring(int i){             return ""+((char)i);         }         public static string intstostring(int[] i){             if(i!=null){                 if(i.length>0){                     string s="";                     for(int a=0;a<i.length;a++){                         s=s+""+((char)i[a]);                     }return s;                 }             }return null;         }         public static string stringstostring(string[] s){             if(s!=null){                 if(s.length>0){                     string s="";                     for(int a=0;a<s.length;a++){                         s=s+s[a]+system.lineseparator();                     }return s;                 }             }return null;         }         public static string[] stringtostrings(string s){             if(s!=null){                 int a=0;                 int c=0;                 for(int b=0;b<s.length();b++){                     if(s.substring(b,b+1).equals(system.lineseparator())){                         a++;                     }                 }string[] s=new string[1+a];                 for(int b=0;b<s.length;b++){                     if(s.substring(b,b+1).equals(system.lineseparator())){                         s[c]=s.substring(a,b);                         a=b;                     }                 }             }return null;         }          public static int getdatatypeof(object clip){             try{                 if(clip.getclass().getsimplename().equals("int[]")){                     return dataconverter.intlist;                 }if(clip.getclass().getsimplename().equals("char[]")){                     return dataconverter.charlist;                 }if(clip.getclass().getsimplename().equals("string[]")){                     return dataconverter.stringlist;                 }if(clip instanceof integer){                     return dataconverter.int;                 }if(clip instanceof character){                     return dataconverter.char;                 }if(clip instanceof string){                     return dataconverter.string;                 }             }catch(nullpointerexception e){             }return 0;         }          public static object convertto(object datafrom,int to){             try{                 int[] out = null;                 switch(getdatatypeof(datafrom)){                 case 3:                     out=stringtoints((string)datafrom);                     break;                 case 4:                     out=(int[])datafrom;                     break;                 case 5:                     out=charstoints((char[])datafrom);                     break;                 case 6:                     out=stringtoints(stringstostring((string[])datafrom));                     break;                 }                 switch(to){                 case 3:                     return intstostring(out);                 case 4:                     return out;                 case 5:                     return intstochars(out);                 case 6:                     return stringtostrings(intstostring(out));                 }             }catch(nullpointerexception e){             }return null;         }          public static int[] toeigthbit(int value){             int[] o=new int[4];             int v=value;             o[0]=v/(255*255*255);   //255*255*255*255             v=v-(o[0]*255*255*255);             o[1]=v/(255*255);       //255*255*255             v=v-(o[1]*255*255);             o[2]=v/(255);           //255*255             v=v-(o[2]*255);             o[3]=v;             return o;         }         public static int fromeigthbit(int[] value){             long o=value[3];             o=o+value[2]*255;             o=o+value[1]*255*255;             o=o+value[0]*255*255*255;             return (int)o;         }      } 

and last needed class, browser:

        import java.io.file;     import java.io.ioexception;      public class browser {         file f;         file[] files;         public int type=-1;         //-1=not exist, 0=folder, 1=file         string hdl="abcdefghijklmnopqrstuvwxyz";         file[] hds;          public void updateharddrives(){             file t;             int b=0;             for(int a=0;a<hdl.length();a++){                 t=new file(hdl.substring(a,a+1)+":"+file.separator);                 if(t.exists()){                     b++;                 }             }if(b>0){                 hds=new file[b];                 int c=0;                 for(int a=0;a<hdl.length();a++){                     t=new file(hdl.substring(a,a+1)+":"+file.separator);                     if(t.exists()){                         hds[c]=new file(hdl.substring(a,a+1)+":"+file.separator);                         c++;                     }                 }             }         }         public boolean updateaddress(){             if(f!=null){                 if(f.exists()){                     if(f.canread()){                         if(f.isdirectory()){                             files=f.listfiles();                             type=0;                         }else{                             files=null;                             type=1;                         }return true;                     }                 }type=-1;             }return false;         }          public boolean setaddress(string add){             if(add!=null){                 f=new file(add);                 if(f.exists()){                     if(f.isfile()){                         type=1;                     }else{                         type=0;                     }return this.updateaddress();                 }return false;             }else{                 type=-1;                 updateharddrives();                 files=new file[hds.length];                 for(int a=0;a<files.length;a++){                     files[a]=new file(hds[a].getabsolutepath());                 }             }return false;         }         public string getcurrentpath(){             if(f!=null&type!=-1){                 return f.getabsolutepath();             }return null;         }          public string[] getinfostring(string add){             string[] s=null;             if(add!=null){                 file tf=new file(add);                 if(tf.exists()){                     if(tf.isdirectory()){                         s=new string[13];                         s[0]=""+tf.getname();                         s[1]="type:\tfolder";                         s[2]="is readable:\t"+tf.canread();                         s[3]="is writable:\t"+tf.canwrite();                         s[4]="is executable:\t"+tf.canexecute();                         s[5]="is hidden:\t"+tf.ishidden();                         s[6]="absolute path:\t"+tf.getabsolutepath();                         try {                             s[7]="canonical path:\t"+tf.getcanonicalpath();                         } catch (ioexception e) {                             s[7]="canonical path:\t"+"error";                         }s[8]="folders size:\t"+tf.length()+" byte(s)";                         s[9]="usable space:\t"+tf.getusablespace()+" byte(s)";                         s[10]="free space:\t"+tf.getfreespace()+" byte(s)";                         s[11]="total space:\t"+tf.gettotalspace()+" byte(s)";                         s[12]="parent address:\t"+tf.getparent();                     }if(tf.isfile()){                         s=new string[13];                         s[0]=""+tf.getname();                         s[1]="type:\tfile";                         s[2]="is readable:\t"+tf.canread();                         s[3]="is writable:\t"+tf.canwrite();                         s[4]="is executable:\t"+tf.canexecute();                         s[5]="is hidden:\t"+tf.ishidden();                         s[6]="absolute path:\t"+tf.getabsolutepath();                         try {                             s[7]="canonical path:\t"+tf.getcanonicalpath();                         } catch (ioexception e) {                             s[7]="canonical path:\t"+"error";                         }s[8]="files size:\t"+tf.length()+" byte(s)";                         s[9]="usable space:\t"+tf.getusablespace()+" byte(s)";                         s[10]="free space:\t"+tf.getfreespace()+" byte(s)";                         s[11]="total space:\t"+tf.gettotalspace()+" byte(s)";                         s[12]="parent address:\t"+tf.getparent();                     }return s;                 }             }else{system.out.println("failed: ");                 if(f!=null){                     if(f.exists()){                      }                 }             }return s;         }         public string[] getnamesstring(string add){             string[] s=null;             if(add!=null){                 file tf=new file(add);                 if(tf.isdirectory()){                     if(2<tf.list().length){                         s=tf.list();                     }                 }             }else{                 if(f!=null){                     if(f.isdirectory()){                         s=f.list();                     }                 }             }return s;         }         public string[] getfilesstring(string add){             string[] s=null;             file[] fi=null;             if(add!=null){                 file tf=new file(add);                 if(tf.isdirectory()){                     fi=tf.listfiles();                     if(fi!=null){                         int b=0;                         for(int a=0;a<fi.length;a++){                             if(fi[a].isfile()){                                 b++;                             }                         }s=new string[b];b=0;                         for(int a=0;a<fi.length;a++){                             if(fi[a].isfile()&b<s.length){                                 s[b]=fi[a].getname();b++;                             }                         }                     }                 }             }else{                 if(f!=null&type!=-1){                     if(f.isdirectory()){                         fi=f.listfiles();                         if(fi!=null){                             int b=0;                             for(int a=0;a<fi.length;a++){                                 if(fi[a].isfile()){                                     b++;                                 }                             }s=new string[b];b=0;                             for(int a=0;a<fi.length;a++){                                 if(fi[a].isfile()&b<s.length){                                     s[b]=fi[a].getname();b++;                                 }                             }                         }                     }                 }             }return s;         }         public string[] getfoldersstring(string add){             string[] s=null;             file[] fi=null;             if(add!=null){                 file tf=new file(add);                 if(tf.isdirectory()){                     fi=tf.listfiles();                     if(fi!=null){                         int b=0;                         for(int a=0;a<fi.length;a++){                             if(fi[a].isdirectory()){                                 b++;                             }                         }s=new string[b];b=0;                         for(int a=0;a<fi.length;a++){                             if(fi[a].isdirectory()&b<s.length){                                 s[b]=fi[a].getname();b++;                             }                         }                     }                 }             }else{/*                 if(f!=null){                     if(f.isdirectory()){                         fi=f.listfiles();                         if(fi!=null){                             int b=0;                             for(int a=0;a<fi.length;a++){                                 if(fi[a].isdirectory()){                                     b++;                                 }                             }s=new string[b];b=0;                             for(int a=0;a<fi.length;a++){                                 if(fi[a].isdirectory()&b<s.length){                                     s[b]=fi[a].getname();b++;                                 }                             }                         }                     }                 }*/                 if(files!=null){                     int b=0;                     for(int a=0;a<files.length;a++){                         if(files[a].isdirectory()){                             b++;                         }                     }s=new string[b];b=0;                     for(int a=0;a<files.length;a++){                         if(files[a].isdirectory()){                             if(type!=-1){                                 s[b]=files[a].getname();                                 b++;                             }else{                                 s[b]=""+files[a];                                 b++;                             }                         }                     }                 }             }return s;         }         public string[] getharddrivesstring(){             string[] s=null;             this.updateharddrives();             //try{                 s=new string[hds.length];                 for(int a=0;a<hds.length;a++){                     s[a]=hds[a].getabsolutepath();                 }             return s;         }         public void folderup(){             string nadd=f.getparent();             setaddress(nadd);         }     } 

the main issues seem having misunderstanding of concurrency , how event dispatching thread works.

swing (and gui frameworks) single threaded environment. interactions ui must done within context of edt. time want create or change ui, must done within edt.

all events raised edt (such actionperformed) done context of edt.

the edt pops event off event queue , processes it, notifying interested parties has occurred, until interested parties return call, edt can not process more events.

like thread, if perform long running or call blocking process, nothing else can executed until block of code completes.

so, in code, wonderful loops blocking edt, preventing processing new events , causing application appear blocked.

your "working" example fluke, side effect of fact build ui within main thread , starting looping here, actionperformed method called edt

start having read through...

also, instead of using jframe, should using modal jdialog, has own mechanism blocking code execution within edt, without blocking edt itself.

take @ how use dialogs, may consider using jfilechooser instead


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -