Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

Void method and return associated with multiple if's

Thread view: 
sanna - 02 Feb 2006 16:50 GMT
Hi,

I have a situation where there is one void method
public void(event){
if (actionCmd.equals("Update")) {

if(condition){
do this;
}
if(condition2){
do this;
}
if(condition3){
do this;
}
if(condition4){
do this;
}
if(condition5){
do this;
}
int i = JOptionPane.showConfirmDialog(
                                                        null,
                                                        "It will
update the Database.  Are you Sure?",
                                                        "Update
Database",

JOptionPane.YES_NO_OPTION);
if (i == 0) {
   getUpdate().updateDatabase();
 }
}

then other whole bunch of if'ssss and then

}

Now I need to return or exit thru the whole method of updating if
conditions3,4, 5 are true. That means if condition 3, 4, 5 are true I
do not want to go to
int i = JOptionPane.showConfirmDialog(
                                                        null,
                                                        "It will
update the Database.  Are you Sure?",
                                                        "Update
Database",

JOptionPane.YES_NO_OPTION);
and so on.......

I tried having a return; after condition3 if and condition4 if and
condition5 if but in that case if condition 3 is true, it will return
and not go to condition 4 or 5 at all. But I need to check these
conditions before returning the method....
Any suggestions?

Thanks.
opalpa@gmail.com opalinski from opalpaweb - 02 Feb 2006 16:59 GMT
boolean dontGiveOption = false;

if(condition3){
 dontGiveOption = true;
do this;
}

if(condition4){
   dontGiveOption = true;
do this;
}

if(condition5){
   dontGiveOption = true;
do this;
}

if (dontGiveOption)
 return

// Option code here

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
sanna - 02 Feb 2006 17:17 GMT
> boolean dontGiveOption = false;
>
[quoted text clipped - 17 lines]
>
> // Option code here

Thanks!
I tried it, now I can get to all the condition 3, 4,5. and dont get the
update databse part.

but when all these conditions are false, It will still NOT go to the
updateDatabase part. which i am thinking is beacause
> if (dontGiveOption)
>   return
is right before this:
int i = JOptionPane.showConfirmDialog(
                                                        null,
                                                        "It will
update the Database.  Are you Sure?",
                                                        "Update
Database",

JOptionPane.YES_NO_OPTION);
if (i == 0) {
   getUpdate().updateDatabase();
 }

Any suggestions please?

Thanks a lot!
opalpa@gmail.com opalinski from opalpaweb - 02 Feb 2006 17:42 GMT
Did you put JOptionPane code outside if (dontGiveOption) block?  The if
(dontGiveOption) block has only one statement in it: return;.

Also  if (i == 0) {  should probably be:
  if (n == JOptionPane.YES_OPTION) {

The option dialog and getUpdate().updateDatabase();  go together right?
There are no conditions where you skip option dialog yet update
database?  Right?  I'm not clear on this part from your second post.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
sanna - 02 Feb 2006 19:41 GMT
> Did you put JOptionPane code outside if (dontGiveOption) block?  The if
> (dontGiveOption) block has only one statement in it: return;.
[quoted text clipped - 5 lines]
>  There are no conditions where you skip option dialog yet update
> database?  Right?  I'm not clear on this part from your second post.

yes, they go together. if i ==0 it will mean yes and update the
database. if i==1 then it will not update the database. and thats it,
it stops there.
but now problem is that it stops after if(dontGiveOption) part and I
dont even get the JoptionPane at all.....

I had it like this:
if (dontGiveOption) {
return;
    }
int i = JOptionPane.showConfirmDialog(
     null,
     "It will update the Database.  Are you Sure?",
    "Update Database",
 JOptionPane.YES_NO_OPTION);
if (i == 0) {
 getUpdate().updateDatabase();
  }

Thanks,
opalpa@gmail.com opalinski from opalpaweb - 02 Feb 2006 19:53 GMT
> but now problem is that it stops after if(dontGiveOption) part and I
> dont even get the JoptionPane at all.....

If it stopping after "if(dontGiveOption)" when you don't want it to
that means you are setting dontGiveOption to true when you don't want
it to be so.

Some info on how conditionals work:
http://www.cookienest.com/content/javabasics-conditionals.php

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Roedy Green - 02 Feb 2006 18:58 GMT
>Now I need to return or exit thru the whole method of updating if
>conditions3,4, 5 are true. That means if condition 3, 4, 5 are true I
>do not want to go to

I am not quite following you, but problems of this sort are often
solved with a boolean.

Something like this:

boolean doctorNeeded;
if ( condition1 )
{
doctorNeeded = true;
 washTheWound();
}
if ( condition2 )
{
doctorNeeded = false;
applyDressing();
}

if ( doctorNeeded )
{
....
}
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Tony Morris - 03 Feb 2006 01:37 GMT
> Hi,
>
[quoted text clipped - 54 lines]
>
> Thanks.

The blind are leading the blind.
Read up on the strategy design pattern - you have a failure of abstraction.

Signature

Tony Morris
http://tmorris.net/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.