• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1901
  • Last Modified:

Warning message - uses unchecked or unsafe operations, please assist

I am in the final stages of completing a college assignment. It works as it should, but when compiled it throws an error warning - about unchecked or unsafe operations. I would like a clean build but do not know what I'm doing wrong. Could you please have a look at my code and advise. Any additional information on how to prevent similar issues in future would also be appreciated. Thanks.
/*
 * Spotting.java
 *
 * Created on 13 July 2007, 14:07
 *
 */
 
package tma03q4;
 
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
 
/**
 *
 * @author M257
 */
public class Spotting extends JFrame
{
   // Insert declarations here
   JRadioButtonMenuItem small;
   JRadioButtonMenuItem medium;
   JRadioButtonMenuItem large;
   
   JRadioButtonMenuItem red;
   JRadioButtonMenuItem green;
   JRadioButtonMenuItem blue;
   
   private JMenuItem undoItem;
   
   private int xVal,yVal,numberOfClicks=0;
   
   // OU code starts below. Above code is mine
   private ArrayList<Spot> spots;
   
   private static int SMALL = 10;
   private static int MEDIUM = 20;
   private static int LARGE = 40;
   
   private int currentSize = SMALL;
   
   private Color currentColor = Color.RED;
   
   private JPanel canvas;
   
   public Spotting()
   {
      setSize(300, 300);
      setTitle("Spotting");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      canvas = new JPanel();
      canvas.setBackground(Color.WHITE);
      canvas.addMouseListener(new MouseWatcher());
      
      // Insert code here to construct the GUI
      //01.02.2008 @ 19:43 Starting work on the assignment:
      
      //Start with setting up the menu bar and menu items
      JMenuBar spottingMenuBar = new JMenuBar();
      
      //Trying to implement the menu items using radio buttons
      
      ButtonGroup sizeGroup = new ButtonGroup();
      ButtonGroup colourGroup = new ButtonGroup();
      
      JMenu spottingSizeMenu = new JMenu("Size");
      JMenu spottingColourMenu = new JMenu("Colour");
      JMenu spottingEditMenu = new JMenu("Edit");
      
      small = new JRadioButtonMenuItem("Small",true);
      medium = new JRadioButtonMenuItem("Medium",false);
      large = new JRadioButtonMenuItem("Large",false);
      
      small.addActionListener (new MenuSelection());
      medium.addActionListener(new MenuSelection());
      large.addActionListener(new MenuSelection());
      
      sizeGroup.add(small);
      sizeGroup.add(medium);
      sizeGroup.add(large);
      
      red = new JRadioButtonMenuItem("Red",true);
      green = new JRadioButtonMenuItem("Green",false);
      blue = new JRadioButtonMenuItem("Blue",false);
      
      red.addActionListener(new MenuSelection());
      green.addActionListener(new MenuSelection());
      blue.addActionListener(new MenuSelection());
      
      spottingSizeMenu.add(small);
      spottingSizeMenu.add(medium);
      spottingSizeMenu.add(large);
      
      spottingColourMenu.add(red);
      spottingColourMenu.add(green);
      spottingColourMenu.add(blue);
      
      undoItem = new JMenuItem("Undo");
      undoItem.addActionListener(new MenuSelection());
      undoItem.setAccelerator(KeyStroke.getKeyStroke("control Z"));
      spottingEditMenu.add(undoItem);
      
      spottingMenuBar.add(spottingSizeMenu);
      spottingMenuBar.add(spottingColourMenu);
      spottingMenuBar.add(spottingEditMenu);
      
      
      colourGroup.add(red);
      colourGroup.add(green);
      colourGroup.add(blue);
     
      setJMenuBar(spottingMenuBar);
     
      spots = new ArrayList();
      
      getContentPane().add("Center", canvas);
   }
   
   public void paint(Graphics g)
   {
      super.paint(g);
      Graphics gr = canvas.getGraphics();
      
     // Insert drawing code here
      //02.02.2008, dabbling with drawing the spot
      for (int i=0;i<numberOfClicks;i++)
      {
         gr.setColor(spots.get(i).getColour());
         gr.fillOval((spots.get(i).getX()-(spots.get(i).getRadius()/2)),
               (spots.get(i).getY()-(spots.get(i).getRadius()/2)),
               spots.get(i).getRadius(),
               spots.get(i).getRadius());
      }
   }
  // Insert code here to define the listener classes
     public class MenuSelection implements ActionListener
   {
      public void actionPerformed (ActionEvent e)
      {
         if (e.getSource()==small)
         {
            currentSize = SMALL;
         }
         
         if (e.getSource()==medium)
         {
            currentSize = MEDIUM;
         }
         
         if (e.getSource()==large)
         {
            currentSize = LARGE;
         }
         if (e.getSource()==red)
         {
            currentColor = Color.RED;
         }
         
         if (e.getSource()==green)
         {
            currentColor = Color.GREEN;
         }
         
         if (e.getSource()==blue)
         {
            currentColor = Color.BLUE;
         }
         if (e.getSource()==undoItem)
         {
            if (numberOfClicks>0)
            {
               spots.remove(numberOfClicks-1);
               numberOfClicks--;
            }
         }
        
         repaint();
      }
   }
 
      
   private class MouseWatcher extends MouseAdapter
   {
      public void mouseClicked (MouseEvent m)
      {
         xVal = m.getX();
         yVal = m.getY();
         spots.add(new Spot(currentColor, xVal, yVal, currentSize));
         numberOfClicks++;
         repaint();
      }
   }
   
  /* public void setColor(Color c)
   {
      currentColor = c;
   }
    */
}

Open in new window

0
appretice
Asked:
appretice
1 Solution
 
gatorvipCommented:
>> spots = new ArrayList();

that should probably be java.util.ArrayList<Spot>
0
 
appreticeAuthor Commented:
Thanks!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now