I am attempting to create a simple applet that can draw a rectangle, I have the following code:

```
import java.util.Scanner;
import java.awt.Graphics;
import javax.swing.JApplet;
public class DrawShapes extends JApplet{

    public void paint(Graphics canvas) {
        Scanner reader  = new Scanner(System.in); 
        System.out.println("How many sides do you want your shape to have: ");
        int sides = reader.nextInt();
        reader.close();
        super.paint(canvas);

        if(sides ==4){
        canvas.drawRect(100, 50, 200, 200);
        }

        System.out.println("Done!");

    }

}

```

I the run this code and when prompted to enter how many sides i want i enter "4"

A new applet window is then created in the upper left corner without any errors. 
But, the second I attempt to expand the applet the following errors are printed to the console: 

```
Exception in thread "AWT-EventQueue-1" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:862)
    at java.util.Scanner.next(Scanner.java:1485)
    at java.util.Scanner.nextInt(Scanner.java:2117)
    at java.util.Scanner.nextInt(Scanner.java:2076)
    at DrawShapes.paint(DrawShapes.java:9)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:842)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
    at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

```

Also, "Applet Started" is repeated in the applet window as such:
"Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started
Applet Started"
What is going on with my code?