Novice question. Given the class MyExample below:
public class MyExample extends GCompound {
//instance variables
public GRect R1 = new GRect(0, 0, 20, 20);
public GRect R2 = new GRect(0, 0, 5, 5); //R2 is in front of R1, but its coordinates are all "inside" of R1's coordinates
//constructor
public MyExample() {
add(R1);
add(R2);
}
}
1) Suppose I'm in a GraphicsProgram and declare:
MyExample myex = new MyExample();
Suppose I have coordinates (x1, y1), and want to find out whether this is the myex object defined in the previous line. I would use:
obj = getElementAt(x, y);
if (obj == myex) (...and so on)
Now suppose I want to test whether the object is the GRect object R1 within myex. Why doesn't the following work?
if(obj ==myex.R1) (...and so on);
Here is the full code that shows my question; it outputs "myex", none of the other outputs come out...
public void run() {
GObject obj1, obj2;
MyExample myex = new MyExample();
add(myex);
obj1 = getElementAt(1, 1);
obj2 = getElementAt(19, 19);
if (obj1 == myex) System.out.println("myex");
if(obj1 == myex.R1) System.out.println("R1");
if(obj1 == myex.R2) System.out.println("R2");
if(obj2 == myex.R1) System.out.println("R11");
if(obj2 == myex.R2) System.out.println("R22");
}