Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 350|回复: 0

[J2ME学习]J2ME变幻线

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-10-11 07:09:36 | 显示全部楼层 |阅读模式
    1. 一、MistifyMIDlet.java
    2. import javax.microedition.lcdui.Display;
    3. import javax.microedition.midlet.MIDlet;
    4. import javax.microedition.midlet.MIDletStateChangeException;
    5. /**
    6. * 太好看了。这是显示有点象windows屏幕保护一样的东西。
    7. * @author fb
    8. *
    9. */
    10. public class MistifyMIDlet extends MIDlet {
    11. private Display display;
    12.    
    13.     public MistifyMIDlet() {
    14.         display=Display.getDisplay(this);
    15.     }
    16.    
    17.     public void startApp() {
    18.         MistifyCanvas t=new MistifyCanvas();
    19.         display.setCurrent(t);
    20.     }
    21.    
    22.     public void pauseApp() {
    23.     }
    24.    
    25.     public void destroyApp(boolean unconditional) {
    26.     }
    27. }
    复制代码

      
       
       
         
       

         
       
      

    二、MistifyCanvas.java
    1. import java.util.*;
    2. import javax.microedition.lcdui.*;
    3. public class MistifyCanvas extends Canvas {
    4.     Random rnd=new Random();
    5.     private Timer tt=new Timer();
    6.     private MistShape ms[]=new MistShape[2];
    7.     private MistColor mc=new MistColor(2,3,4);
    8.     int k=10;
    9.    
    10.     public MistifyCanvas() {
    11.         super();
    12.         ms[0]=new MistShape(new Rectangle(0,0,super.getWidth(),super.getHeight()));
    13.         ms[1]=ms[0].Copy();
    14.         tt.scheduleAtFixedRate(new MyTask(this),100,100);
    15.     }
    16.    
    17.     public void paint(Graphics g) {
    18.         try {
    19.             if (k==0) {
    20.                 g.setColor(255,255,255);
    21.                 ms[1].Paint(g);
    22.             }
    23.             g.setColor(mc.ColorRed(),mc.ColorGreen(),mc.ColorBlue());
    24.             ms[0].Paint(g);
    25.         }
    26.         catch (Exception e) {
    27.             g.drawString(e.toString(),10,10,0);
    28.         }
    29.     }
    30.    
    31.     protected  void keyPressed(int keyCode) {
    32.     }
    33.    
    34.     protected  void keyReleased(int keyCode) {
    35.     }
    36.    
    37.     protected  void keyRepeated(int keyCode) {
    38.     }
    39.    
    40.     protected  void pointerDragged(int x, int y) {
    41.     }
    42.    
    43.     protected  void pointerPressed(int x, int y) {
    44.     }
    45.    
    46.     protected  void pointerReleased(int x, int y) {
    47.     }
    48.    
    49.     private class MyTask extends TimerTask
    50.     {
    51.         private MistifyCanvas m;
    52.         
    53.         public MyTask(MistifyCanvas mistify) {
    54.             m=mistify;
    55.         }
    56.         
    57.         public void run() {
    58.             ms[0].Delocate();
    59.             if (k==0)
    60.                 ms[1].Delocate();
    61.             else
    62.                 k--;
    63.             
    64.             mc.Delocate();
    65.             m.repaint();
    66.         }
    67.         
    68.     }
    69.    
    70.     private class MistShape {
    71.         private MistPoint pt[]=new MistPoint[3];
    72.         
    73.         public MistShape(Rectangle rect) {
    74.             pt[0]=new MistPoint(rect,1,-2);
    75.             pt[1]=new MistPoint(rect,2,-3);
    76.             pt[2]=new MistPoint(rect,3,-1);
    77.         }
    78.         public MistShape(MistPoint mp0,MistPoint mp1,MistPoint mp2) {
    79.             pt[0]=mp0;
    80.             pt[1]=mp1;
    81.             pt[2]=mp2;
    82.         }
    83.         
    84.         public void Delocate() {
    85.             pt[0].Delocate();
    86.             pt[1].Delocate();
    87.             pt[2].Delocate();
    88.         }
    89.         
    90.         public void Paint(Graphics g) {
    91.             g.drawLine(pt[0].Left(),pt[0].Top(),pt[1].Left(),pt[1].Top());
    92.             g.drawLine(pt[1].Left(),pt[1].Top(),pt[2].Left(),pt[2].Top());
    93.             g.drawLine(pt[2].Left(),pt[2].Top(),pt[0].Left(),pt[0].Top());
    94.         }
    95.         
    96.         public MistShape Copy() {
    97.             return new MistShape(pt[0].Copy(),pt[1].Copy(),pt[2].Copy());
    98.         }
    99.     }
    100.     private class MistPoint {
    101.         private int x,y,x0,y0;
    102.         private Rectangle r;
    103.         
    104.         public MistPoint(Rectangle rect,int deltaX,int deltaY) {
    105.             r=rect;
    106.             x0=deltaX;
    107.             y0=deltaY;
    108.             x=Math.abs(rnd.nextInt()) % (r.Right()-r.Left()) + r.Left();
    109.             y=Math.abs(rnd.nextInt()) % (r.Bottom()-r.Top()) + r.Top();
    110.         }
    111.         public MistPoint(Rectangle rect,int left,int top,int deltaX,int deltaY) {
    112.             r=rect;
    113.             x=left;
    114.             y=top;
    115.             x0=deltaX;
    116.             y0=deltaY;
    117.         }
    118.    
    119.         public int Left() { return x; }
    120.         public int Top() { return y; }
    121.         
    122.         public void Delocate() {
    123.             if (x+x0< r.Left() || x+x0>r.Right()) x0=-x0;
    124.             if (y+y0< r.Top() || y+y0>r.Bottom()) y0=-y0;
    125.             x+=x0;
    126.             y+=y0;
    127.         }
    128.         public MistPoint Copy() {
    129.             return new MistPoint(r,x,y,x0,y0);
    130.         }        
    131.     }
    132.     public class MistColor {
    133.         private int r,g,b,r0,g0,b0;
    134.         
    135.         public MistColor(int deltaR,int deltaG, int deltaB) {
    136.             this.r0=deltaR;
    137.             this.g0=deltaG;
    138.             this.b0=deltaB;
    139.         }
    140.         
    141.         public int ColorRed() { return r; }
    142.         public int ColorGreen() { return g; }
    143.         public int ColorBlue() { return b; }
    144.         
    145.         public void Delocate() {
    146.             if (r+r0<0 || r+r0>255) r0=-r0;
    147.             if (g+g0<0 || g+g0>255) g0=-g0;
    148.             if (b+b0<0 || b+b0>255) b0=-b0;
    149.             r+=r0;
    150.             g+=g0;
    151.             b+=b0;
    152.         }
    153.     }
    154.    
    155.     public class Rectangle {
    156.         private int x0,y0,x1,y1;
    157.         
    158.         public Rectangle(int x0,int y0,int x1,int y1) {
    159.             this.x0=x0;
    160.             this.y0=y0;
    161.             this.x1=x1;
    162.             this.y1=y1;
    163.         }
    164.         
    165.         public int Left() { return x0; }
    166.         public int Top() { return y0; }
    167.         public int Right() { return x1; }
    168.         public int Bottom() { return y1; }
    169.     }
    170. }
    复制代码
    三、运行图:
      

      
      
       
       

         
       

         
       
      
    复制代码

    源码下载:http://203.93.208.26/kj/cwb/dir7/J2MEMistify.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-2-26 07:04 , Processed in 0.292002 second(s), 36 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表