0

RaspberryPIで実行されるSwingGUIをテストしようとしています。私の目標は、1秒ごとのショーシステム時間です。「cycleTime」秒ごとに「planValue」が更新されます。デスクトップでテストするのは正常です。RaspPIで実行すると、「planValue」を更新したり、ポップアップの新しいダイアログを開いたりすると、非常に遅く、時間の遅延が発生します。

これはMainScreenクラスです

public class MainScreen extends javax.swing.JFrame implements ActionListener {

    private javax.swing.JLabel jLabelPlan;
    private javax.swing.JLabel jLabelSysTime;
    int planValue;
    int cycleTime = 5; //5 seconds
    int counter = 1;

    public MainScreen() {
        initComponents();
        //start timer.
        javax.swing.Timer timer = new javax.swing.Timer(1000,this);
        timer.start();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        showDisplay();
    }

    public void showDisplay() {
        DateFormat formatTime = new SimpleDateFormat("HH:mm:ss");
        jLabelSysTime.setText(formatTime.format(Calendar.getInstance().getTime()));
        jLabelPlan.setText(String.valueOf(planValue));
    }
}

新しいタイマーplanTimerを作成した場合

Timer planTimer = new Timer(cycleTime * 1000, new ActionListener() {   
    @Override
    public void actionPerformed( ActionEvent e ) {
        planValue += 1;
    }
});
planTimer.start(); //Timer updPlan start

またはループを使用しますactionPerformed(ActionEvent e)

@Override
public void actionPerformed(ActionEvent e) {
    showDisplay();
        if(counter == cycleTime) {
            planValue += 1;
            counter = 1;
        } else {
            counter++;
        }
    }
}

なにか提案を?または、RaspberriPIでGUIを実行するための最良のソリューション。ありがとう。

4

1 に答える 1

4

を使用して、イベントを繰り返し発生させるタイマーを作成する必要がありますTimer.setRepeats(true)

Timer planTimer = new Timer(cycleTime * 1000, new ActionListener() {   
    @Override
    public void actionPerformed( ActionEvent e ) {
        planValue += 1;
    }
});
plainTimer.setRepeats(true);//Set repeatable.
planTimer.start();

そして、timer変数は次のようになります。

javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener()
{
    @Override
    public void actionPerformed(ActionEvent evt)
    {
        showDisplay();
    }
});
timer.setRepeats(true);
timer.start();
于 2013-03-27T07:47:34.560 に答える