编译下面代码时出现了这样的错误
注意: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
注意: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
private ArrayList circleArrayList = new ArrayList();为
// ArrayList to hold drawn circles
private ArrayList<Circle> circleArrayList = new ArrayList<Circle>();就可以了