DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2006
    Location
    Military
    Posts
    2

    Question Turning this program into a GUI

    Can someone please explain to me how to turn this program into a GUI? Thanks.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.Toolkit;
    import javax.swing.JOptionPane;
    import java.io.IOException;
    import java.io.*;
    import java.util.Date;
    import java.text.*; //Declares the java import for accomplishing mathematical logic and float numbers

    public class newprogram3 //public class for java
    {//begin logic for string arguments (main)

    public static void main(String[] args)//throws exception for possible user input error
    {//begin logic for program

    getinput();
    finish();

    }

    public static void Titles()
    {
    System.out.println("\tBalance\t\t\tPayments\t\tInterest\n\n");
    }


    public static void getinput()
    {
    int input = 0;
    final double interest[] = {5.35, 5.5, 5.75};
    final int AmountTerm[] = {7, 15, 30};
    double monthlyPayment[] = new double[3];
    int Add = 1;
    String amount = ("Enter the loan amount for amoritization list\n(do not use commas or dollar signs)\n or click cancel to exit:");
    if(amount == null) finish();
    double loanAmount = Double.parseDouble(JOptionPane.showInputDialog(null, amount));
    double interestPaid = 0.0, principalPaid = 0.0, loanBalance = loanAmount;
    DecimalFormat df = new DecimalFormat("$#,###.00");
    boolean done = false;
    double GetmonthlyPayment= 0;
    int GetAmountTerm = 0;
    double Getinterest = 0;
    for(int i = 0; i<3; i++)
    {//beginning loop for display

    monthlyPayment[i] = (loanAmount * ((interest[i]/100)/12)) / (1-1 / Math.pow((1 + (interest[i]/100)/12),AmountTerm[i] * 12));

    while (!done)
    {

    try
    {
    String message = "Select an interest rate:" + "\n\n1) Interest rate of " +interest[0]+ "%\n2) Interest rate of " +interest[1]+ "%\n3) Interest rate of " +interest[2]+ "%\n4) Quit\n";
    input = Integer.parseInt(JOptionPane.showInputDialog(null, message));
    if (input<1 || input>4) throw new NumberFormatException();
    else done = true;
    if(input == 4) finish();

    switch(input)
    {
    case 1: JOptionPane.showMessageDialog(null,"\n\tYou selected option "+ input + ".\n");
    GetmonthlyPayment = monthlyPayment [i];
    Getinterest = interest[i];
    GetAmountTerm = AmountTerm[i];
    JOptionPane.showMessageDialog(null,"\n\tHere is the amoritization for option "+ input + ".\n");
    break;

    case 2: JOptionPane.showMessageDialog(null,"\n\tYou selected option "+ input + ".\n");
    GetmonthlyPayment = monthlyPayment [i];
    Getinterest = interest[i];
    GetAmountTerm = AmountTerm[i];
    JOptionPane.showMessageDialog(null,"\n\tHere is the amoritization for option "+ input + ".\n");
    break;

    case 3: JOptionPane.showMessageDialog(null,"\n\tYou selected option "+ input + ".\n");
    GetmonthlyPayment = monthlyPayment [i];
    Getinterest = interest[i];
    GetAmountTerm = AmountTerm[i];
    JOptionPane.showMessageDialog(null,"\n\tHere is the amoritization for option "+ input + ".\n");
    break;

    }//end of try

    }//end of switch

    catch (NumberFormatException e)
    {
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(null,"Please enter a 1, 2, 3 or 4.", "ERROR", JOptionPane.ERROR_MESSAGE);
    }//end of catch

    }//end loop

    }//end of for loop

    do{
    //pause program after 35 entries are displayed, wait for user to hit enter key.
    if(Add % 10== 0)
    {
    temporaryHold();
    Titles();//reprint header columns for each set of records
    }


    double interestPayment = 0.0;
    double primaryPayment = 0.0;

    primaryPayment = GetmonthlyPayment;
    interestPayment = Getinterest;


    //Calculate interest paid & principal paid
    interestPaid = (loanBalance * (interestPayment/100))/12;
    principalPaid = primaryPayment - interestPaid;



    //Output Values and Mortgage Payment Results
    System.out.println(Add +"\t" + df.format(loanBalance)
    + "\t\t" + df.format(principalPaid)
    + "\t\t" + df.format(interestPaid)+"\n");

    //calculate new loan balance and increment the counter
    loanBalance = loanBalance - principalPaid;
    Add++;

    }while (Add <= loanBalance); //end while statement
    Toolkit.getDefaultToolkit().beep();
    gotomain();//asks user to make a decision

    }//end amoritization



    //declares temporary hold method
    public static void temporaryHold()
    {
    JOptionPane.showMessageDialog(null,"\nHit OK button to see results.");
    }

    public static void gotomain()
    {
    JOptionPane.showConfirmDialog(null,"\nWould you like to return to the main menu? ");
    }

    public static void finish()
    {
    System.exit(0);






    }//end main

    }//end program

  2. #2
    Join Date
    Mar 2006
    Posts
    28
    with this program you could use a JTextArea with JScrollPane

    here's a simple example:
    http://www.leepoint.net/notes-java/G...-textarea.html

Similar Threads

  1. Turning This Program into A JAVA GUI
    By NAN47 in forum Java
    Replies: 2
    Last Post: 04-06-2006, 11:31 PM
  2. Replies: 0
    Last Post: 02-02-2006, 11:53 PM
  3. problem in program in c++
    By mheasen in forum Architecture and Design
    Replies: 0
    Last Post: 03-20-2002, 09:24 AM
  4. Please help with running executable vb program.
    By Gordon Reichhardt in forum VB Classic
    Replies: 2
    Last Post: 01-08-2002, 10:06 AM
  5. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 08:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links