JOptionpane validation with double input
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
|
show 5 more comments
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
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
|
show 5 more comments
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
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
java arrays validation double joptionpane
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
|
show 5 more comments
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
|
show 5 more comments
2 Answers
2
active
oldest
votes
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
}
}
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
add a comment |
Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
}
}
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
add a comment |
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
}
}
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
add a comment |
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
}
}
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
}
}
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
add a comment |
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
add a comment |
Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.
add a comment |
Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.
add a comment |
Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.
Read the section from the Swing tutorial on Stopping Automatic Dialog Closing. Customize the code to do you particular edit.
answered Apr 24 '13 at 23:38
camickr
274k15126239
274k15126239
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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