title: Access static variable from another class
body: <p>I have two classes in same package. i have declared a <code>static variable</code> in one class and want to access that variable in another class. </p>
  
  <p>Here is my code in which i have declared the static variable</p>
  
  <pre><code>public class wampusGUI extends javax.swing.JFrame {
  
      static String userCommand;
  
      public wampusGUI() {
          initComponents();
      }
  
      public void setTextArea(String text) {
          displayTextArea.append(text);
      }
  
      private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {
          userCommand = commandText.getText();
      }
  
      public static void main(String args[]) {
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
  
              public void run() {
                  wampusGUI w = new wampusGUI();
                  w.setVisible(true);
                  Game g = new Game(w);
                  g.play();
              }
          });
      }
  }
  </code></pre>
  
  <p>Here is the code in which i want to access variable</p>
  
  <pre><code>public class Game {
  
      private wampusGUI gui;
  
      public Game(wampusGUI w) {
          world = new World();
          world.start();
          gui = w;
      }
  
      public void play() {
          gui.setTextArea(welcome());
          gui.setTextArea(describe());
          for (;;) {
              String s = userCommand; // here value should come should 
              System.out.println(userCommand);
              Command c = Command.create(s);
              String r = c.perform(world);
              // is game over?
              if (r == null) {
                  break;
              }
              System.out.println(r);
          }
          System.out.println("Game over");
      }
  }
  </code></pre>
  
  <p>However, i can pass the variable from first class as a argument. but the problem is that, when i will run program the value is going null first time, which i dont want. i want when i enter value in <code>textfield</code>  then it should go to another class.</p>
  
  <p>Thank you.</p>