home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 3009
Discussions: 188,378, Posts: 2,243,448, Members: 232,606
Old October 23rd, 2002, 03:52 AM   Digg it!   #1 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
Converting/reading int as a boolean...

I have this set of code in my main RentACar.class:

Code:
int aaa  = JOptionPane.showConfirmDialog(null,"AAA Selected?");
This'll show a dialog box with the text AAA Selected? and then a 'yes' 'no' 'cancel' button. It returns 0, 1, and 2 respectively. The project Im working on requires that we store the instance variable 'aaa' (located in the CarRental.class) as a boolean. When I use a set method to set a value to 'aaa' it obviously needs to be a boolean but showConfirmDialog returns an int. So any ideas on how I should go about converting that int into a boolean first...or maybe even changing things around so it would work better.

This teacher is extremely anal and is making some projects more difficult than they need to be....such is school life!!!
__________________
YAH! I knew you'd be jealous

Tekk is online now   Reply With Quote
Old October 23rd, 2002, 03:59 AM     #2 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
you could use a switch statement

case 1:
boolvar = true;
case 2:
boolvar = false;
case 3:
break;

that work?

vass0922 is online now   Reply With Quote
Old October 23rd, 2002, 04:01 AM     #3 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
Hmmm, if bool is a native type, can you cast it?

Dunno how well that would work, but worth a try

Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.

jkrohn is offline   Reply With Quote
Old October 23rd, 2002, 05:28 AM     #4 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
vass, Java switch statements 'fall through' (like in C)

jkrohn, Java only lets you cast primitive numeric types to each other - boolean is primitive but not numeric.

Tekk, how's about:
Code:
int result = JOptionPane.showConfirmDialog(null,"AAA Selected?");
if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
    // bottle out
} else {
    boolean bresult = (result == JOptionPane.YES_OPTION);
}
strangerstill is offline   Reply With Quote
Old October 23rd, 2002, 10:45 PM     #5 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
works fantastic stranger Altho I suppose I could made this easier and instead of using showConfirmDialog I could have done showInputDialog and had the user enter a y or an n. Then convert those to a boolean. Ah well. This way is more fancy!!! Thanks again
Tekk is online now   Reply With Quote
Old October 24th, 2002, 12:43 PM     #6 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Yeah, don't annoy your users by making them do more work than they need to!
strangerstill is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2882)
The United States Debt (20)
Looks like Burris will get his Sena.. (7)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
dual monitors wont boot (0)
Folderchat Weekday thread (439)
New Build ( Finally ) (0)
MSN Hotmail Down??? (7)
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:06 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28