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 14 of 14

Thread: GUI's

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GUI's

    Hi I am hoping to get some help here because I am completely lost. I am using netbeans and have to come up with this: Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. I have ben reading to try and figure this out. I get results in my run window like normal but I dont get any results in the GUI.

    package ChngReq4Pkg;
    import java.text.DecimalFormat;


    /**
    *
    * @author
    */
    public class ChangeRequest4 extends javax.swing.JFrame {

    /**
    * Creates new form ChangeRequest4
    */
    public ChangeRequest4() {
    initComponents();

    }

    /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    calculate = new javax.swing.JButton();
    loanCalculation = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jTextField1 = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    setTitle("Loan Calculator");

    calculate.setText("Calculate");
    calculate.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    calculateActionPerformed(evt);
    }
    });

    loanCalculation.setText("Loan");

    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);

    jTextField1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jTextField1ActionPerformed(evt);
    }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jScrollPane1))
    .addGroup(layout.createSequentialGroup()
    .addGap(185, 185, 185)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(calculate)
    .addGroup(layout.createSequentialGroup()
    .addComponent(loanCalculation)
    .addGap(18, 18, 18)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGap(0, 212, Short.MAX_VALUE)))
    .addContainerGap())
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(19, 19, 19)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(loanCalculation)
    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(19, 19, 19)
    .addComponent(calculate, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(18, 18, 18)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
    .addGap(51, 51, 51))
    );

    pack();
    }// </editor-fold>

    private void calculateActionPerformed(java.awt.event.ActionEven t evt) {

    }

    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }


    public static void main(String args[]) {
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 / 12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));
    DecimalFormat decimalPlaces=new DecimalFormat("0.00");//Rounds up the dollar amount

    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println("The Monthly Payment is $" + decimalPlaces.format(monthlyPayment));

    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
    * If Nimbus (introduced in Java SE 6) is not available, stay with the
    * default look and feel. For details see
    * How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClass Name());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(ChangeRequest4. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(ChangeRequest4. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(ChangeRequest4. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(ChangeRequest4. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
    }
    //</editor-fold>

    /*
    * Create and display the form
    */
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new ChangeRequest4().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton calculate;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JLabel loanCalculation;
    // End of variables declaration
    }


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: GUI's

    Okay.

    Highlight your code and ask a specific question.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    /**
    *
    * @author
    */
    public class ChangeRequest4 extends javax.swing.JFrame {

    /**
    * Creates new form ChangeRequest4
    */
    public ChangeRequest4() {
    initComponents();

    }
    private void calculateActionPerformed(java.awt.event.ActionEven t evt) {

    }
    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }


    public static void main(String args[]) {
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years


    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 / 12;
    double loanLengthInMonths = loanLengthInYears * 12;

    double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));
    DecimalFormat decimalPlaces=new DecimalFormat("0.00");//Rounds up the dollar amount

    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println("The Monthly Payment is $" + decimalPlaces.format(monthlyPayment));

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI's

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    public class ChangeRequest4 extends javax.swing.JFrame {
     
     
    public ChangeRequest4() {
    initComponents();
     
    }
    private void calculateActionPerformed(java.awt.event.ActionEven t evt) {
     
    }
    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {
     
    }
     
     
    public static void main(String args[]) {
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years
     
     
    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 / 12;
    double loanLengthInMonths = loanLengthInYears * 12;
     
    double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));
    DecimalFormat decimalPlaces=new DecimalFormat("0.00");//Rounds up the dollar amount
     
    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println("The Monthly Payment is $" + decimalPlaces.format(monthlyPayment));

  6. #6
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    public class ChangeRequest4 extends javax.swing.JFrame {
     
     
    public ChangeRequest4() {
    initComponents();
     
    }
    private void calculateActionPerformed(java.awt.event.ActionEvent evt) {
     
    }
    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
     
    }
     
     
    public static void main(String args[]) {
    double annualInterest = 5.75; //This is the annual interest rate
    double loanAmount = 200000; //This is the loan amount
    double loanLengthInYears = 30; //This is the length of the loan in years
     
     
    //Formuals bieng used are:
    double monthlyInterest = annualInterest / 100 / 12;
    double loanLengthInMonths = loanLengthInYears * 12;
     
    double monthlyPayment = (loanAmount * monthlyInterest) * (1 + Math.pow((1 - monthlyInterest), loanLengthInYears));
    DecimalFormat decimalPlaces=new DecimalFormat("0.00");//Rounds up the dollar amount
     
    System.out.println("MortgageCalculator");
    System.out.println("Annual Interest: 5.75%");
    System.out.println("Loan Amount: $200,000");
    System.out.println("Loan Length: 30 years");
    System.out.println("The Monthly Payment is $" + decimalPlaces.format(monthlyPayment));
    Last edited by kprofgold; February 10th, 2012 at 08:03 PM. Reason: incorrect spacing

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI's

    What is your purpose for posting that code fragment?

  8. #8
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    honestly Im not sure...Im really confused and just copied everything from my netbeans and pasted it.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI's

    There is a lot of code missing.
    Specifically there is no ending }
    Compared to your first post, a lot of code is missing.

  10. #10
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    Thats what Im trying to figure out. I can get results just by running the code in netbeans but in the GUI I cant get it. I have created the GUI jLabel and textfield but cannot figure out how to get those results to display when I hit the jButton.

  11. #11
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    Oh sorry there is a } to end it but it was lower in the code and I didnt copy it

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI's

    You need to post all of the code that you want help with. Just part of it won't do.

  13. #13
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GUI's

    Sorry, like I said I am really confused and dont know how to code it. Ive had one 3 hour class on this and no programming exp before this. This is all the code I have. From my reading material I think I have to create code within these 2 sections:

    private void calculateActionPerformed(java.awt.event.ActionEven t evt) {
    }
    private void jTextField1ActionPerformed(java.awt.event.ActionEv ent evt) {
    // TODO add your handling code here:
    }

    But I have no clue what to do next. I of course know you probably wont just give me code but please help me with examples or something to show me how to figure the code out.... Also the jButton has been renamed to calculate.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI's

    Your problem with getting the code and posting it is with the editor part of your IDE.
    I have no idea how to use your IDE.

    Your use of the GUI creating part of the IDE is another barrier. I don't use your IDE and can not work with the code generated by it. I definitely would not recommend a beginner use the GUI generated by the IDE.

Similar Threads

  1. Noob at GUI's, need layout help.
    By tyb97 in forum AWT / Java Swing
    Replies: 6
    Last Post: November 2nd, 2011, 03:50 PM