Results 1 to 4 of 4

Thread: JOptionPane

  1. #1
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default JOptionPane

    How would i makea Jopt confirm to either continue with the following portions of the program, or restart at the top of the program??

    Java Code:
    JOptionPane.showConfirmDialog(null, "Would you like to see the amortization of the current loan?");
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.Question_MESSAGE,
        null, continue
    This is all i have got so far, but i dont know how to control it.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Have you read the API documentation for that class? The showXXXDialog( ... ) methods return an int indicating which button was clicked; you have to take it from there.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    Ok so i changed some stuff around on this... I want to confirmdialog to ask the user to either continue the program and go threw the loop, or enter another loan amount, or exit... This is what i got so far but its wrong. I cant seem to find much about this online.

    Java Code:
    import javax.swing.*;
    
    
    public class MortgageApp3 {
    	public static void main(String args[])
    		{
    
    
    		double loan,
    		 interest_yr,
    		 years,
    		 interest_mo,
    		 loan_pmts,
    		 payments,
    		 new_balance,
    		 interest,
    		 interestamt,
    		 principal,
    		 principalamt,
    		 payamt,
    		 balance;
    
    	     int p;
    
            //Above is all the varaibles used for calculations
    
    
    
    
            String loanamt,
    		  interest_peryr,
    	      yearstot,
    	      pay_amt;
    	    //The above declares the strings for the program
    
    
    
    
    	 loanamt= JOptionPane.showInputDialog("Enter Loan Amount");    //Obtains input from user for loan amount
    	 interest_peryr=JOptionPane.showInputDialog("Enter the Interest Percentage: Example 5.6");  //Obtains input from user for interest %
    	 yearstot=JOptionPane.showInputDialog("Enter Loan Period in Years");  //Obtains input for length of loan
    
    
    
    
         // Below is the code to parse stings into doubles
    	 loan=Double.parseDouble(loanamt);
    	 interest_yr=Double.parseDouble(interest_peryr);
    	 years=Double.parseDouble(yearstot);
    
    
    
    
         interest_mo = (interest_yr/12.0)/100.0; // Turns percent whole numbers into decimals
    
         loan_pmts= years * 12;  //Gets total amount of months the loan will last after user inputs length of loan in years
    
         payments = (loan*interest_mo/(1- Math.pow((1+interest_mo),-loan_pmts))); //Loan calculation
    
    
    	 JOptionPane.showMessageDialog (null, String.format( "Your payment is: $ %.2f ", + payments)); //Shows payment with 2 decimal places
    
    
         principalamt= payments - (loan *interest_mo);  //calculates principle
    
         JOptionPane.showMessageDialog(null, String.format( "your prinicple paid is: $ %.2f ", + principalamt)); //shows principle with 2 decimal places
    
         interestamt= payments-principalamt ;  //calculates interest
    
         JOptionPane.showMessageDialog(null, String.format( "your interest paid is: $ %.2f ", + interestamt)); //shows interest with 2 decimal places
    
    
        Object[] options= {"Show Amortization","Enter Another Laon","Exit Program"};
         }
        JOptionPane.showConfirmDialog(null, "Would you like to see the amortization of the current loan?");
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.Question_MESSAGE;
    
        if(response==yes)
        {continue;
        }else{
           loanamt=JOptionPane.showInputDialog;
        }
    
    
    
    
    
    
    
    
    
    
    //below is the loop
       p=1;
      balance=loan;
      //payment=1
      for(int month=0;month<(years*12);month++)
    
      {
      	interest=balance*interest_mo;
      //System.out.println("interest "+interest);
    
      principal=payments-interest;
      //System.out.println("principal "+ principal);
    
      System.out.println("For Payment: " +p++ );
      System.out.println( String.format("Principal paid is: $ %.2f",  + principal));
    
      balance=balance-principal;
      System.out.println( String.format("Remaining balance is: $ %.2f",
        + balance));
    
    
     }
    
    
    
    
    
    
    
    
      System.exit(0);
    
    
      }
    
    }

  4. #4
    louiedogg418 is offline Member
    Join Date
    Jun 2011
    Posts
    52
    Rep Power
    0

    Default

    getClass().getName() + '@' + Integer.toHexString(hashCode())??

    how does this work? is this what i am looking for in order to pull up loanamt string?

Similar Threads

  1. JOptionPane
    By thorobred in forum Eclipse
    Replies: 4
    Last Post: 04-19-2011, 05:15 AM
  2. JOptionPane
    By izzy in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 05:55 PM
  3. Help with JOptionPane
    By sanctishit in forum New To Java
    Replies: 1
    Last Post: 03-10-2010, 11:20 AM
  4. JOptionpane
    By tommyyyy in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 09:33 AM
  5. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 03:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •