swing画太极图案源码

package org.open.swing.taiji;

/**
 * @(#)Taichi.java
 *
 *
 * @author 
 * @version 1.00 2007/6/12
 */
import javax.swing.*;
import java.awt.*;

public class taiji extends JFrame {

    int width = 400;
    int height = 300;
    
    /**
     * @Fields serialVersionUID : TODO
     */
    private static final long serialVersionUID = 4561427255541891262L;
    /**
     * Creates a new instance of <code>Taichi</code>.
     */
    public taiji() {
        setSize(width, height);
        setTitle("太极图");
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int x = (screenSize.width  - width) / 2;
        int y = (screenSize.height - height) / 2;
        setLocation(x, y);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * @param args
     *            the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        taiji frame = new taiji();
        DrawPanel drawPanel = new DrawPanel();
        frame.setContentPane(drawPanel);
        frame.setVisible(true);
    }

}

class DrawPanel extends JPanel {
    /**
     * @Fields serialVersionUID : TODO
     */
    private static final long serialVersionUID = 5533924769973854832L;
    public DrawPanel() {
        setBackground(Color.GRAY);
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        g.fillArc(x, y, d, d, 0, 180);
        g.setColor(Color.WHITE);
        g.fillArc(x, y, d, d, 180, 180);
        g.setColor(Color.BLACK);
        g.fillArc(x + d / 2, y + d / 4, d / 2, d / 2, 180, 180);
        g.setColor(Color.WHITE);
        g.fillArc(x, y + d / 4, d / 2, d / 2, 0, 180);
        g.fillOval(x + d * 3 / 4 - 5, y + d / 2 - 5, 10, 10);
        g.setColor(Color.BLACK);
        g.fillOval(x + d / 4 - 5, y + d / 2 - 5, 10, 10);
    }

    int x = 100;
    int y = 40;
    int d = 200;
}

 

posted @ 2013-10-25 10:16  古来征战几人回  阅读(343)  评论(0编辑  收藏  举报