JOptionpane validation with double input












0














I am learning java. I try to declare a double array. For the input method, I would like to use JOptionPane. My question is how can I create the validation for this array.(For example: I want to valid that the salary input will be from 2000 to 10000). I'm sorry for my bad writing. Thank you guys!



Here is my code!



import javax.swing.JOptionPane;

public class Testing {

/**
* @param args
*/
public static void main(String args) {

double salary = new double[10];

for(int i = 0; i < salary.length; i++)
{
salary[i] = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
}

}

}









share|improve this question
























  • Do you know if and else?
    – Smit
    Apr 24 '13 at 22:00












  • What are you going to do if the salary entered is out of range?
    – PM 77-1
    Apr 24 '13 at 22:01










  • I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
    – tkay87
    Apr 24 '13 at 22:02










  • @ PM it is why I need a validation
    – tkay87
    Apr 24 '13 at 22:03










  • I need to set a limit range salary. =)
    – tkay87
    Apr 24 '13 at 22:04
















0














I am learning java. I try to declare a double array. For the input method, I would like to use JOptionPane. My question is how can I create the validation for this array.(For example: I want to valid that the salary input will be from 2000 to 10000). I'm sorry for my bad writing. Thank you guys!



Here is my code!



import javax.swing.JOptionPane;

public class Testing {

/**
* @param args
*/
public static void main(String args) {

double salary = new double[10];

for(int i = 0; i < salary.length; i++)
{
salary[i] = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
}

}

}









share|improve this question
























  • Do you know if and else?
    – Smit
    Apr 24 '13 at 22:00












  • What are you going to do if the salary entered is out of range?
    – PM 77-1
    Apr 24 '13 at 22:01










  • I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
    – tkay87
    Apr 24 '13 at 22:02










  • @ PM it is why I need a validation
    – tkay87
    Apr 24 '13 at 22:03










  • I need to set a limit range salary. =)
    – tkay87
    Apr 24 '13 at 22:04














0












0








0







I am learning java. I try to declare a double array. For the input method, I would like to use JOptionPane. My question is how can I create the validation for this array.(For example: I want to valid that the salary input will be from 2000 to 10000). I'm sorry for my bad writing. Thank you guys!



Here is my code!



import javax.swing.JOptionPane;

public class Testing {

/**
* @param args
*/
public static void main(String args) {

double salary = new double[10];

for(int i = 0; i < salary.length; i++)
{
salary[i] = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
}

}

}









share|improve this question















I am learning java. I try to declare a double array. For the input method, I would like to use JOptionPane. My question is how can I create the validation for this array.(For example: I want to valid that the salary input will be from 2000 to 10000). I'm sorry for my bad writing. Thank you guys!



Here is my code!



import javax.swing.JOptionPane;

public class Testing {

/**
* @param args
*/
public static void main(String args) {

double salary = new double[10];

for(int i = 0; i < salary.length; i++)
{
salary[i] = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
}

}

}






java arrays validation double joptionpane






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 24 '13 at 22:00

























asked Apr 24 '13 at 21:54









tkay87

8126




8126












  • Do you know if and else?
    – Smit
    Apr 24 '13 at 22:00












  • What are you going to do if the salary entered is out of range?
    – PM 77-1
    Apr 24 '13 at 22:01










  • I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
    – tkay87
    Apr 24 '13 at 22:02










  • @ PM it is why I need a validation
    – tkay87
    Apr 24 '13 at 22:03










  • I need to set a limit range salary. =)
    – tkay87
    Apr 24 '13 at 22:04


















  • Do you know if and else?
    – Smit
    Apr 24 '13 at 22:00












  • What are you going to do if the salary entered is out of range?
    – PM 77-1
    Apr 24 '13 at 22:01










  • I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
    – tkay87
    Apr 24 '13 at 22:02










  • @ PM it is why I need a validation
    – tkay87
    Apr 24 '13 at 22:03










  • I need to set a limit range salary. =)
    – tkay87
    Apr 24 '13 at 22:04
















Do you know if and else?
– Smit
Apr 24 '13 at 22:00






Do you know if and else?
– Smit
Apr 24 '13 at 22:00














What are you going to do if the salary entered is out of range?
– PM 77-1
Apr 24 '13 at 22:01




What are you going to do if the salary entered is out of range?
– PM 77-1
Apr 24 '13 at 22:01












I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
– tkay87
Apr 24 '13 at 22:02




I know if and else, but I can not apply it in the JOtionPane. I can only use it in a given data, not by JOtionPane input
– tkay87
Apr 24 '13 at 22:02












@ PM it is why I need a validation
– tkay87
Apr 24 '13 at 22:03




@ PM it is why I need a validation
– tkay87
Apr 24 '13 at 22:03












I need to set a limit range salary. =)
– tkay87
Apr 24 '13 at 22:04




I need to set a limit range salary. =)
– tkay87
Apr 24 '13 at 22:04












2 Answers
2






active

oldest

votes


















0














I think this will help you a bit to resolve your issue.



int i = 0;
double temp;
while(i < salary.length) {
// parseDouble throws NumberFormatException, handle it
temp = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
if (temp >= 2000.0 && temp <= 10000.0){
salary[i] = temp;
i++; // if in range change counter to next count
// do something
} else {
// do something for out of range
}
}





