Using command line arguments in EDT

From: Philipp (nospam_kitschen_at_hotmail.com)
Date: 11/26/04


Date: Fri, 26 Nov 2004 11:52:32 +0100

Hello,
As suggested in FAQ 4.3 I try to build and start my Swing GUI with
invokeLater(). How can I access variables of my main method (eg. command
line arguments)?
With following code I get an error:
Cannot refer to a non-final variable "argument" inside an inner class
defined in a different method.

import javax.swing.*;
public class TestClass {
   public static void main(String[] args) {
     String argument = null;
     if (args.length > 0) {
       argument = args[0];
     }
     SwingUtilities.invokeLater(new Runnable(){
       public void run() {
         JFrame myFrame = new JFrame();
         myFrame.getContentPane().add(new JLabel(argument));
         myFrame.pack();
         myFrame.setVisible(true);
       }
     });
   }
}

Sorry if it's a newbie question. Thanks for answers.
Phil