English 中文(简体)
相当于 j。 安乐施会
原标题:Equivalent to javax.swing.Timer in Android

是否有像<条码>javax.swing”这样的东西。 时间。 我知道如何建立自己的read子,但是否有象周转人这样的东西?

最佳回答

还有Java s TimerTask。 我的《守则》就是一个例子,我在这里做录音样本:

import java.util.Timer;
import java.util.TimerTask;

// from constructor, shown here out of place
timer = new Timer();

// and in method, again, shown out of place:
        INTERVAL_MILLISECONDS = (int)((double)(bufSize) / (double)(nativeSampleRate * 2) * 1000);
        timer.scheduleAtFixedRate( new TimerTask() {
                public void run() {
                        synchronized(this){
                                track.write(data, 0, bufSize);
                                track.play();
                        }
                }
        }, 0, INTERVAL_MILLISECONDS);
问题回答

http://developer.android.com/fer/android/os/CountDowntimer.html。

You can inherit the class like this:

class MyTimer extends CountDownTimer
{
    public MyTimer(int secsInFuture) {
        super(secsInFuture*1000, 1000); //interval/ticks each second.
    }

    @Override
    public void onFinish() {
        Log.d("mytag","timer finished!");
    }

    @Override
    public void onTick(long millisUntilFinished) {
        //fired on each interval
        Log.d("mytag","tick; " + millisUntilFinished + " ms left");
    }
}

<代码>javax.swing.timer的主要要点是,它执行全球倡议(EDT-活动铺面)的任务。 这使得操纵航程部件是安全的。

安德森也设有教育、青年和体育部,只有view.postDelayed(runnable)

下述法典正确地处理:(1) 要求调查组校对的任务,(2) 在任务需要时间超过延迟时,不要淹没调查组的read,(3) 停工时收集垃圾:

import android.os.Handler;
import android.os.Looper;

import java.util.ArrayList;

class ActionEvent {
    public ActionEvent(Object src) {

    }
}

interface ActionListener {
    public void actionPerformed(ActionEvent e);
}

class Timer {
    public Timer(int delay, ActionListener al) {
        addActionListener(al);
        _delay = delay;
    }

    public void addActionListener(ActionListener al) {
        _listeners.add(al);
    }

    private void fireActionPerformed() {
        for (ActionListener al : _listeners.toArray(new ActionListener[0])) {
            al.actionPerformed(new ActionEvent(this));
        }
    }

    private void fireAfterDelay() {
        if (!_bStarted)
            return;
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            public void run() {
                if (_bStarted) {
                    fireActionPerformed();
                    if (_bStarted)
                        fireAfterDelay();
                }
            }
        }, _delay);
    }

    public void start() {
        if (!_bStarted) {
            _bStarted = true;
            fireAfterDelay();
        }
    }

    public void stop() {
        _bStarted = false;
    }

    private final ArrayList<ActionListener> _listeners = new ArrayList<>();
    private int _delay;
    private boolean _bStarted;
}

我在“行动”和“行动生活”课堂上,与Java Swing更加兼容。 简而言之,您可以删除“行动”一词,代之以可操作的“行动生计”。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签