4 Replies - 3999 Views - Last Post: 07 November 2006 - 02:34 PM Rate Topic: -----

#1 keitham_2002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-October 06

"showMessageDialog" not found and formatting to two decimal

Posted 31 October 2006 - 12:42 PM

when i compile i get this error saying symbol not found, also how do I format the output dialog box so that all of those numbers are to two decimal places. im supposed to use string format but dont completely understand how to do that. error below and code attached. thanks,

keith
_______________________________
error:

TriangleMeasurementsDialogBox.java:39: cannot find symbol
symbol : method showMessageDialog(<nulltype>,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null, outputStr, JOptionPane.INFORMATION_MESSAGE);
^
1 error

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
__________________________________


import java.util.*;
import javax.swing.JOptionPane;
import static java.lang.Math.*;

public class TriangleMeasurementsDialogBox
{
   public static void main (String [] args)
	{ double num1, num2, num3; //Sides of triangle
	  double x;				//Perimeter of tringle variable
	  double area;			 //Area of a triangle
	  String sidesStr;
	  String outputStr;

	  //Input the three numbers in dialog box
	  sidesStr =
		  JOptionPane.showInputDialog("Enter the lengths of three sides of a triangle seperated by spaces: ");

	 //Determine the perimeter
	 x = num1 + num2 + num3;

	 //Determine the area
	 area = sqrt((x/2) * (x/2 - num1) * (x/2 - num2) * (x/2 - num3));

	 //Out put the sides, perimeter and area in dialog box
 
	 outputStr = "Sides: " + num1 + num2 + num3 +
				 "Perimeter: " + x + "units" +
				 "Area: " + area + "square units";
	 
	  JOptionPane.showMessageDialog(null, outputStr, JOptionPane.INFORMATION_MESSAGE);

	  System.exit(0);
	  

	 }
}



Is This A Good Question/Topic? 0
  • +

Replies To: "showMessageDialog" not found and formatting to two decimal

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 289
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: "showMessageDialog" not found and formatting to two decimal

Posted 31 October 2006 - 03:07 PM

think you forgot the third parameter (title) to
	JOptionPane.showMessageDialog(null, outputStr, "results", JOptionPane.INFORMATION_MESSAGE);



you also need to extract num1 num2 and num3 from the String sidesStr
You can wrap sidesStr in a StringReader() and then use Scannet.readInt().

To format your output to two decimal places use the Formatter class which allows C printf-style format strings. see
http://java.sun.com/.../Formatter.html

updated code is now
import java.util.*;
import javax.swing.*;
import static java.lang.Math.*;
import java.io.*;

public class TriangleMeasurementsDialogBox
{
   public static void main (String [] args)
	{ double num1=0, num2=0, num3=0; //Sides of triangle
	  double x;				//Perimeter of tringle variable
	  double area;			 //Area of a triangle
	  String sidesStr;

	  //Input the three numbers in dialog box
	  sidesStr = JOptionPane.showInputDialog("Enter the lengths of three sides of a triangle seperated by spaces: ");
	  Scanner scanner=new Scanner(new StringReader(sidesStr));
	  num1=scanner.nextInt();
	  num2=scanner.nextInt();
	  num3=scanner.nextInt();
 
	  //Determine the perimeter
	  x = num1 + num2 + num3;

	  //Determine the area
	  area = sqrt((x/2) * (x/2 - num1) * (x/2 - num2) * (x/2 - num3));

	  //Out put the sides, perimeter and area in dialog box
	  Formatter outputStr = new Formatter(new StringBuilder());
	  outputStr.format("Sides: %4.2f %4.2f %4.2f, Perimeter: %4.2f units, Area: %4.2f square units", num1, num2, num3, x, area);
	  JOptionPane.showMessageDialog(null, outputStr, "results", JOptionPane.INFORMATION_MESSAGE);
	  System.out.println(outputStr);
	  System.exit(0);
	 }
}


if 5 12 16 is entered the output is now
Sides: 5.00 12.00 16.00, Perimeter: 33.00 units, Area: 20.66 square units

This post has been edited by horace: 01 November 2006 - 04:37 AM

Was This Post Helpful? 0
  • +
  • -

#3 keitham_2002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-October 06

Re: "showMessageDialog" not found and formatting to two decimal

Posted 07 November 2006 - 11:52 AM

Thanks, that helps alot. one last thing how do I format the output box to show the three items on seperate line?
__________
sides:
perimeter:
area:....
Was This Post Helpful? 0
  • +
  • -

#4 keitham_2002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 17-October 06

Re: "showMessageDialog" not found and formatting to two decimal

Posted 07 November 2006 - 12:04 PM

nvm did some reading figured that out too. love this site.
Was This Post Helpful? 0
  • +
  • -

#5 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 289
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: "showMessageDialog" not found and formatting to two decimal

Posted 07 November 2006 - 02:34 PM

View Postkeitham_2002, on 7 Nov, 2006 - 06:52 PM, said:

Thanks, that helps alot. one last thing how do I format the output box to show the three items on seperate line?
__________
sides:
perimeter:
area:....

put newline characters \n in the output string, i.e.
outputStr.format("Sides: %4.2f %4.2f %4.2f\n Perimeter: %4.2f units\n Area: %4.2f square units", num1, num2, num3, x, area);
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1