📄 ui_scroll.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.cnxinshe.noteview;import javax.microedition.lcdui.Graphics;/** * * @author 尹佳 * QQ:387687685 * email:387687685@qq.com */public class UI_Scroll { //滚动条属性 private int startX; private int startY; private int width; private int height; //滚动块属性 private int rectStartX; private int rectStartY; private int rectWidth = 14; private int rectHeight = 100; public UI_Scroll(int startX, int startY, int width, int height) { this.startX = startX; this.startY = startY; this.width = width; this.height = height; this.rectStartX = startX + 3; this.rectStartY = startY + 20; this.rectWidth = width - 4; setRect(90, 90, 90); } /** * 算法思想 * * @param alreView * @param canView * @param allView */ public void setRect(int alreView, int canView, int allView) { if (allView <= canView) { // allView = canView; rectHeight = height - 40; rectStartY = startY + 20; return; } rectHeight = canView * 100 / allView * (height - 40) / 100; rectStartY = startY + 20 + (((alreView - canView) * 100 / (allView - canView)) * (height - 40 - rectHeight)) / 100; } public void paint(Graphics g) { //画背景框 g.setColor(0); g.fillRect(startX, startY, width, height); g.setColor(0xFFFFFF); g.fillTriangle(startX + 4, startY + 15, startX + width - 4, startY + 15, startX + width / 2, startY + 5); g.fillTriangle(startX + 4, startY + height - 15, startX + width - 4, startY + height - 15, startX + width / 2, startY + height - 5); paintRect(g); } //画滚动块 private void paintRect(Graphics g) { //画包围滚动块的矩形(144,144,144) g.setColor(144, 144, 144); g.drawLine(rectStartX + 1, rectStartY, rectStartX + rectWidth - 1, rectStartY); g.drawLine(rectStartX, rectStartY + 1, rectStartX, rectStartY + rectHeight - 1); g.drawLine(rectStartX + rectWidth, rectStartY + 1, rectStartX + rectWidth, rectStartY + rectHeight - 1); g.drawLine(rectStartX + 1, rectStartY + rectHeight, rectStartX + rectWidth - 1, rectStartY + rectHeight); //画滚动块 g.setColor(136, 136, 136); g.drawLine(rectStartX + 2, rectStartY + 2, rectStartX + 2, rectStartY + rectHeight - 2); g.setColor(144, 144, 144); g.drawLine(rectStartX + 3, rectStartY + 2, rectStartX + 3, rectStartY + rectHeight - 2); g.setColor(140, 140, 140); g.drawLine(rectStartX + 4, rectStartY + 2, rectStartX + 4, rectStartY + rectHeight - 2); g.setColor(112, 112, 112); g.drawLine(rectStartX + 5, rectStartY + 2, rectStartX + 5, rectStartY + rectHeight - 2); g.setColor(80, 80, 80); g.drawLine(rectStartX + 6, rectStartY + 2, rectStartX + 6, rectStartY + rectHeight - 2); g.setColor(52, 52, 52); g.drawLine(rectStartX + 7, rectStartY + 2, rectStartX + 7, rectStartY + rectHeight - 2); g.setColor(32, 32, 32); g.drawLine(rectStartX + 8, rectStartY + 2, rectStartX + 8, rectStartY + rectHeight - 2); g.setColor(24, 24, 24); g.drawLine(rectStartX + 9, rectStartY + 2, rectStartX + 9, rectStartY + rectHeight - 2); g.setColor(24, 24, 24); g.drawLine(rectStartX + 10, rectStartY + 2, rectStartX + 10, rectStartY + rectHeight - 2); g.setColor(24, 24, 24); g.drawLine(rectStartX + 11, rectStartY + 2, rectStartX + 12, rectStartY + rectHeight - 2); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -