Java Tutorial - Swing Timer | ActionListener | SIMPLE

Опубликовано: 16 Апрель 2017
на канале: Morriso
8,299
59

Step by step tutorial explaining how to implement a swing timer using an actionListener / Event. Watch the full video to learn how to initiate a timer from a JButton, whilst also learning the basic of passing data into methods using parameters.

Music sourced from: http://nocopyrightsounds.co.uk/

Full source code below:

import javax.swing.Timer;
import java.awt.event.ActionListener;

public class SwingTimer{

Timer stopwatch;

int count = 0;
int delay = 1000;


//startTimer(60); this is how to instantiate the timer method for 60 secs

public void startTimer(int countPassed){
ActionListener action = new ActionListener(){
public void actionPerformed(ActionEvent e){
if(count == 0){
stopwatch.stop();
lblTimer.setText("You're out of time!");

}else{
lblTimer.setText("You have " + count + " seconds remaining");
count --;
}
}
};
stopwatch = new Timer(delay, action);
stopwatch.setInitialDelay(0);
stopwatch.start();
count = countPassed;
}
}


На этой странице сайта вы можете посмотреть видео онлайн Java Tutorial - Swing Timer | ActionListener | SIMPLE длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Morriso 16 Апрель 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 8,299 раз и оно понравилось 59 зрителям. Приятного просмотра!