silly girl
10-25-2003, 02:38 PM
i need help in this java program. i cant get the scroll bar to work. could some1 please help me?? :(
// Java core packages
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing. *;
// Java extension packages
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Interest {
// main method begins execution of Java application
public static void main( String args[] )
{
double amount;
String dis;
//String outputText;
// create JTextArea to display output
JTextArea outputArea = new JTextArea(17, 20);
JScrollPane scroller = new JScrollPane (outputArea);
String rte = JOptionPane.showInputDialog(
"Enter the rate: " );
String prin = JOptionPane.showInputDialog(
"Enter the principal: ");
String yr = JOptionPane.showInputDialog(
"Enter the years: ");
double rate = Double.parseDouble(rte);
double principal = Double.parseDouble (prin);
double year = Double.parseDouble (yr);
// create DecimalFormat to format floating-point numbers
// with two digits to the right of the decimal point
NumberFormat moneyFormat =
NumberFormat.getCurrencyInstance( Locale.US );
// set first line of text in outputTextArea
dis.setText( "Year\tAmount on deposit\n" );
// calculate amount on deposit for each of ten years
for ( int yea = 1; yea <= year; yea++ )
{
// calculate new amount for specified year
amount = principal * Math.pow( 1.0 + rate, yea );
// append one line of text to outputTextArea
dis.append( yea + "\t" +
moneyFormat.format( amount ) + "\n" );
} // end for structure
outputArea.setText( dis);
// display results
JOptionPane.showMessageDialog( null, scroller,
"Compound Interest", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate the application
} // end method main
} // end class Interest
// Java core packages
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing. *;
// Java extension packages
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Interest {
// main method begins execution of Java application
public static void main( String args[] )
{
double amount;
String dis;
//String outputText;
// create JTextArea to display output
JTextArea outputArea = new JTextArea(17, 20);
JScrollPane scroller = new JScrollPane (outputArea);
String rte = JOptionPane.showInputDialog(
"Enter the rate: " );
String prin = JOptionPane.showInputDialog(
"Enter the principal: ");
String yr = JOptionPane.showInputDialog(
"Enter the years: ");
double rate = Double.parseDouble(rte);
double principal = Double.parseDouble (prin);
double year = Double.parseDouble (yr);
// create DecimalFormat to format floating-point numbers
// with two digits to the right of the decimal point
NumberFormat moneyFormat =
NumberFormat.getCurrencyInstance( Locale.US );
// set first line of text in outputTextArea
dis.setText( "Year\tAmount on deposit\n" );
// calculate amount on deposit for each of ten years
for ( int yea = 1; yea <= year; yea++ )
{
// calculate new amount for specified year
amount = principal * Math.pow( 1.0 + rate, yea );
// append one line of text to outputTextArea
dis.append( yea + "\t" +
moneyFormat.format( amount ) + "\n" );
} // end for structure
outputArea.setText( dis);
// display results
JOptionPane.showMessageDialog( null, scroller,
"Compound Interest", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 ); // terminate the application
} // end method main
} // end class Interest