timer - Doing an action after a set delay in java -


edit: got work. problem was using cmd compile exited vm before delay ended. switched jgrasp , program worked intended. next need learn how make java applet run on computer. everyone

i'm trying set alarm of sorts using java. i'd open webpage after set delay. code below compiles , runs without errors or warnings running code nothing. starts , stops program. have feeling issue arises how catch exceptions i'm not sure. little lost on actionperformed() method does. or insight appreciated

import java.awt.desktop; import java.net.uri; import java.net.urisyntaxexception; import java.io.ioexception; import java.awt.event.actionlistener; import java.awt.event.actionevent; import javax.swing.timer;  public class ytalarmtest {     public static void main (string [] args)     {         string url = "https://stackoverflow.com/questions/ask";          int delay = 1000;         actionlistener task = new actionlistener()         {             public void actionperformed(actionevent evt)              {                    try                 {                     if (desktop.isdesktopsupported())                     {                         desktop.getdesktop().browse(new uri(url));                     }                 }                 catch (urisyntaxexception e)                 {                     system.out.println("exception");                 }                 catch (ioexception e)                 {                     system.out.println("exceptio");                 }             }         };         new timer(delay, task).start();     } } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -