以文本方式查看主题

-  课外天地 李树青  (http://njcie.com/bbs/index.asp)
--  JavaME移动开发课件  (http://njcie.com/bbs/list.asp?boardid=18)
----  程序代码——绘制太极图  (http://njcie.com/bbs/dispbbs.asp?boardid=18&id=553)

--  作者:admin
--  发布时间:2008/10/8 22:48:34
--  程序代码——绘制太极图

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet {
        private Display display;

        public Exec() {
                display = Display.getDisplay(this);
        }

        public void startApp() {

                display.setCurrent(new DrawPanel());
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }
}

class DrawPanel extends Canvas {
        public void paint(Graphics g) {
                int width = getWidth() * 2 / 3;
                int left = getWidth() * 1 / 6;
                int height = getHeight() * 2 / 3;
                int top = getHeight() * 1 / 6;

                g.setColor(0, 0, 0);
                g.fillArc(left, top, width, height, 90, 180);

                g.setColor(255, 255, 0);
                g.fillArc(left, top, width, height, 270, 180);

                g.setColor(0, 0, 0);
                g.fillArc(left * 2, top * 3, width / 2, height / 2, 270, 180);

                g.setColor(255, 255, 0);
                g.fillArc(left * 2, top, width / 2, height / 2, 0, 360);

                g.setColor(255, 255, 0);
                g.fillArc(left * 2 + left * 3 / 4, top * 3 + top * 3 / 4, width / 8,
                                height / 8, 0, 360);

                g.setColor(255, 0, 0);
                g.fillArc(left * 2 + left * 3 / 4, top + top * 3 / 4, width / 8,
                                height / 8, 0, 360);
        }
}

[此贴子已经被作者于2010-12-12 18:33:50编辑过]