Hot to set class variable to be visible to its public static methods?
- by RCola
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);?