Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to add buttons on this code

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to add buttons on this code

    I am stuck with adding reset and exit buttons to this. Here is my code.
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
    public class MortgageCalculatorGUI///Name of my File and Class
    {
    public static void main(String[] args)
    {
    double loanAmount;//Declaring my Variables
    double loanInterest;//Declaring my Variables
    double monthlyPayment;//Declaring my Variables
    double interestRate;
    int loanTerm;
    String totalLoan, interestLoan, termLoan;
    DecimalFormat decimalPlaces=new DecimalFormat("0.00"); //Format decimal point for proper display
     
    totalLoan=JOptionPane.showInputDialog(null, "Enter the Loan Amount: ");
    loanAmount = Double.parseDouble(totalLoan);
     
    interestLoan=JOptionPane.showInputDialog(null, "Enter the Interest Rate of the Loan in decimal Form: ");
    loanInterest = Double.parseDouble(interestLoan)/12;
     
    termLoan=JOptionPane.showInputDialog(null, "Enter the Term of the Loan: ");
    loanTerm = Integer.parseInt(termLoan)*12;
     
     
    // calculations
    monthlyPayment = loanAmount *(loanInterest/(1 - Math.pow(1 + loanInterest, -loanTerm)));//Formula for Monthly Payments
     
    JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" + decimalPlaces.format(monthlyPayment));
    System.exit(0);}}.

    Can anyone help? It's for my homework assignment due Monday.
    Last edited by copeg; April 17th, 2011 at 11:09 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,273
    Thanks
    177
    Thanked 822 Times in 765 Posts
    Blog Entries
    5

    Default Re: How to add buttons on this code

    For future reference, please use the code tags. I don't know exactly what the question is....I suggest you read the following: How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to add buttons on this code

    I am sorry for not giving more of an explanation of what I asking. Within the JOptionpane container how do you add buttons?

    here is my code
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
    public class MortgageCalculatorGUI///Name of my File and Class
    {
    public static void main(String[] args)
    {
    double loanAmount;//Declaring my Variables
    double loanInterest;//Declaring my Variables
    double monthlyPayment;//Declaring my Variables
    double interestRate;
    int loanTerm;
    String totalLoan, interestLoan, termLoan;
    DecimalFormat decimalPlaces=new DecimalFormat("0.00"); //Format decimal point for proper display
     
    totalLoan=JOptionPane.showInputDialog(null, "Enter the Loan Amount: ");
    loanAmount = Double.parseDouble(totalLoan);
     
    interestLoan=JOptionPane.showInputDialog(null, "Enter the Interest Rate of the Loan in decimal Form: ");
    loanInterest = Double.parseDouble(interestLoan)/12;
     
    termLoan=JOptionPane.showInputDialog(null, "Enter the Term of the Loan: ");
    loanTerm = Integer.parseInt(termLoan)*12;
     
     
    // calculations
    monthlyPayment = loanAmount *(loanInterest/(1 - Math.pow(1 + loanInterest, -loanTerm)));//Formula for Monthly Payments
     
    JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" + decimalPlaces.format(monthlyPayment));

  4. #4
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: How to add buttons on this code

    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
     
    public class MortgageCalculatorGUI///Name of my File and Class
    {
    	public static void main(String[] args){
    		double loanAmount;//Declaring my Variables
    		double loanInterest;//Declaring my Variables
    		double monthlyPayment;//Declaring my Variables
    		double interestRate;
    		int loanTerm;
    		String totalLoan, interestLoan, termLoan;
    		DecimalFormat decimalPlaces=new DecimalFormat("0.00"); //Format decimal point for proper display
     
    		totalLoan=JOptionPane.showInputDialog(null, "Enter the Loan Amount: ");
    		loanAmount = Double.parseDouble(totalLoan);
     
    		interestLoan=JOptionPane.showInputDialog(null, "Enter the Interest Rate of the Loan in decimal Form: ");
    		loanInterest = Double.parseDouble(interestLoan)/12;
     
    		termLoan=JOptionPane.showInputDialog(null, "Enter the Term of the Loan: ");
    		loanTerm = Integer.parseInt(termLoan)*12;
     
     
    		// calculations
    		monthlyPayment = loanAmount *(loanInterest/(1 - Math.pow(1 + loanInterest, -loanTerm)));//Formula for Monthly Payments
     
    		JOptionPane.showMessageDialog(null,"Your Monthly Payments Are" + decimalPlaces.format(monthlyPayment));
    	}
    }
    Last edited by DanBrown; April 18th, 2011 at 04:16 AM.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  5. #5
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: How to add buttons on this code

    Where you want to add button my dear?
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  6. #6
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: How to add buttons on this code

    JOptionPane from Java 6 API I'd suggests the last example, and taking a look at the option parameters in the constructors.

Similar Threads

  1. [SOLVED] Buttons not working..
    By khms in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 2nd, 2010, 06:01 PM
  2. Create buttons at runtime
    By rtumatt in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 06:42 AM
  3. create buttons in a JEditorPane
    By seeker in forum AWT / Java Swing
    Replies: 4
    Last Post: December 5th, 2009, 08:01 AM
  4. JRadio buttons
    By chronoz13 in forum AWT / Java Swing
    Replies: 0
    Last Post: November 29th, 2009, 12:08 AM
  5. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM