Here is the program that i have written which creates a class called Brick and then creates an instance of this class called myBrick. My problem is that my code does almost everything it's supposed to do but one little problem that instead of displaying a brick (basically a rectangle) i see a line that responds to every single event like grow, shrink, etc... Could anyone help me figure out what am i doing wrong and i did use drawRect().
What this does is introduce variables local to the constructor--it does NOT initialize the member variables declared above it. These local variables disappear the moment the call to the constructor is popped off the stack. As it happens, an object's member variables are initialized to default values (in this case 0) when it is created; so what you end up with is an effectively dimensionless Brick located at (0,0) whenever you make a new Brick.
Hope that helps.
Originally posted by David Harkness:
Brick's constructor is the problem.You declare new local variables to hold the parameter values. When the constructor exits, the local variables disappear. Removing the four "int"s should fix the problem. You might want to use "this.x = ..." to be very clear that you're setting the instance variables.
thanx, David. It did fix the problem. I am beginner trying hard to learn java and since i didn't get any compilation error i didn't look at that spot carefully. I appreciate you taking time to help me out.