paintComponent is not reading my private variables
Just to simplify, I'll leave out the details to my code:
Code :
public class Theclass{
private short a,b;
public Theclass(short a,short b){
}
public void paintComponent(Graphics g){
super.paintComponent(g)
System.out.println("a: "+a+" and b: "+b);//outputs: "a: 0 and b: 0"
}
public static void main(String[]args){
a=10;
b=5;
Theclass tc=new TheClass(a,b);
}
}
So why isn't my paintComponent reading these 2 variables? It draws other things. I'm guessing it's being called before main is called. How do i get it to run when i want it to, aka after the required variables and methods have been run so it knows what to do?
Re: paintComponent is not reading my private variables
You left out so many details that your code is uncompilable.
What's the point of a constructor that takes two arguments and doesn't do anything with them? Recommended reading: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
db
Re: paintComponent is not reading my private variables
sorry i didn't think the code would be enough, but I figured it out.