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; }
【签名→→→】【****知其然知其所以然****】
工具只能帮助我们解决我们认识到的问题,解决不了我们都没理解的问题。
不能再把一切扔给框架、容器、工具!
首先理解你的业务逻辑,理解你要实现的功能,
然后搞清楚框架、容器、工具会帮助我们做什么。
只有理解了自己的业务逻辑,理解了自己的代码,理解了自己要用到的第三方代码,
才能真正完美地实现我们需要的功能!