DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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

    Turning This Program into A JAVA GUI

    Can someone please show me how to turn my program into a GUI? I have the JOption Dialogs down, however I would like to implement my program as a GUI. Please help. Thanks.

    Here is my program :
    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

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    dont cross post plz

Similar Threads

  1. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  2. Informix and Java GUI
    By Anna in forum Database
    Replies: 1
    Last Post: 01-23-2003, 12:41 PM
  3. I need someone to write a java program for me!
    By Dan in forum java.announcements
    Replies: 1
    Last Post: 01-15-2002, 04:55 PM
  4. operating system program in java
    By bina in forum Java
    Replies: 2
    Last Post: 09-18-2001, 11:52 AM
  5. clearin the screen from a java program
    By arun chakravarty in forum Java
    Replies: 1
    Last Post: 12-01-2000, 10:59 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