Java
Home

Exemplo de Componente JTextArea Text Swing

 

/*
* Main.java
*
* Created on 16 de Janeiro de 2007, 21:39
*/

package swing_simples;

import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;


/**
*
* @author Windows
*/

public class Main {

   /** Creates a new instance of Main */
   public Main() {
   }

   /**
   * @param args the command line arguments
   */

   public static void main(String[] args) {
      // TODO code application logic here

      // Cria um formato decimal de dois digitos a direita do ponto
      NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );

      double amount, principal = 1000.0, rate = 0.05;

      JTextArea outputTextArea = new JTextArea();
      outputTextArea.setText("ANO\tQuanto em deposito\n" );
      
      for ( int year=1; year<=10; year++ )
      {
         amount = principal * Math.pow( 1.0 + rate, year );

         outputTextArea.append( year + "\t" + moneyFormat.format( amount ) + "\n" );
      }


      JOptionPane.showMessageDialog(null, outputTextArea, "Titulo", JOptionPane.INFORMATION_MESSAGE );


      System.exit(0);


   }

}