Why I can not access my variable p in mull class’s iterate method?
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);
}
}
}
class MyPanel extends JPanel {
....
}
Why does Eclipse force me to use this:
((MyPanel) p).setParamsRing(i*5, i*7, 200, 200);
instead of:
p.setParamsRing(i*5, i*7, 200, 200);
?
so what you need is:
Edit: And to your last question: it’s because p is of type JPanel which doesn’t have any method setParamsRing(). You probably added that method in class MyPanel.