// DecimalFormattingScroller.java
// Demos formatting with $ and decimal places
// Demos JScrollPane( );
// APPLET CODE="DecimalFormattingScroller" HEIGHT=300 WIDTH=400
import java.awt.*;
import javax.swing.*;
import java.text.DecimalFormat;

public class DecimalFormattingScroller extends JApplet {
        double amount;
        Container c;
        JTextArea displayDec;
        JScrollPane scroller;
        
        public void init( ) {
                c = getContentPane( );
                c.setLayout( new FlowLayout( ) );
                amount = 3999.33999999999;
                DecimalFormat currency0 = new DecimalFormat( "$0" );
                DecimalFormat comma1 = new DecimalFormat( "#,##0.0" );
                DecimalFormat currency2 = new DecimalFormat( "$#,##0.00" );
        
                displayDec = new JTextArea( 2, 30 );

                scroller = new JScrollPane( displayDec );

                c.add( scroller );

                displayDec.append( "The amount formatted with a dollar sign, no commas and no decimals is " + currency0.format( amount ) + ",\n" +
                                "the amount formatted without a dollar sign but with commas and one decimal is " + comma1.format( amount ) + " and\n" +
                                "the amount formatted with a dollar sign, commas and two decimals is " + currency2.format( amount ) + "." );
        }
}