编译下面代码时出现了这样的错误
注意:PainterJPanel.java使用了未经检查或不安全的操作。
不知道是哪里出错了,大家帮忙呀!
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;public class PainterJPanel extends JPanel
{
   private int circleDiameter; // diameter of circle
   private Color circleColor;  // color of circle   private Circle newCircle; // Circle to add to the ArrayList   // ArrayList to hold drawn circles
   private ArrayList circleArrayList = new ArrayList();
   
   // constructor
   public PainterJPanel( Color colorValue, int diameter )
   {
      circleColor = colorValue;
      circleDiameter = diameter;
      
      // set up mouse motion listener
      addMouseMotionListener(
      
         new MouseMotionListener() // anonymous inner class
         {
            // event handler called when mouse is dragged
            public void mouseDragged( MouseEvent event )
            {
               painterJPanelMouseDragged( event );
            }            // event handler must exist to implement interface
            public void mouseMoved( MouseEvent event )
            {
            }
            
         } // end anonymous inner class
         
      ); // end call to addMouseMotionListener
      
   } // end constructor
   
   // sets the circleColor
   public void setColor( Color choice )
   {
      circleColor = choice;   } // end method setColor   // gets the circleColor
   public Color getColor()
   {
      return circleColor;   } // end method getColor
   
   // sets the circleDiameter
   public void setDiameter( int diameter )
   {
      circleDiameter = diameter;   } // end method setDiameter
   
   // paint a circle on this PainterJPanel
   public void paintComponent( Graphics g )
   {
      super.paintComponent( g );      Iterator circleIterator = circleArrayList.iterator();
      Circle drawCircle;      // iterate through the ArrayList
      while( circleIterator.hasNext() )
      {
         drawCircle = ( Circle )circleIterator.next();
         drawCircle.draw( g ); // draw each circle
      }   } // end method paintComponent   // create a circle and add it to the ArrayList
   private void painterJPanelMouseDragged( MouseEvent event )
   {
      if ( event.isMetaDown() )
      {
         // erase circle if right mouse button is pressed
         newCircle = new Circle( circleDiameter, event.getPoint(),
            this.getBackground() );
      }
      else
      {
         // draw circle if left mouse button is pressed
         newCircle = new Circle( circleDiameter, event.getPoint(),
            circleColor );
      }
  
  
circleArrayList.add( newCircle );
              repaint(); // repaint this PainterJPanel   } // end method painterJPanelMouseDragged
   
} // end class PainterJPanel

解决方案 »

  1.   

    circleArrayList.add(newCircle);你使用了JDK5.0及以上,在对集合操作时,系统提示您最好检查newCircle是否是您期望的数据类型。修改  // ArrayList to hold drawn circles
      private ArrayList circleArrayList = new ArrayList();为
      // ArrayList to hold drawn circles
      private ArrayList<Circle> circleArrayList = new ArrayList<Circle>();就可以了
      

  2.   

    哦,原来如此,我也感觉是集合方面的问题就是不知道怎么改,我用的是jdk1.6的版本,谢谢楼上的了!
      

  3.   

    瑶蝶论坛近期将举行“瑶蝶建站暨第一届LOGO大赛”,比赛流程都以用公告写出,大家可以积极参加哦