gpt4 book ai didi

blackberry - 黑莓上的字幕文本

转载 作者:行者123 更新时间:2023-12-02 05:19:36 24 4
gpt4 key购买 nike

我想在 BlackBerry 应用程序中选取一些文本。

最佳答案

在这里。只需创建一个名为 MarqueeLabel 的类并复制粘贴此代码,然后您就可以使用此类来显示选取框文本:

package mypackage;

import java.util.Timer;

import java.util.TimerTask;

import net.rim.device.api.system.Display;

import net.rim.device.api.ui.DrawStyle;

import net.rim.device.api.ui.Font;

import net.rim.device.api.ui.Graphics;

import net.rim.device.api.ui.component.LabelField;

class MarqueLabel extends LabelField {

int currentChar = 0;

String currentText = null;

Font ourFont;

private Timer _scrollTimer;

private TimerTask _scrollTimerTask;

public MarqueLabel(String text, long style) {

super(text, style);

}

public void paint(Graphics graphics) {

currentText = this.getText();

if (currentChar < currentText.length()) {

currentText = currentText.substring(currentChar);

}

graphics.drawText(currentText, 0, 0, DrawStyle.ELLIPSIS, Display.getWidth());

super.paint(graphics);

}

public void layout(int width, int height) {

ourFont = this.getFont();

setExtent(500, ourFont.getHeight());

}

protected void onDisplay() {

startScroll();

}

protected void onUnfocus() {

startScroll();

}

private void startScroll() {

// Start scrolling

final String fullText = this.getText();

if (_scrollTimer == null) {

_scrollTimer = new Timer();

_scrollTimerTask = new TimerTask() {

public void run() {

currentChar = currentChar + 2;

if (currentChar > fullText.length()) {

currentChar = 0;

}

invalidate();

}

};

_scrollTimer.scheduleAtFixedRate(_scrollTimerTask, 0, 450);

}

}

protected void onFocus(int direction) {

if (_scrollTimer != null) {

_scrollTimerTask.cancel();

_scrollTimer.cancel();

_scrollTimer = null;

_scrollTimerTask = null;

}

}

protected boolean navigationMovement(int dx, int dy,

int status, int time) {

currentText = this.getText();

int oldCurrentChar = currentChar;

if (Math.abs(dx) > Math.abs(dy)) {

if (dx > 0) {

currentChar = Math.min(currentText.length() - 1,

currentChar + 1);

} else if (dx < 0) {

currentChar = Math.max(0, currentChar - 1);

}

if (oldCurrentChar != currentChar) {

this.invalidate();

}

return true;

} else {

return super.navigationMovement(dx, dy, status, time);

}

}

}

关于blackberry - 黑莓上的字幕文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1672020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com