@Override
        public void paintComponent(Graphics g) {
            // magic used to stop flickering when redrawing for animation later.
            super.paintComponent(g);

            setBackground(Color.BLACK);

            // Strange but we need to cast so we can paint
            Graphics2D g2 = (Graphics2D) g;

            // make drawing antialias so smooth not pixelated edges
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                    RenderingHints.VALUE_RENDER_QUALITY);

            g2.setColor(Color.WHITE);

            // Draw stars
            Rectangle2D.Double[] r = new Rectangle2D.Double[100];
            for (int i = 0; i < r.length; i++) {
                r[i] = new Rectangle2D.Double(new Random().nextInt(width), new Random().nextInt(height), 5, 5);
                g2.draw(r[i]);
                g2.fill(r[i]);
            }

            // Draw title
            Font fontB = new Font(FONT_NAME, Font.BOLD, (int) (0.1 * height)); // scale 40/500
            Rectangle d = fontB.getStringBounds("Pong CC8", g2.getFontRenderContext()).getBounds();
            g2.setFont(fontB);
            g2.drawString("Pong CC8", width / 2 - d.width / 2, d.height);

            Font font = new Font(FONT_NAME, Font.BOLD, (int) (0.04 * height)); // scale 20/500
            g2.setFont(font);

            if (searchForGame) {
                showSearchGame(g2, d, font);
            } else if (waitForGame) {
                showWaitForGame(g2, d, font);
            } else if (!isPlay) {
                showMainMenu(g2, font);
            } else {
                showNetworkMenu(g2, d, font);
            }

            // release memory of graphics2d after finished drawing with it.
            g2.dispose();
        }