java - I can't call the repaint() method in my main method -
everytime try call repaint() method says non static method cannot reference static method. btw, it's in same class paintcomponent method. tried create object out of class first, reference object name didn't work. please help.
public class p extends jpanel { p g = new p(); boolean change = true; static int x = 0; static int y = 0; static color circlec = new color(0, 0, 0); static string position = ""; p p = new p(); public void paintcomponent(graphics g) { g.setcolor(circlec); g.filloval(x, y, 50, 50); g.setcolor(color.white); g.drawstring(position, x, y + 25); } public static void main(string[] args) throws interruptedexception { p.repaint(); } }
the main method static. p object not: instance field of p class. try this:
public static void main(string[] args) throw interruptedexception { eventqueue.invokelater( new runnable() { public void run() { p p = new p(); p.repaint(); } } ); }
you should access swing components event dispatch thread, why put in eventqueue invokelater.
Comments
Post a Comment