share|improve this answer























  • I tried it, it not working. =)
    – tkay87
    Apr 24 '13 at 22:21










  • Thank you for your quick respond Smit
    – tkay87
    Apr 24 '13 at 22:21










  • @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
    – Smit
    Apr 24 '13 at 22:37










  • It works perfectly. Thank you Smit. I appreciate your help.
    – tkay87
    Apr 25 '13 at 21:09










  • @tkay87 You are welcome. I am glad I could help.
    – Smit
    Apr 25 '13 at 21:10



















0














Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16202888%2fjoptionpane-validation-with-double-input%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I think this will help you a bit to resolve your issue.



    int i = 0;
    double temp;
    while(i < salary.length) {
    // parseDouble throws NumberFormatException, handle it
    temp = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
    if (temp >= 2000.0 && temp <= 10000.0){
    salary[i] = temp;
    i++; // if in range change counter to next count
    // do something
    } else {
    // do something for out of range
    }
    }





    share|improve this answer























    • I tried it, it not working. =)
      – tkay87
      Apr 24 '13 at 22:21










    • Thank you for your quick respond Smit
      – tkay87
      Apr 24 '13 at 22:21










    • @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
      – Smit
      Apr 24 '13 at 22:37










    • It works perfectly. Thank you Smit. I appreciate your help.
      – tkay87
      Apr 25 '13 at 21:09










    • @tkay87 You are welcome. I am glad I could help.
      – Smit
      Apr 25 '13 at 21:10
















    0














    I think this will help you a bit to resolve your issue.



    int i = 0;
    double temp;
    while(i < salary.length) {
    // parseDouble throws NumberFormatException, handle it
    temp = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
    if (temp >= 2000.0 && temp <= 10000.0){
    salary[i] = temp;
    i++; // if in range change counter to next count
    // do something
    } else {
    // do something for out of range
    }
    }





    share|improve this answer























    • I tried it, it not working. =)
      – tkay87
      Apr 24 '13 at 22:21










    • Thank you for your quick respond Smit
      – tkay87
      Apr 24 '13 at 22:21










    • @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
      – Smit
      Apr 24 '13 at 22:37










    • It works perfectly. Thank you Smit. I appreciate your help.
      – tkay87
      Apr 25 '13 at 21:09










    • @tkay87 You are welcome. I am glad I could help.
      – Smit
      Apr 25 '13 at 21:10














    0












    0








    0






    I think this will help you a bit to resolve your issue.



    int i = 0;
    double temp;
    while(i < salary.length) {
    // parseDouble throws NumberFormatException, handle it
    temp = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
    if (temp >= 2000.0 && temp <= 10000.0){
    salary[i] = temp;
    i++; // if in range change counter to next count
    // do something
    } else {
    // do something for out of range
    }
    }





    share|improve this answer














    I think this will help you a bit to resolve your issue.



    int i = 0;
    double temp;
    while(i < salary.length) {
    // parseDouble throws NumberFormatException, handle it
    temp = Double.parseDouble(JOptionPane.showInputDialog(null," Enter Salary: "));
    if (temp >= 2000.0 && temp <= 10000.0){
    salary[i] = temp;
    i++; // if in range change counter to next count
    // do something
    } else {
    // do something for out of range
    }
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 24 '13 at 22:47

























    answered Apr 24 '13 at 22:11









    Smit

    4,17112027




    4,17112027












    • I tried it, it not working. =)
      – tkay87
      Apr 24 '13 at 22:21










    • Thank you for your quick respond Smit
      – tkay87
      Apr 24 '13 at 22:21










    • @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
      – Smit
      Apr 24 '13 at 22:37










    • It works perfectly. Thank you Smit. I appreciate your help.
      – tkay87
      Apr 25 '13 at 21:09










    • @tkay87 You are welcome. I am glad I could help.
      – Smit
      Apr 25 '13 at 21:10


















    • I tried it, it not working. =)
      – tkay87
      Apr 24 '13 at 22:21










    • Thank you for your quick respond Smit
      – tkay87
      Apr 24 '13 at 22:21










    • @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
      – Smit
      Apr 24 '13 at 22:37










    • It works perfectly. Thank you Smit. I appreciate your help.
      – tkay87
      Apr 25 '13 at 21:09










    • @tkay87 You are welcome. I am glad I could help.
      – Smit
      Apr 25 '13 at 21:10
















    I tried it, it not working. =)
    – tkay87
    Apr 24 '13 at 22:21




    I tried it, it not working. =)
    – tkay87
    Apr 24 '13 at 22:21












    Thank you for your quick respond Smit
    – tkay87
    Apr 24 '13 at 22:21




    Thank you for your quick respond Smit
    – tkay87
    Apr 24 '13 at 22:21












    @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
    – Smit
    Apr 24 '13 at 22:37




    @tkay87 I updated the answer. What is the problem you are encountering? let us know to help you better.
    – Smit
    Apr 24 '13 at 22:37












    It works perfectly. Thank you Smit. I appreciate your help.
    – tkay87
    Apr 25 '13 at 21:09




    It works perfectly. Thank you Smit. I appreciate your help.
    – tkay87
    Apr 25 '13 at 21:09












    @tkay87 You are welcome. I am glad I could help.
    – Smit
    Apr 25 '13 at 21:10




    @tkay87 You are welcome. I am glad I could help.
    – Smit
    Apr 25 '13 at 21:10













    0














    Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.






    share|improve this answer


























      0














      Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.






      share|improve this answer
























        0












        0








        0






        Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.






        share|improve this answer












        Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 24 '13 at 23:38









        camickr

        274k15126239




        274k15126239






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16202888%2fjoptionpane-validation-with-double-input%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