16 June 2011

Java Distribution, SwingWorker

Java Distribution
OK one more time: Java Distro made easy:

if using Netbeans: (bad GUI IDE...)

Right click on the dist folder, send it to a compressed folder
this will put the lib directory in place with all your extra jars.

do NOT futz with classpath... it wont do any good Java is notorious for not finding jars,
and deceiving about CLASSPATH

put a batch file called fred.bat
java -jar fred.jar
in the dist directory before you zip it.

In my old age I am finally writing static libraries of common functions.
But I am not permitted to do static imports,which nicely hide the class names...
_____________________________________________________
SwingWorker
Java Swing is NOT threadsafe - beware the black screen, which only task manager can kill

You need a silly thing called SwingWorker if your gonna wait for a card etc...


void SAM() //Button action HOT Switching SAMs
{
    UID = "";
    tSAM.setText("Insert SAM ");
    if (cardTerms == null)
    initTerms(); // make a list of all teminals: java does this nicely   

//_________________________________________________________


    SwingWorker waitForSAM = new SwingWorker()
    {
        public String doInBackground()
    {
    do
    {
       
 tryAllTermsCL(true); // <<<< find a SAM on a NonNFC reader
                                              

// do as much SAM/Card dependent stuff as you can, here, inside the SwingWorker..                                                                


        if (this.isCancelled()) // ideally have a Cancel button
             exit return("can"); 
    
     } 
     while ( UID.length() < 2); 

         publish(UID); //publish an update, this will get added to a list and processed in bulk by the process() method at some point 
     try 
     { 
         Thread.sleep(150); // let a cancel in?? 
     }
     catch (InterruptedException e) 
     {    
         System.out.println("Irrrrr"); 
         return("rupt"); 
     } 
     return("blank"); 
     } 
     @Override protected void process(List    chunks) 
     {
         //System.out.println("\n process " + chunks);

     }

        @Override
        protected void done()
        {
            tSAM.setText(UID);
        } // done
    }; //waitForCard definition fin

//_________________________________________________________
    waitForSAM.execute();

// card wait stuff done here may cause black-screen.....

    tArea.setCaretPosition(tArea.getDocument().getLength());


No comments:

Post a Comment