Results 1 to 8 of 8
Thread: Three Different Dialogue Boxes
- 10-26-2010, 08:25 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 80
- Rep Power
- 0
Three Different Dialogue Boxes
Hello World!
I have to create 3 diff. dialogue boxes:
1) Input the owner's name w/wording that reads:
This program...
...
...
Please enter owner's last name
2) Please enter the sales price of the home
3) Final box should look like this:
Jone's Home Sale(in the upper left-hand corner)
The Jones' home sold for $10000.00
The cost to sell the home was $5000.00
The selling or listing agent earned $1500
I've got the first 2 boxes OK. For the last box do I have to write an inputStr for each of those 3 lines and then add and format the lines in the outputStr?
How do I get Jone's Home Sale in the upper left-hand corner?
My Code:
Java Code:import java.util.*; import javax.swing.JOptionPane; public class Wk3_Lab331b { static Scanner console = new Scanner(System.in); public static void main(String[] args) { String ownerName; String inputStr; String outputStr; double homePrice; ownerName = JOptionPane.showInputDialog ("Please enter the owner's last name and press OK: "); inputStr = JOptionPane.showInputDialog ("Please enter the sales price of the home. "); homePrice = Double.parseDouble(inputStr); outputStr = "Owner's Name: " + ownerName + " " + inputStr + "\n" + "The" + ownerName + "'s" + "home sold for"; JOptionPane.showMessageDialog(null,ownerName,"Home Sale",JOptionPane.INFORMATION_MESSAGE); } }
Thanks In AdvanceLast edited by Fubarable; 10-26-2010 at 08:35 PM. Reason: Moderator Edit: Code tags added
-
I've edited your original post and have added code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luck!Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 10-26-2010, 08:44 PM #3
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
here is the make up of the showMessageDialog() method
Object message - what will appear inside the dialog boxJava Code:public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
String title- what will appear in the upper left
int messageType - e.g. information message
- 10-26-2010, 09:30 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 80
- Rep Power
- 0
Three Different Dialogue Boxes
I want 2 decimal points for homePrice but I am only getting one 100.0. FYI: I am using jGrasp.Java Code:OutputStr = "The" + ownerName + "'s" + " home sold for : $" + homePrice + "\n" + "The cost to sell the home was: $" + cost + String.format("%.2f", homePrice);
- 10-26-2010, 09:40 PM #5
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
format before hand:
Now use the variable price inside the outputStrJava Code:String price=String.format("%.2f", homePrice);
- 10-27-2010, 01:52 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 80
- Rep Power
- 0
Three Different Dialogue Boxes
Thank you all. You help is greatly appreciated.
lala
- 10-27-2010, 08:08 PM #7
And once you get through the beginner stage, never again use double for price or other currency values. Either use int and place a decimal point before the last two digits with an appropriate format, or (better) use BigDecimal.
db
- 10-29-2010, 07:04 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 80
- Rep Power
- 0
Similar Threads
-
dialog boxes
By gedas in forum Java 2DReplies: 1Last Post: 02-19-2010, 11:23 AM -
List Boxes
By zzpprk in forum AWT / SwingReplies: 2Last Post: 12-15-2009, 09:43 PM -
Duplicate Input Boxes
By habester in forum New To JavaReplies: 3Last Post: 11-09-2009, 06:13 PM -
Dragging Boxes
By anilanar in forum New To JavaReplies: 8Last Post: 09-05-2009, 09:23 PM -
Help! Need to randomly assign boxes
By newb101 in forum New To JavaReplies: 1Last Post: 09-16-2008, 10:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks