import java.awt.Toolkit; import java.util.Timer; import java.util.TimerTask; import javax.swing.JOptionPane; import javax.swing.JFrame; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class Reminder { Toolkit tester; static String stringInput; Timer time; public Reminder(int seconds) { tester = Toolkit.getDefaultToolkit(); time = new Timer(); time.schedule(new MediR(), seconds * 1000); } class MediR extends TimerTask { public void run() { JOptionPane.showMessageDialog(null, "Time to take " + stringInput); tester.beep(); } } public static boolean isNumeric(String str) { try { double d = Double.parseDouble(str); } catch(NumberFormatException nfe) { return false; } return true; } public static void main(String args[]) { JOptionPane.showMessageDialog(null, "This is a program that will ask for a medicine and remind you when to take it."); stringInput = JOptionPane.showInputDialog("Enter Medicine: "); String i; i = JOptionPane.showInputDialog("Enter Time to wait: "); while(isNumeric(i) == false) i = JOptionPane.showInputDialog("Invalid input. Please enter again: "); new Reminder(Integer.parseInt(i)); System.out.println("Task scheduled."); } }