I wrote this program, when i run it, everything seems to work ok, but in the eclipse console i get a long list of errors, what is wrong with my program and how should i fix it?
thanks
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.List;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
// <applet code="AppletInterfaz" width="300" height="200"> </applet>
public class AppletInterfaz extends Applet implements ItemListener {
List colors;
public AppletInterfaz() {
colors = new List(4);
colors.add("Aqua");
colors.add("Black");
colors.add("Blue");
colors.add("Fuchsia");
colors.add("Gray");
colors.add("Green");
colors.add("Lime");
colors.add("Maroon");
colors.add("Navy");
colors.add("Olive");
colors.add("Purple");
colors.add("Red");
colors.add("Silver");
colors.add("Teal");
colors.add("White");
colors.add("Yellow");
add(colors);
colors.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
public void paint(Graphics g) {
int choice = colors.getSelectedIndex();
int red, green, blue;
int colorMix[][] = { { 0, 255, 255 }, { 0, 0, 0 }, { 0, 0, 255 },
{ 255, 0, 255 }, { 128, 128, 128 }, { 0, 128, 0 },
{ 0, 255, 0 }, { 128, 0, 0 }, { 0, 0, 128 }, { 128, 128, 0 },
{ 128, 0, 128 }, { 255, 0, 0 }, { 192, 192, 192 },
{ 0, 128, 128 }, { 255, 255, 255 }, { 255, 255, 0 } };
red = colorMix[choice][0];
green = colorMix[choice][1];
blue = colorMix[choice][2];
Color fondo = new Color(red, green, blue);
g.setColor(fondo);
g.drawRect(0, 0, 300, 200);
g.fillRect(0, 0, 300, 200);
}
}
this is the list of errors
Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: -1
at AppletInterfaz.paint(AppletInterfaz.java:48)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.X11.XRepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.X11.XComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)