Polygon shape does not show up in Java

I'm trying to make some shapes with Java, I created two rectangles and they show up normally, but lately I integrated a polygon shape code but it not showing up while running the program. Somebody help in this please!

Here is a screenshot after running:

Here is the code I use:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class shapes extends JPanel{
int midX = 120;
int midY = 60;
int radius[] = {118,40,90,40};
int nPoints = 16;
int[] X = new int[nPoints];
int[] Y = new int[nPoints];
int i;
double max;

public void paintComponent(Graphics gphcs){



gphcs.setColor(new Color(190,81,215));
gphcs.drawString("This is my text", 25, 120);

for (double current=0.0; i<nPoints; i++)
    double x = Math.cos(current*((2*Math.PI)/max))*radius[i % 4];
    double y = Math.sin(current*((2*Math.PI)/max))*radius[i % 4];

    X[i] = (int) x+midX;
    Y[i] = (int) y+midY;
gphcs.fillPolygon(X, Y, nPoints);

Acutally I wanted the polygon to show up as a star shape but it even didn't appear at all!

Thank you..


All your polygon co-ordinates are the same. Try

for (int i=0; i < nPoints; i++) {
   double x = Math.cos(i * ((2 * Math.PI) / nPoints)) * radius[i % 4];
   double y = Math.sin(i * ((2 * Math.PI) / nPoints)) * radius[i % 4];

   X[i] = (int) x + midX;
   Y[i] = (int) y + midY;

Need Your Help

ASP.NET MVC - Is a ViewModel an appropriate place to do minor calculations?

asp.net-mvc viewmodel

I'm working on a UserViewModel, and I'm wondering if it's appropriate to do minor calculations in the VM, or if I need to separate it further and calculate elsewhere.

DropDownList with the non-unique values is screwing up viewstate/postbacks

c# asp.net

Okay, so I have a DropDownList control that contains 50 ListItems, one for each of the 50 states. The text value reflects each state name which makes each text value unique. However, the value prop...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.