![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import java.awt.*; import java.util.Scanner; import javax.swing.*; public class Test extends JFrame{ public Test(){ add(new PolygonPanel()); } public static void main(String[] args){ Test frame = new Test(); frame.setSize(400, 400); frame.setTitle("Exercise15_8"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); // Center the frame frame.setVisible(true); } } class PolygonPanel extends JPanel{ protected void paintComponent(Graphics g){ super.paintComponent(g); int xCenter = getWidth()/2; int yCenter = getHeight()/2; int radius =(int)(Math.min(getWidth(), getHeight())*0.4); Polygon polygon = new Polygon(); polygon.addPoint(xCenter, yCenter); g.drawPolygon(x, y, 4); } }