Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box :
This part works great, now down to business:
I'm trying to get the program to basically reload it, or go back to the beginning
if the reply is YES.
I have googled until my fingers hurt, but I haven't found anything except for JS.
(The window.reload function)
Here's the complete code for my program. If there's anything I can do to accomplish this, please let me know. Otherwise I'll be forced to take it out of the program. By the way, I'm using JCreator.
Thanks,
Adam
Code:
int reply;
String message = "Do you want to input another number?";
String title = "Input Another Number?";
reply = (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.NO_OPTION) {
System.exit(0); }
I'm trying to get the program to basically reload it, or go back to the beginning
if the reply is YES.
I have googled until my fingers hurt, but I haven't found anything except for JS.
(The window.reload function)
Here's the complete code for my program. If there's anything I can do to accomplish this, please let me know. Otherwise I'll be forced to take it out of the program. By the way, I'm using JCreator.
Code:
// TimeConverter.java
// Author: Adam Martin
// Assignment #2, Time Converter
// This program lets the user input seconds and converts into hours, minutes and seconds (HH:MM:SS).
// Imports the GUI interface used by Swing. JOptionPane is used for producing special windows called dialog
// windows, dialog boxes, or just dialogs.
import javax.swing.JOptionPane;
public class TimeConverter
{
public static void main(String[] args)
{
// Input dialog box to input number of seconds. Takes the input from the user and assigns it to a string
// and converts the string into an integer
String secondsString = JOptionPane.showInputDialog("Enter number of seconds:");
int secondsAmount = Integer.parseInt(secondsString);
int hours, minutes, seconds, remainder; // whole number for hours, divides seconds by 3600 (number of seconds in one hour)
hours = secondsAmount / 3600; // the remainder operator (%) will get the remainder of secondsAmount / 3600
remainder = secondsAmount % 3600; // whole number for minutes, divides the remainder by 60 (number of seconds in one minute)
minutes = remainder / 60; // remainder operator gets the remainder of secondsAmount / 60, it will be used as the left
seconds = remainder % 60; // over seconds that were not converted
JOptionPane.showMessageDialog(null,"The time is " + (hours < 10 ? "0" : "") + hours + ":" +
(minutes < 10 ? "0" : "") + minutes + ":" + (seconds <10 ? "0" : "") + seconds + " (HH:MM:SS)");
int reply;
String message = "Do you want to input another number?";
String title = "Input Another Number?";
reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.NO_OPTION) {
System.exit(0); }
if (reply == JOptionPane.YES_OPTION) {
}
}
}
Adam
Comment