PDA

View Full Version : question about JOptionPane


inkedmn
09-01-2002, 11:25 PM
ok, so i have this statement in my applet code:


JOptionPane.showMessageDialog(null, "Subtotal with tax: " + formattedTotalWithTax +
"\nDiscount Amount: " + formattedDiscountAmount +
"\nTotal Cost: " + formattedTotalCost);


but, it's opening a new window for each element i want to print instead of just listing the three in one window...

eh?

Dru Lee Parsec
09-03-2002, 12:19 PM
By "for each element " do you mean each line? I wrote a quick and dirty test and it seemed to work>

import javax.swing.*;

public class Dtest
{
public static void main(String args[])
{
String formattedTotalCost = "12.50";
String formattedDiscountAmount = "35.48";
String formattedTotalWithTax = "53.49";
JOptionPane.showMessageDialog(null, "Subtotal with tax: " + formattedTotalWithTax +
"\nDiscount Amount: " + formattedDiscountAmount +
"\nTotal Cost: " + formattedTotalCost);

}
}


What is the data type you used for formattedTotalWithTax, formattedDiscountAmount , and formattedTotalCost ? I used String.

Dru Lee Parsec
09-03-2002, 12:25 PM
Here's a jpeg of the output of the code I just posted.

inkedmn
09-03-2002, 02:19 PM
yeah, the formatted outputs are Strings...

it's weird, when i open the crapp-o html page i made for this (it's an applet, btw), i get individual message boxes for each value. when i open it with appletviewer, it works fine...

weird...

Dru Lee Parsec
09-03-2002, 06:13 PM
when i open the crapp-o html page

AHA! OK, so you're running it through your browser. I'm going to bet that your browser has an older version of the JRE. That's why it works with appletviewer and not in the browser.

OK, so here's how to fix that. Go here http://java.sun.com/products/plugin/index.html (Damn that link was hard to find on Sun's new web site) and click the "I.T. Professional" link. Part of the Java Plugin package you'll be downloading is a tool called HTML Convertor. Run the convertor on the HTML you're sending to your browser. What will happen is that when the applet is run it will check your browser to see if you have the latest JVM. If not, then you will be asked to download the JVM (once only). After that your applet will work fine.

In the future any other applet which has been tagged by the html convertor will also use the new Java runtime environment. So this is a one time download for your users.