简体   繁体   English

getX()在java.awt.Rectangle中有私有访问权限吗?

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

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() 为什么以下代码生成错误消息: 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() . 根据doc, Rectangle确实有一个公共方法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;

}

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

    }

getX() is private in some specifications of java. getX()在某些java规范中是私有的。 For example, jsr-217 does not have getX() has public. 例如,jsr-217没有getX()具有public。 Check the specification of java that you are running. 检查您正在运行的java的规范。 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 http://docs.oracle.com/javame/config/cdc/ref-impl/pbp1.1.2/jsr217/index.html

pierr, getX() works with a more limited program: pierr,getX()适用于更有限的程序:


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. 但是我不明白为什么你的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM