码迷,mamicode.com
首页 > 其他好文 > 详细

15.8

时间:2016-06-28 23:49:14      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

技术分享
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);
    }   
}
View Code

 

15.8

标签:

原文地址:http://www.cnblogs.com/wanjiang/p/5625235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!