List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:MainClass.java
License:asdf
public static void main(String[] args) { Timer timer = new Timer(1000, new MyTimerActionListener()); timer.start();//from www . j a va 2s .c o m try { Thread.sleep(10000); } catch (InterruptedException e) { } timer.stop(); }
From source file:MainClass.java
public static void main(String[] args) { Timer t = new Timer(1000, new Ticker()); t.start();// w w w .j a v a 2 s. c o m JOptionPane.showMessageDialog(null, "Click OK to exit program"); System.exit(0); }
From source file:Main.java
public static void main(String[] args) { final JLabel label = new JLabel(); int timerDelay = 1000; new Timer(timerDelay, new ActionListener() { int timeLeft = 5; @Override//from w ww . j a v a 2 s. com public void actionPerformed(ActionEvent e) { if (timeLeft > 0) { label.setText("Closing in " + timeLeft + " seconds"); timeLeft--; } else { ((Timer) e.getSource()).stop(); Window win = SwingUtilities.getWindowAncestor(label); win.setVisible(false); } } }) { { setInitialDelay(0); } }.start(); JOptionPane.showMessageDialog(null, label); }
From source file:MainClass.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hello World Timer"); }//from w w w. j a v a 2 s. c o m }; Timer timer = new Timer(500, actionListener); timer.start(); }
From source file:TimerSample.java
public static void main(String args[]) { new JFrame().setVisible(true); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hello World Timer"); }/* www. j av a 2 s.co m*/ }; Timer timer = new Timer(500, actionListener); timer.start(); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(pb);//w w w . jav a 2s.c o m f.pack(); f.setVisible(true); Timer timer = new Timer(50, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { progress += 1; if (progress >= 100) { progress = 100; ((Timer) e.getSource()).stop(); } pb.setValue(progress); } }); timer.start(); }
From source file:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Date date = new Date(); final JLabel timeLabel = new JLabel(date.toString()); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { date.setTime(System.currentTimeMillis()); timeLabel.setText(date.toString()); }//www .j a v a 2 s . co m }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea textArea = new JTextArea(); f.add(new JScrollPane(textArea), BorderLayout.CENTER); Timer timer = new Timer(1000, new ActionListener() { @Override//from w w w .java 2 s.c om public void actionPerformed(ActionEvent e) { textArea.append("bla"); } }); timer.setRepeats(true); timer.start(); JButton button = new JButton("Click me"); button.addActionListener(e -> { System.out.println("Before option pane"); JOptionPane.showMessageDialog(f, "A message dialog"); System.out.println("After option pane"); }); f.add(button, BorderLayout.SOUTH); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:TimerSample.java
public static void main(String args[]) { Runnable runner = new Runnable() { public void run() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hello World Timer"); }/*from ww w. ja va2 s . c om*/ }; Timer timer = new Timer(500, actionListener); timer.start(); } }; EventQueue.invokeLater(runner); }
From source file:TimerSample.java
public static void main(String args[]) { Runnable runner = new Runnable() { public void run() { Timer.setLogTimers(true); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Hello World Timer"); }//from w ww. ja v a 2s . co m }; Timer timer = new Timer(500, actionListener); timer.start(); } }; EventQueue.invokeLater(runner); }