Advertisement
Guest User

Timer

a guest
Nov 10th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public class Test4 extends JPanel {
  2.  
  3.     static int count = 0;
  4.     static Timer timer;
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.     JFrame frame = new JFrame("Gui");
  9.     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  10.     Container contentPane = frame.getContentPane();
  11.     contentPane.setLayout ( new BorderLayout () );
  12.  
  13.  
  14.     int timerSpeed = 1; //1 милисекунда
  15.  
  16.     ActionListener al = (ActionEvent e) -> {
  17.  
  18.     System.out.println("W");
  19.  
  20.     if (count > 10000)
  21.     {
  22.     timer.stop(); //По достижении 10 секунд таймер должен остановиться
  23.     }
  24.     count++;
  25.     };
  26.      
  27.     timer = new Timer(timerSpeed, al);
  28.      
  29.     timer.start();
  30.  
  31.     frame.setSize(new Dimension(200, 200));
  32.     frame.setVisible(true);
  33.     }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement