J2ME GUI实战之五 ----------LWUIT的绘图功能
2009-09-12 00:00:00 来源:WEB开发网接着再给出绘图功能实现的代码:
1. /*
2. * Copyright ?2008 Sun Microsystems, Inc. All rights reserved.
3. * Use is subject to license terms.
4. *
5. */
6. package com.sun.lwuit.uidemo;
7.
8. import com.sun.lwuit.Command;
9. import com.sun.lwuit.Component;
10. import com.sun.lwuit.Form;
11. import com.sun.lwuit.Graphics;
12. import com.sun.lwuit.events.ActionEvent;
13. import com.sun.lwuit.events.ActionListener;
14. import com.sun.lwuit.layouts.BorderLayout;
15.
16.
17. /**
18. * Demonstrates simple animation both static and manual
19. *
20. * @author Shai Almog
21. */
22. public class PaintingDemo extends Form implements ActionListener {
23. public Form form = new Form("PaintingDemo");
24. private Command backCommand = new Command("Back", 1);
25. private Command nextCommand = new Command("next", 2);
26. PaintingDemo()
27. {
28. form.addCommand(backCommand);
29. form.addCommand(nextCommand);
30. form.setCommandListener(this);
31. form.setLayout(new BorderLayout());
32. form.addComponent(BorderLayout.CENTER, new Painting());
33.
34. }
35. public class Painting extends Component{
36. private int w;
37. public void paint(Graphics g) {
38. g.setColor(0x000000);
39. g.fillRect(0, 0, this.getWidth(), this.getHeight());
40. w = getWidth();
41. drawSqrt1(g);
42. g.setColor(0xffffff);
43. g.drawString("hellogv", 12, 33);
44.
45. }
46. private void drawSqrt1(Graphics g) {
47. long start = System.currentTimeMillis();
48.
49. int centerY1 = 50;
50.
51. //绘制X轴
52. //设置绘图颜色为蓝色
53. g.setColor(0x0000FF);
54. g.drawLine(0, centerY1, w, centerY1);
55.
56. //设置绘图颜色为白色
57. g.setColor(0xFFFFFF);
58. int oldX = 0;
59. int oldY1 = centerY1;
60.
61. int y1;
62. for(int i=1;i<w;i++) {
63. // 放大3倍
64. y1 = centerY1 - (int)(3*Math.sqrt(i));
65. g.drawLine(oldX, oldY1, i, y1);
66. oldX = i;
67. oldY1 = y1;
68. }
69. long time = System.currentTimeMillis() - start;
70. System.out.println("drawSqrt1 Runtime: " + time);
71. }
72.
73. }
74. public void actionPerformed(ActionEvent arg0) {
75. if(arg0.getCommand()==backCommand)
76. {
77. UIDemoMIDlet.backToMainMenu();
78. }
79. else if(arg0.getCommand()==nextCommand)
80. {
81.
82. }
83. }
84. }
OK,还是那句,希望大家多多支持LWUIT,让它可以做得更加好!
- ››实战:企业使用交换机VLAN路由配置
- ››实战案例分析:高质量软文对网站百度排名的影响
- ››实战经验浅谈网站搬家后的优化工作
- ››GUI库:使本机应用程序具备Windows窗体的简易性
- ››实战Active Directory站点部署与管理,Active Dir...
- ››实战操作主机角色转移,Active Directory系列之十...
- ››实战经验:巧用微博推广淘宝网店
- ››实战iPhone GPS定位系统
- ››实战Linux环境配置DBD:Oracle模块
- ››实战DeviceIoControl系列之一:通过API访问设备驱...
- ››实战DeviceIoControl系列之二:获取软盘/硬盘/光盘...
- ››实战DeviceIoControl系列之三:制作磁盘镜像文件
更多精彩
赞助商链接