📄 paintingdemo.java
字号:
/* * Copyright ?2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */package com.sun.lwuit.uidemo;import com.sun.lwuit.Command;import com.sun.lwuit.Component;import com.sun.lwuit.Form;import com.sun.lwuit.Graphics;import com.sun.lwuit.events.ActionEvent;import com.sun.lwuit.events.ActionListener;import com.sun.lwuit.layouts.BorderLayout;/** * Demonstrates simple animation both static and manual * * @author Shai Almog */public class PaintingDemo extends Form implements ActionListener { public Form form = new Form("PaintingDemo"); private Command backCommand = new Command("Back", 1); private Command nextCommand = new Command("next", 2); PaintingDemo() { form.addCommand(backCommand); form.addCommand(nextCommand); form.setCommandListener(this); form.setLayout(new BorderLayout()); form.addComponent(BorderLayout.CENTER, new Painting()); } public class Painting extends Component{ private int w; public void paint(Graphics g) { g.setColor(0x000000); g.fillRect(0, 0, this.getWidth(), this.getHeight()); w = getWidth(); drawSqrt1(g); g.setColor(0xffffff); g.drawString("hellogv", 12, 33); } private void drawSqrt1(Graphics g) { long start = System.currentTimeMillis(); int centerY1 = 50; //绘制X轴 //设置绘图颜色为蓝色 g.setColor(0x0000FF); g.drawLine(0, centerY1, w, centerY1); //设置绘图颜色为白色 g.setColor(0xFFFFFF); int oldX = 0; int oldY1 = centerY1; int y1; for(int i=1;i<w;i++) { // 放大3倍 y1 = centerY1 - (int)(3*Math.sqrt(i)); g.drawLine(oldX, oldY1, i, y1); oldX = i; oldY1 = y1; } long time = System.currentTimeMillis() - start; System.out.println("drawSqrt1 Runtime: " + time); } } public void actionPerformed(ActionEvent arg0) { if(arg0.getCommand()==backCommand) { UIDemoMIDlet.backToMainMenu(); } else if(arg0.getCommand()==nextCommand) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -