   Java - fillPolygon   HELP!
  Hey Im trying to setup a method where I can pass in the values for the x and y points and have the polygon draw to the window.I am in cs1, and we are using Java to learn the basic features of OOP, and I am stuck.  Can anyone help with this?Here is my 'driver' class:public class Driver{    private JFrame theWindow;    private Shape t1, t2, t3;    public Driver()    {   theWindow = new JFrame("Output");   theWindow.setBounds(10,10,256,256);   theWindow.setLayout(null);   theWindow.setVisible(true);   /*t1=new Shape("box", 0,0,50,50);   theWindow.add(t1,0);   t2=new Shape("oval", 75,75,50,50);   theWindow.add(t2,0);*/   int[] x={10,25,50};   int[] y={10,25,50};   t3=new Shape(x, y, 3,0,0,128,128);   theWindow.add(t3,0);    }}I am overloading the 'Shape' class, but I wanted to do it just for my own experience.This is the Shape class:mport javax.swing.*;import java.awt.*;/** Shape Supplier Class  * Author: Brett Unzaga * Date: September, 2007 */public class Shape extends JComponent{    private String shape;    private int[] polyX;    private int[] polyY;    private int polyN;    public Shape(String s, int x, int y, int w, int h)    {   super();   setBounds(x, y, w, h);   setBackground(Color.black);   shape=s;    }    public Shape(int[] xPoints, int[] yPoints, int nPoints, int x, int y, int w, int h)    {   super();   shape="poly";   polyN=nPoints;   int[] polyX=xPoints;   int[] polyY=yPoints;   setBounds(x, y, w, h);   setBackground(Color.black);    }    public void paint(Graphics g)    {   g.setColor( getBackground() );   if(shape=="oval")   {  g.fillOval(0, 0, getWidth()-1, getHeight()-1);   }   if(shape=="box")   {  g.fillRect(0, 0, getWidth()-1, getHeight()-1);   }   if(shape=="poly")   {  g.fillPolygon(polyX, polyY, polyN);   }   paintChildren(g);   }}Basically I get all kinds of errors:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionat Shape.paint(Shape.java:46)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paint(JComponent.java:1031)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paint(JComponent.java:1031)at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)at javax.swing.RepaintManager.paint(RepaintManager.java:1128)at javax.swing.JComponent.paint(JComponent.java:1008)at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)at java.awt.Container.paint(Container.java:1797)at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionat Shape.paint(Shape.java:46)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paint(JComponent.java:1031)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paint(JComponent.java:1031)at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)at javax.swing.JComponent.paintChildren(JComponent.java:859)at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)at javax.swing.RepaintManager.paint(RepaintManager.java:1128)at javax.swing.JComponent.paint(JComponent.java:1008)at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)at java.awt.Container.paint(Container.java:1797)at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)I tried to take out the 'setBounds' for the polygon method and I don't get the errors, but then I don't get any output on my window at all.Please let me know where I am going wrong!BUnzaga   
  I tried to change my classes to this and I just get a blank 256x256 window, but no errors...Driver Classimport javax.swing.*;import java.awt.*;/** * Write a description of class Driver here. *  * @author (your name)  * @version (a version number or a date) */public class Driver{    private JFrame theWindow;    private Shape t1, t2, t3;    public Driver()    {   theWindow = new JFrame("Output");   theWindow.setBounds(10,10,256,256);   theWindow.setLayout(null);   theWindow.setVisible(true);   /*t1=new Shape("box", 0,0,50,50);   theWindow.add(t1,0);   t2=new Shape("oval", 75,75,50,50);   theWindow.add(t2,0);*/   int[] x={10,25,50};   int[] y={10,0,30};   t3=new Shape(x, y, 3);   theWindow.add(t3,0);    }}Shape classimport javax.swing.*;import java.awt.*;/** Shape Supplier Class  * Author: Brett Unzaga * Date: September, 2007 */public class Shape extends JComponent{    public String shape;    public int[] polyX;    public int[] polyY;    public int polyN;    public Shape(String s, int x, int y, int w, int h)    {   super();   setBounds(x, y, w, h);   setBackground(Color.black);   shape=s;    }    public Shape(int[] xPoints, int[] yPoints, int nPoints)    {   super();   shape="poly";   polyN=nPoints;   int[] polyX=xPoints;   int[] polyY=yPoints;//   setBounds(x, y, w, h);   setBackground(Color.black);    }    public void paint(Graphics g)    {   g.setColor( getBackground() );   if(shape=="oval")   {  g.fillOval(0, 0, getWidth()-1, getHeight()-1);   }   if(shape=="box")   {  g.fillRect(0, 0, getWidth()-1, getHeight()-1);   }   if(shape=="poly")   {  Polygon polygon = new Polygon(polyX, polyY, polyN);  g.fillPolygon(polygon);   }   paintChildren(g);   }}