| 
 
TA的每日心情|  | 开心 2021-3-12 23:18
 | 
|---|
 签到天数: 2 天 [LV.1]初来乍到 | 
 
| 
 复制代码/*
 * 双缓存显示图片
 */
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class HeartDemo extends MIDlet implements CommandListener {
        private Command exitCommand;
        private HeartCanvas sg;
        public HeartDemo() {
                exitCommand = new Command("Exit", Command.EXIT, 1);
                sg = new HeartCanvas();
                sg.addCommand(exitCommand);
                sg.setCommandListener(this);
                Display.getDisplay(this).setCurrent(sg);
                
        }
        protected void startApp(){
        }
        protected void pauseApp() {
        }
        protected void destroyApp(boolean arg0){                
        }
        public void commandAction(Command c, Displayable d) {
                if (c == exitCommand) {                        
                        destroyApp(false);                        
                        notifyDestroyed();
                }
        }        
}
class HeartCanvas extends Canvas{
        
        Image offScreen;//缓冲区对象
        Graphics drawOffScreen;
        int width,height;
        protected HeartCanvas(){
                try {
                        
                        //指定缓冲区域为屏幕大小
                        width = this.getWidth();
                        height = this.getHeight();
                        offScreen =Image.createImage(width,height);
                        drawOffScreen = offScreen.getGraphics();// 获得一个新的Graphics对象
                        drawOffScreen.setColor(0x00f7f7f7);
                        drawOffScreen.fillRect(0,0,width,height);
                        drawOffScreen.setColor(0x00ee0000);
                        int i,j;
                        double x,y,r;
                        
                        for(i=0;i<=90;i++)
                                for(j = 0;j <=90;j++){
                                        
                                        //转换为直角坐标
                                        r = Math.PI/45*i*(1-Math.sin(Math.PI/45*j))*18;
                                        x = r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45*i) + width/2;
                                        y = - r *Math.sin(Math.PI/45*j)+height/4;
                                        
                                        drawOffScreen.fillArc((int)x,(int)y-20,1,1,0,360);
                                        
                                }
                        
                } catch (Exception e) {                        
                        e.printStackTrace();
                }                                        
                
        }
        protected void paint(Graphics g) {                
                //显示缓存区的可变Image对象
                //g.drawImage(offScreen,0,0,Graphics.TOP|Graphics.LEFT);
                
                //drawOffScreen.setColor(0,0,0);
                //int i,j;
                //double x,y,r;
                
                //for(i=0;i<=90;i++)
                //        for(j = 0;j <=90;j++){
                                
                                //转换为直角坐标
                                //r = Math.PI/45*i*(1-Math.sin(Math.PI)/45*j)*18;
                                //x = r*Math.cos(Math.PI/45*j)*Math.sin(Math.PI/45+i) + width/2;
                                //y = - r *Math.sin(Math.PI/45*j)+height/4;
                                
                                //drawOffScreen.fillArc((int)x,(int)y,2,2,0,360);
                        //        drawOffScreen.fillArc(0,0,2,2,0,360);
                //        }
                g.drawImage(offScreen,0,0,Graphics.TOP|Graphics.LEFT);
                
                
        }
        
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 源码下载:http://203.93.208.26/kj/cwb/dir7/HeartDemo.zip
 | 
 |