J2ME实现石英钟

    技术2022-05-14  4

    这个是没有进行底层加速的样例。重在模拟效果!

     

     import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; public class ClockCanvas extends Canvas implements Runnable { public int x , y ; public ClockCanvas(){ System.out.println("new "); new Thread(this).start(); } private static final int[] SinTab = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 57, 57, 58, 58, 58, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 62, 62, 62, 62, 61, 61, 61, 60, 60, 60, 59, 59, 58, 58, 58, 57, 57, 56, 55, 55, 54, 54, 53, 53, 52, 51, 51, 50, 49, 49, 48, 47, 46, 46, 45, 44, 43, 42, 41, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 32, 31, 30, 29, 28, 27, 26, 25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -25, -26, -27, -28, -29, -30, -31, -31, -32, -33, -34, -35, -36, -37, -38, -39, -40, -41, -41, -42, -43, -44, -45, -46, -46, -47, -48, -49, -49, -50, -51, -51, -52, -53, -53, -54, -54, -55, -55, -56, -57, -57, -58, -58, -58, -59, -59, -60, -60, -60, -61, -61, -61, -62, -62, -62, -62, -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, -64, -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, -62, -62, -62, -62, -61, -61, -61, -60, -60, -60, -59, -59, -58, -58, -58, -57, -57, -56, -55, -55, -54, -54, -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, -44, -43, -42, -41, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -32, -31, -30, -29, -28, -27, -26, -25, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -8, -7, -6, -5, -4, -3, -2, -1 }; private static final int[] CosTab = new int[] { 64, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 62, 62, 62, 62, 61, 61, 61, 60, 60, 60, 59, 59, 58, 58, 58, 57, 57, 56, 55, 55, 54, 54, 53, 53, 52, 51, 51, 50, 49, 49, 48, 47, 46, 46, 45, 44, 43, 42, 41, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 31, 30, 29, 28, 27, 26, 25, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -25, -26, -27, -28, -29, -30, -31, -32, -32, -33, -34, -35, -36, -37, -38, -39, -40, -41, -41, -42, -43, -44, -45, -46, -46, -47, -48, -49, -49, -50, -51, -51, -52, -53, -53, -54, -54, -55, -55, -56, -57, -57, -58, -58, -58, -59, -59, -60, -60, -60, -61, -61, -61, -62, -62, -62, -62, -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, -64, -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, -62, -62, -62, -62, -61, -61, -61, -60, -60, -60, -59, -59, -58, -58, -58, -57, -57, -56, -55, -55, -54, -54, -53, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, -44, -43, -42, -41, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -32, -31, -30, -29, -28, -27, -26, -25, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 53, 54, 54, 55, 55, 56, 57, 57, 58, 58, 58, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 }; public void paint(Graphics g) { g.setColor(0xffffff); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0xff0000); g.drawArc(28, 28, 140, 140, 0, 360) ; g.drawLine(100, 100, 100 + x, 100+ y); } public void run() { int i =0 ; while (true) { y = SinTab[i] ; x= CosTab[i] ; if (i==SinTab.length-1) { i = 0; } i++ ; repaint(); serviceRepaints(); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } } }


    最新回复(0)