编译下面代码时出现了这样的错误
注意: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
解决方案 »
- 如何覆盖list里面的信息
- 用hql怎么写
- 急!!!如何清楚session???在线。。。
- 关于进制的问题
- 各位前辈,请问一下:(关于hashmap的用法)
- 求助!哪位有javaexcelapi的那个jar文件,给我一份!谢谢了。他的官方网站以经上不去了。
- 快,各位哥哥帮帮小妹阿,大家知道C.Thomas.Wu的《面向对象程序设计导论〉吗?这本书提供了一个Javabook包,那是一个带有很多类的集合,
- 巨烂的JAVA及LINUX,谁有好办法,我给300分。
- 怎么考SUN的java程序员和系统分析员证书?
- Enumeration 里可以存 int 吗?
- JButton中文字竖直显示的问题。
- 50求教一个关于JTable的难题, 高手帮忙, 谢谢
private ArrayList circleArrayList = new ArrayList();为
// ArrayList to hold drawn circles
private ArrayList<Circle> circleArrayList = new ArrayList<Circle>();就可以了