display image after after on the panel with a time gap

前端 未结 2 759
礼貌的吻别
礼貌的吻别 2021-01-26 08:42
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.*;
import java.io.*;

import javax.swing.ImageIcon;
imp         


        
相关标签:
2条回答
  • 2021-01-26 09:20

    Use a Swing Timer (not a TimerTask). When the Timer fires the code will execute in the EDT so you can safely reset the icon of your JLabel. So I would first create ImageIcons from your BufferedImages and store the Icons in your array.

    Read the secton from the Swing tutorial on How to Use Timers for more information. You may also want to check out the section on Concurreny to understand why executing code in the EDT is important.

    0 讨论(0)
  • 2021-01-26 09:26

    You can create a TimerTask

    class VideoTask extends TimerTask {
       private Frame frame;
       private int frameId;
       public void run() {
         frame.drawImage(....);
         frameId++;
       }
    }
    

    And in the action listener for the button - schedule the task:

    VideoTask videoTask = new VideoTask(frame);
    videoTask.schedule(..);
    
    0 讨论(0)
提交回复
热议问题