variable hat einen privaten Zugang

Ich versuche zu machen, eine abstrakte Form, die Klasse für Rechteck und ellipse die einzige abstrakte Methode, die ich gab Form wurde die draw-Methode, aber nachdem ich gab es einen Konstruktor und alles, was es gibt mir eine Fehlermeldung in die Rechteck-Klasse zu sagen, dass die Farbe und die anderen Variablen haben private Zugänge hier ist mein code:

public abstract class Shape{
        private int x, y, width, height;
        private Color color;
        public Shape(int x, int y, int width, int height, Color color){
            setXY(x, y);
            setSize(width, height);
            setColor(color);
        }

        public boolean setXY(int x, int y){
            this.x=x;
            this.y=y;
            return true;
        }

        public boolean setSize(int width, int height){
            this.width=width;
            this.height=height;
            return true;
        }

        public boolean setColor(Color color){
            if(color==null)
                return false;
            this.color=color;
            return true;
        }

        public abstract void draw(Graphics g);
    }

    class Rectangle extends Shape{
        public Rectangle(int x, int y, int width, int height, Color color){
            super(x, y, width, height, color);
        }

        public void draw(Graphics g){
            setColor(color);
            fillRect(x, y, width, height);
            setColor(Color.BLACK);
            drawRect(x, y, width, height);
        }
    }

    class Ellipse extends Shape{
        public Ellipse(int x, int y, int width, int height, Color color){
            super(x, y, width, height, color);
        }

        public void draw(Graphics g){
            g.setColor(color);
            g.fillOval(x, y, width, height);
            g.setColor(Color.BLACK);
            g.drawOval(x, y, width, height);
        }
    }

InformationsquelleAutor user3602628 | 2014-05-05

Schreibe einen Kommentar