java - Waiting for Drag and Drop gesture before executing a method -


i have class called filedragdemo purpose drag , drop (dnd) pdf file gui, , once done shows path of file dropped. let’s call step 1, works fine! want save file path string variable stringfile want use , pass on different class pdfeasymanager.

step 2 run class pdfeasymanager(after previous step completed) , pass on stringfile variable. struggling- created method called callclass want execute after of step 1 completed (dnd , string variable stored); in other words, want method callclass last step taken in filedragdemo class. when place callclass last item in main method, program executes before dnd gesture… in other words, program not wait user dnd file before calls pdfeasymanager. have tried changing location of callclass different errors. sorry comments in code trying different things..

below code filedragdemo:

import java.awt.datatransfer.dataflavor; import java.awt.datatransfer.unsupportedflavorexception; import java.io.file; import java.io.ioexception; import java.util.arraylist; import java.util.list; import javax.swing.*;  @suppresswarnings("serial") public class filedragdemo extends jpanel {   public static string stringfile;  public jlist list = new jlist();    public filedragdemo() {   list.setdragenabled(true);   list.settransferhandler(new filelisttransferhandler(list));    add(new jscrollpane(list));  }  public static void createandshowgui() {   filedragdemo mainpanel = new filedragdemo();    jframe frame = new jframe("filedragdemo");   frame.setdefaultcloseoperation(jframe.exit_on_close);   frame.getcontentpane().add(mainpanel);   frame.pack();   frame.setlocationbyplatform(true);   frame.setvisible(true);   }  public static void callclass() throws exception {     pdfeasymanager pdfeasymanagerobject = new pdfeasymanager ();        try {            pdfeasymanagerobject.main(null);          } catch (ioexception e) {              //todo auto-generated catch block             e.printstacktrace();         } }  public static void main(string[] args) throws exception {     swingutilities.invokelater(new runnable() {      public void run() {         createandshowgui();       }    });  callclass(); }  }  @suppresswarnings("serial") class filelisttransferhandler extends transferhandler { public jlist list;   public static string stringfile;   public filelisttransferhandler(jlist list) {   this.list = list; }  public int getsourceactions(jcomponent c) {   return copy_or_move; }  public boolean canimport(transfersupport ts) {   return ts.isdataflavorsupported(dataflavor.javafilelistflavor); }  public boolean importdata(transfersupport ts){   try {      @suppresswarnings("rawtypes")       list data = (list) ts.gettransferable().gettransferdata(            dataflavor.javafilelistflavor);      if (data.size() < 1) {         return false;      }// close if       defaultlistmodel listmodel = new defaultlistmodel();       (object item : data) {            file file = (file) item;          //file1 = item;         listmodel.addelement(file);         system.out.println ("%%%%%%%%%%%file... " + file);         stringfile = file.tostring();         system.out.println ("%%%%%%%%%%%string... " + stringfile);                } // close      //string filestring = file.tostring();       list.setmodel(listmodel);      return true;     }// close try     catch (unsupportedflavorexception e) {      return false;   } catch (ioexception e) {      return false;   }   } } 

below code pdfeasymanager:

import java.io.file; import java.io.ioexception;   public class pdfeasymanager {  public static file file;    public static void main(string[] args) throws exception {       calleasy();     callsearch();      /* system.out.println ("stringfile is: " + stringfile);     file = new file (stringfile);*/      //easysearch easysearchobject = new easysearch();     //system.out.println(easysearchobject.totext()); //for reason needs there in order work..?      /*searchpdftext searchpdftextobject = new searchpdftext();                 try {                     searchpdftextobject.main(null);         } catch (exception e1) {             // todo auto-generated catch block             e1.printstacktrace();         }*/    } public static void calleasy()throws exception {     easysearch easysearchobject = new easysearch();     system.out.println(easysearchobject.totext()); //for reason needs there in order work..? }  public static void callsearch()throws exception {      searchpdftext searchpdftextobject = new searchpdftext();      try {          searchpdftextobject.main(null);      } catch (exception e1) {          // todo auto-generated catch block          e1.printstacktrace();      } } }     


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -