Results 1 to 8 of 8
  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default 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 Advance
    Last edited by Fubarable; 10-26-2010 at 08:35 PM. Reason: Moderator Edit: Code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck!

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    here is the make up of the showMessageDialog() method
    Java Code:
    public static void showMessageDialog(Component parentComponent,
                                         Object message,
                                         String title,
                                         int messageType)
    Object message - what will appear inside the dialog box
    String title- what will appear in the upper left
    int messageType - e.g. information message

  4. #4
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default Three Different Dialogue Boxes

    Java Code:
    OutputStr = "The" + ownerName + "'s" + " home sold for : $" + homePrice + "\n"  
    								+ "The cost to sell the home was: $"  + cost
    								+ String.format("%.2f", homePrice);
    I want 2 decimal points for homePrice but I am only getting one 100.0. FYI: I am using jGrasp.

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    format before hand:
    Java Code:
    String price=String.format("%.2f", homePrice);
    Now use the variable price inside the outputStr

  6. #6
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default Three Different Dialogue Boxes

    Thank you all. You help is greatly appreciated.
    lala

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    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

  8. #8
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default Three Different Dialogue Boxes (Solved)

    Zack & Darryl, everyone thank you so very much for making my Java journey smoother. :)

Similar Threads

  1. dialog boxes
    By gedas in forum Java 2D
    Replies: 1
    Last Post: 02-19-2010, 11:23 AM
  2. List Boxes
    By zzpprk in forum AWT / Swing
    Replies: 2
    Last Post: 12-15-2009, 09:43 PM
  3. Duplicate Input Boxes
    By habester in forum New To Java
    Replies: 3
    Last Post: 11-09-2009, 06:13 PM
  4. Dragging Boxes
    By anilanar in forum New To Java
    Replies: 8
    Last Post: 09-05-2009, 09:23 PM
  5. Help! Need to randomly assign boxes
    By newb101 in forum New To Java
    Replies: 1
    Last Post: 09-16-2008, 10:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •