Hot to set class variable to be visible to its public static methods?

Posted by RCola on Stack Overflow See other posts from Stack Overflow or by RCola
Published on 2011-11-24T17:42:15Z Indexed on 2011/11/24 17:51 UTC
Read the original article Hit count: 137

Filed under:

Why I can noy access my variable p in mull form iterate method? How to resolve a problem? Hot to set class variable to be visible to its public static methods?

public class mull {
    public static void main(String[] args) throws InterruptedException  {
    final JPanel p = createAndShowGUI();

        Timer timer = new Timer(1000, new MyTimerActionListener());

    timer.start();
    try {
      Thread.sleep(10000);
    } catch (InterruptedException e) {
    }
    timer.stop();
public static void iterate(){

    for (int i  = 0; i < 55; i++){
         // "p cannot be resolved"
    p.moveSquare(i*10, i*10);
        p.setParamsRing(i*5, i*7, 200, 200);
//            p.repaint();
        }
    }
}

class MyPanel extends JPanel {
....

}

How to access variable set in another method (in this example main())?


Why Eclipse forces me to use this ((MyPanel) p).setParamsRing(i*5, i*7, 200, 200); instead of this p.setParamsRing(i*5, i*7, 200, 200);?

© Stack Overflow or respective owner

Related posts about java