473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Java Swing Application Reload?

risk32
98
Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box :
Expand|Select|Wrap|Line Numbers
  1. int reply;
  2. String message = "Do you want to input another number?";
  3. String title = "Input Another Number?";
  4. reply = (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
  5. if (reply == JOptionPane.NO_OPTION) {
  6. System.exit(0); }
  7.  
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.

Expand|Select|Wrap|Line Numbers
  1. // TimeConverter.java
  2. // Author: Adam Martin 
  3. // Assignment #2, Time Converter 
  4. // This program lets the user input seconds and converts into hours, minutes and seconds (HH:MM:SS).
  5.  
  6.     // Imports the GUI interface used by Swing. JOptionPane is used for producing special windows called dialog 
  7.     // windows, dialog boxes, or just dialogs.
  8.     import javax.swing.JOptionPane;
  9.  
  10.      public class TimeConverter
  11.         {
  12.             public static void main(String[] args)
  13.                 {            
  14.  
  15.  
  16.     // Input dialog box to input number of seconds. Takes the input from the user and assigns it to a string
  17.     // and converts the string into an integer
  18.  
  19.        String secondsString = JOptionPane.showInputDialog("Enter number of seconds:");
  20.     int secondsAmount = Integer.parseInt(secondsString);                    
  21.  
  22.     int hours, minutes, seconds, remainder;  // whole number for hours, divides seconds by 3600 (number of seconds in one hour)    
  23.         hours = secondsAmount / 3600;        // the remainder operator (%) will get the remainder of secondsAmount / 3600 
  24.         remainder = secondsAmount % 3600;    // whole number for minutes, divides the remainder by 60 (number of seconds in one minute)
  25.         minutes = remainder / 60;            // remainder operator gets the remainder of secondsAmount / 60, it will be used as the left
  26.         seconds = remainder % 60;            // over seconds that were not converted
  27.  
  28.         JOptionPane.showMessageDialog(null,"The time is " + (hours < 10 ? "0" : "") + hours + ":" +
  29.                                      (minutes < 10 ? "0" : "") + minutes + ":" + (seconds <10 ? "0" : "") + seconds + " (HH:MM:SS)");
  30.  
  31.     int reply;
  32.         String message = "Do you want to input another number?"; 
  33.         String title = "Input Another Number?";  
  34.         reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
  35.            if (reply == JOptionPane.NO_OPTION) {  
  36.         System.exit(0); }
  37.         if (reply == JOptionPane.YES_OPTION) {
  38.                     }
  39.                 }
  40.             }                    
  41.  
  42.  
Thanks,
Adam
Dec 10 '08 #1
8 5655
JosAH
11,448 Expert 8TB
Just a while loop will do:

Expand|Select|Wrap|Line Numbers
  1. while (true) {
  2.    // all your original code here ...
  3.    // ...
  4.    if (JOptionPane.showConfirmDialog(null, message, title,  
  5.          JOptionPane.YES_NO_OPTION == JOptionPane.NO_OPTION) 
  6.         System.exit(0);
  7. }
  8.  
kind regards,

Jos
Dec 10 '08 #2
risk32
98
That's all there is to it? What determines the true/false value of the code?
Dec 11 '08 #3
r035198x
13,262 8TB
Read the code that has been posted and see what that if is doing there.
Dec 11 '08 #4
risk32
98
The if statement is if the JOptionPane.NO_OPTION is selected, the system will exit. BUT, there is no statement for the boolean value of true/false for the option selected.
Dec 12 '08 #5
JosAH
11,448 Expert 8TB
@risk32
You don't need it, it is directly put in the if clause. Anything that can be true or false can be used for an if clause;

You did this:

Expand|Select|Wrap|Line Numbers
  1. boolean result= ... something complicated ...
  2. if (result) ...
  3.  
and I did this:

Expand|Select|Wrap|Line Numbers
  1. if (... something complicated ...) ...
  2.  
kind regards,

Jos
Dec 12 '08 #6
karthickkuchanur
156 100+
@JosAH
I dont know where to post the new thread

iam login after a long time ,iam ashame to post here
Dec 12 '08 #7
r035198x
13,262 8TB
Go to answers - bytes
There is a button for "New Thread" near the top left corner.
Dec 12 '08 #8
risk32
98
Thanks for the help Jos, I had to tweak my code a little since I had 2 showConfirmDialog screens. I also had to add an extra ')' that was missing. I found that out from my Java instructor. I must say, it's conforting that there are individuals like yourselves willing to help others when learning, or when they're stuck. I really appreciate it.

Adam
Dec 17 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SubbaRao Karanam | last post by:
What does this error for the Code below java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at...
73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
5
by: erekose666 | last post by:
I have this program right now, but I need to modify it to output to the JTextPane. What I mean is, when someone clicks on the 1 button, it needs to output to the TextArea a 1. None of the add,...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
5
by: xirowei | last post by:
public class Result { private int countA = 0; private int countB = 0; private int statement; private boolean statusA = false; private boolean statusB = false; private int arrayA = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.