getX() has private access in java.awt.Rectangle?

1.8k views Asked by At

Why following code generate error message : getX() has private access in java.awt.Rectangle (int)dest.getX(), (int)dest.getY(), (int)dest.getWidth(), (int)dest.getHeight()

According to the doc , Rectangle do have a public method getX().

   public boolean setSize(java.awt.Rectangle source, java.awt.Rectangle dest)
{

    setVideoSize((int)source.getX() ,(int)source.getY(), (int)source.getWidth(), (int)source.getHeight(),
              (int)dest.getX(), (int)dest.getY(), (int)dest.getWidth(), (int)dest.getHeight()
     );


     return true;

}
3

There are 3 answers

1
Bala R On BEST ANSWER

I just tried the following and it compiles fine.

public boolean setSize(java.awt.Rectangle source, java.awt.Rectangle dest) {

        setVideoSize((int) source.getX(), (int) source.getY(),
                (int) source.getWidth(), (int) source.getHeight(),
                (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth(),
                (int) dest.getHeight());

        return true;

    }

    private void setVideoSize(int x, int y, int width, int height, int x2,
            int y2, int width2, int height2) {
        // TODO Auto-generated method stub

    }
0
jcomeau_ictx On

pierr, getX() works with a more limited program:


jcomeau@intrepid:/tmp$ cat test.java; java test
import java.awt.*;
public class test {
 public static void main(String args[]) {
  Rectangle rect = new Rectangle(0, 0, 1, 1);
  System.out.println("x: " + rect.getX());
 }
}
x: 0.0

I cannot see why yours is erroring, though.

0
goknicks On

getX() is private in some specifications of java. For example, jsr-217 does not have getX() has public. Check the specification of java that you are running. If it is private, you might have access the data member directly.

http://docs.oracle.com/javame/config/cdc/ref-impl/pbp1.1.2/jsr217/index.html