Skip to main content

Arraylist cannot find symbol

1 reply [Last post]
fukawa
Offline
Joined: 2010-03-13

Good morning everyone

I have a little problem to execute a code sample demonstrating the use of a list in java 2D, I obtain this senseless -to me at least- error message :

P2 - Informatique\B211 Programmation orientée objet\atelier\test(to be<br />
deleted)>javac Whiteboard.java<br />
Whiteboard.java:18: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
    private List shapes;<br />
                 ^<br />
Whiteboard.java:71: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
    public void addShape(Forme myShape) {<br />
                         ^<br />
Whiteboard.java:22: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
        shapes = new ArrayList();<br />
                               ^<br />
Whiteboard.java:31: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
        for (Forme myShape : shapes) {<br />
             ^<br />
Whiteboard.java:38: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
        for (Forme myShape : shapes) {<br />
             ^<br />
Whiteboard.java:77: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
        Forme test =  new Forme(new Rectangle2D.Float(20, 20, 60, 50), true, Col<br />
or.RED);<br />
        ^<br />
Whiteboard.java:77: cannot find symbol<br />
symbol  : class Forme<br />
location: class java2d.Whiteboard<br />
        Forme test =  new Forme(new Rectangle2D.Float(20, 20, 60, 50), true, Col<br />
or.RED);<br />
                          ^<br />
7 errors

This is the first class :

package java2d;</p>
<p>import java.awt.AlphaComposite;<br />
import java.awt.BasicStroke;<br />
import java.awt.Graphics2D;<br />
import java.awt.Paint;<br />
import java.awt.Shape;<br />
import java.awt.Stroke;<br />
import java.awt.geom.AffineTransform;</p>
<p>public class Forme {</p>
<p>    private Shape shape;<br />
    private Paint backgroundPaint;<br />
    private Stroke stroke;<br />
    private Paint outlinePaint;<br />
    private boolean filled=false;<br />
    private boolean outlined;<br />
    private boolean visible=true;<br />
    private AffineTransform transform;<br />
    private float opacity=1.0f;<br />
    private int compositionRule= AlphaComposite.SRC_OVER;</p>
<p>    public Forme() {<br />
        stroke = new BasicStroke(2.0f);</p>
<p>    }</p>
<p>    public Forme(Shape shape, boolean filled, Paint backgroundPaint) {<br />
        this();<br />
        this.filled = filled;<br />
        this.shape = shape;<br />
        this.backgroundPaint = backgroundPaint;<br />
    }</p>
<p>    public void draw(Graphics2D g) {<br />
        if(visible) {<br />
            //On crée un contexte Graphique temporaire afin d'appliquer toutes les modifs qu'on veut sans avoir à les défaire par la suite<br />
            Graphics2D g2d = (Graphics2D) g.create();<br />
            //On définit la Stroke que les Graphics vont utiliser<br />
            g2d.setStroke(stroke);</p>
<p>            //On applique l'éventuelle transformation affine<br />
            if (transform != null) {<br />
                g2d.setTransform(transform);<br />
            }</p>
<p>            //On applique le composite si besoin est<br />
            if(opacity != 1.0f) {<br />
                g2d.setComposite(AlphaComposite.getInstance(compositionRule, opacity));<br />
            }<br />
            //Si la forme est remplie on dessine le fond.<br />
            if (filled) {<br />
                g2d.setPaint(backgroundPaint);<br />
                //Draw Background paint<br />
                g2d.fill(shape);<br />
                if(outlined) {<br />
                    g2d.setPaint(outlinePaint);<br />
                    g2d.draw(shape);<br />
                }<br />
            } else {<br />
                //On dessine la forme<br />
                g2d.setPaint(backgroundPaint);<br />
                g2d.draw(shape);<br />
            }<br />
            g2d.dispose();<br />
        }<br />
    }</p>
<p>    /**<br />
     * @return the shape<br />
     */<br />
    public Shape getShape() {<br />
        if (transform != null) {<br />
            return transform.createTransformedShape(shape);<br />
        }<br />
        return shape;<br />
    }</p>
<p>    /**<br />
     * @param shape the shape to set<br />
     */<br />
    public void setShape(Shape shape) {<br />
        this.shape = shape;<br />
    }</p>
<p>    /**<br />
     * @return the backgroundPaint<br />
     */<br />
    public Paint getBackgroundPaint() {<br />
        return backgroundPaint;<br />
    }</p>
<p>    /**<br />
     * @param backgroundPaint the backgroundPaint to set<br />
     */<br />
    public void setBackgroundPaint(Paint backgroundPaint) {<br />
        this.backgroundPaint = backgroundPaint;<br />
    }</p>
<p>    /**<br />
     * @return the stroke<br />
     */<br />
    public Stroke getStroke() {<br />
        return stroke;<br />
    }</p>
<p>    /**<br />
     * @param stroke the stroke to set<br />
     */<br />
    public void setStroke(Stroke stroke) {<br />
        this.stroke = stroke;<br />
    }</p>
<p>    /**<br />
     * @return the outlinePaint<br />
     */<br />
    public Paint getOutlinePaint() {<br />
        return outlinePaint;<br />
    }</p>
<p>    /**<br />
     * @param outlinePaint the outlinePaint to set<br />
     */<br />
    public void setOutlinePaint(Paint outlinePaint) {<br />
        this.outlinePaint = outlinePaint;<br />
    }</p>
<p>    /**<br />
     * @return the filled<br />
     */<br />
    public boolean isFilled() {<br />
        return filled;<br />
    }</p>
<p>    /**<br />
     * @param filled the filled to set<br />
     */<br />
    public void setFilled(boolean filled) {<br />
        this.filled = filled;<br />
    }</p>
<p>    /**<br />
     * @return the outlined<br />
     */<br />
    public boolean isOutlined() {<br />
        return outlined;<br />
    }</p>
<p>    /**<br />
     * @param outlined the outlined to set<br />
     */<br />
    public void setOutlined(boolean outlined) {<br />
        this.outlined = outlined;<br />
    }</p>
<p>    /**<br />
     * @return the visible<br />
     */<br />
    public boolean isVisible() {<br />
        return visible;<br />
    }</p>
<p>    /**<br />
     * @param visible the visible to set<br />
     */<br />
    public void setVisible(boolean visible) {<br />
        this.visible = visible;<br />
    }</p>
<p>    /**<br />
     * @return the transform<br />
     */<br />
    public AffineTransform getTransform() {</p>
<p>        return transform;<br />
    }</p>
<p>    /**<br />
     * @param transform the transform to set<br />
     */<br />
    public void setTransform(AffineTransform transform) {<br />
        this.transform = transform;<br />
    }</p>
<p>    /**<br />
     * @return the opacity<br />
     */<br />
    public float getOpacity() {<br />
        return opacity;<br />
    }</p>
<p>    /**<br />
     * @param opacity the opacity to set<br />
     */<br />
    public void setOpacity(float opacity) {<br />
        this.opacity = opacity;<br />
    }</p>
<p>    /**<br />
     * @return the compositionRule<br />
     */<br />
    public int getCompositionRule() {<br />
        return compositionRule;<br />
    }</p>
<p>    /**<br />
     * @param compositionRule the compositionRule to set<br />
     */<br />
    public void setCompositionRule(int compositionRule) {<br />
        this.compositionRule = compositionRule;<br />
    }</p>
<p>}

and this is the class containing the main

package java2d;</p>
<p>import java.awt.Color;<br />
import java.awt.Graphics;<br />
import java.awt.Graphics2D;<br />
import java.awt.RenderingHints;<br />
import java.awt.event.MouseEvent;<br />
import java.awt.event.MouseListener;<br />
import java.awt.geom.AffineTransform;<br />
import java.awt.geom.Rectangle2D;<br />
import java.util.ArrayList;<br />
import java.util.List;</p>
<p>import javax.swing.JComponent;<br />
import javax.swing.JFrame;</p>
<p>public class Whiteboard extends JComponent implements MouseListener {<br />
    private List shapes;</p>
<p>    public Whiteboard() {<br />
        this.addMouseListener(this);<br />
        shapes = new ArrayList();<br />
    }</p>
<p>    @Override<br />
    protected void paintComponent(Graphics g) {<br />
        super.paintComponent(g);</p>
<p>        Graphics2D g2d = (Graphics2D) g;<br />
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);<br />
        for (Forme myShape : shapes) {<br />
            myShape.draw(g2d);<br />
        }<br />
    }</p>
<p>    @Override<br />
    public void mouseClicked(MouseEvent arg0) {<br />
        for (Forme myShape : shapes) {<br />
            if (myShape.getShape().contains(arg0.getX(), arg0.getY())) {<br />
                myShape.setFilled(!myShape.isFilled());<br />
                repaint();<br />
            }<br />
        }</p>
<p>    }</p>
<p>    @Override<br />
    public void mouseEntered(MouseEvent arg0) {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    @Override<br />
    public void mouseExited(MouseEvent arg0) {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    @Override<br />
    public void mousePressed(MouseEvent arg0) {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    @Override<br />
    public void mouseReleased(MouseEvent arg0) {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void addShape(Forme myShape) {<br />
        shapes.add(myShape);<br />
    }</p>
<p>    public static void main(String[] args) {<br />
        Whiteboard c = new Whiteboard();<br />
        Forme test =  new Forme(new Rectangle2D.Float(20, 20, 60, 50), true, Color.RED);<br />
        test.setOutlined(true);<br />
        test.setOutlinePaint(Color.black);<br />
        test.setTransform(AffineTransform.getRotateInstance(21, 3.01));<br />
        c.addShape(test);<br />
        JFrame f = new JFrame();<br />
        f.add(c);<br />
        f.setSize(400, 300);<br />
        f.setLocationRelativeTo(null);<br />
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);<br />
        f.setVisible(true);<br />
    }</p>
<p>}

Can you help me please, thank you in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Olivier Lefevre

Most likely a classpath or surcepath issue, nothing to do with Java2D.

-- O.L.
--
To unsubscribe from the java2d-interest list, send email to:
java2d-interest-unsubscribe@java-mail-lists.kenai.com
Instructions will be mailed back to you.