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

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

In accordance with the document Rectanglehave an open 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
source share
3 answers

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

    }
+1
source

getX () is private in some java specifications. For example, jsr-217 does not have a getX () function. Check out the java spec you are using. If it is confidential, you can directly access the data item.

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

+1
source

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 do not understand why you are mistaken.

0
source

Source: https://habr.com/ru/post/1794614/


All Articles