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

Thread: Strange boxes appearing

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Strange boxes appearing

    Please help! I have a program that ammortizes a loan. When I click on calulate the first time it produces these strange little boxes where my interest, payment, and balance should be. Please, any help would be appreciated! Thanks.
     
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    import java.awt.event.*;
    import java.lang.String.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    public class WeekThreeCalc extends javax.swing.JFrame {
     
     
        double amount = 0;
        double[] iRate = {.0535, .055, .0575};
        double iRate1 = iRate [2];
        double[] years = {7, 15, 30};
        double interest = 0.0;
        double term = years [2];
        double tMonths = 0.0;
        double mPayment1;
        double balance = 0;
        double mRatePaid = 0.00;
        double mPrinciple = 0.00;
        int months = 0;
        double mRate = 0;
        DecimalFormat ePay = new DecimalFormat ("$###,##0.00");;
        NumberFormat currency = 
                NumberFormat.getCurrencyInstance();
     
        public WeekThreeCalc() {
            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() {
     
            lAmountLabel = new javax.swing.JLabel();
            termIntLabel = new javax.swing.JLabel();
            mPaymentLabel = new javax.swing.JLabel();
            termInt = new javax.swing.JComboBox();
            lAmount = new javax.swing.JTextField();
            mPayment = new javax.swing.JTextField();
            results = new java.awt.ScrollPane();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            exitButton = new javax.swing.JButton();
            calcButton = new javax.swing.JButton();
            clearButton = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            lAmountLabel.setText("Loan Amount");
     
            termIntLabel.setText("Term/Interest");
     
            mPaymentLabel.setText("Monthly Payment");
     
            termInt.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Loan Term and Interest", "7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%" }));
     
            mPayment.setEditable(false);
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
     
            results.add(jScrollPane1);
     
            exitButton.setText("Exit");
            exitButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    exitButtonActionPerformed(evt);
                }
            });
     
            calcButton.setText("Calculate!");
            calcButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calcButtonActionPerformed(evt);
                }
            });
     
            clearButton.setText("Clear");
            clearButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearButtonActionPerformed(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.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(22, 22, 22)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lAmountLabel)
                                .addComponent(lAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(69, 69, 69)
                                    .addComponent(termIntLabel))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(termInt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(40, 40, 40)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(mPayment, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(mPaymentLabel)))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(48, 48, 48)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(exitButton)
                                    .addGap(54, 54, 54)
                                    .addComponent(calcButton)
                                    .addGap(87, 87, 87)
                                    .addComponent(clearButton))
                                .addComponent(results, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(24, 24, 24)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lAmountLabel)
                        .addComponent(termIntLabel)
                        .addComponent(mPaymentLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(termInt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(mPayment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(124, 124, 124)
                    .addComponent(results, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(clearButton)
                        .addComponent(calcButton)
                        .addComponent(exitButton))
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>
     
        private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
           System.exit(0);
        }
     
        private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {
            lAmount.setText("");
            mPayment.setText("");
            jTextArea1.setText("");
        }
     
        private void calcButtonActionPerformed(java.awt.event.ActionEvent evt) {
           Integer termInt1;
           termInt1 = termInt.getSelectedIndex();
           if (termInt1 == 0)
           { 
     
           }
           if (termInt1 == 1)
           {
               interest = iRate [0];
               term = years [0];
           }
           if (termInt1 == 2)
           {
               interest = iRate [1];
               term = years [1];
           }
           if (termInt1 == 3)
           {
               interest = iRate [2];
               term = years [2];
           }
           double monthRate = iRate1 /12;
     
    		 mPayment1 = amount *(monthRate / (1-Math.pow(1 + monthRate, -tMonths)));
           amount = Double.parseDouble(lAmount.getText());
           mPayment.setText(currency.format(mPayment1) + "   ");
           repaint();
           tMonths = term * 12;
           balance = amount;
     
     
           for (months = 1; months <= tMonths; months++)
           {
          mRate = iRate1 /12;
          mRatePaid = balance * mRate;
          mPrinciple = mPayment1 - mRatePaid;
          balance = balance - mPrinciple;
          jTextArea1.append("   "+ months + "\t\t    " + ePay.format(mPayment1) +"\t\t" + ePay.format(mRatePaid) + "\t\t" + ePay.format (balance) + "\n");
           }
        }
     
    		  /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /*
             * Set the Nimbus look and feel
             */
            //<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
             * [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Javaô Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(WeekThreeCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(WeekThreeCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(WeekThreeCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(WeekThreeCalc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /*
             * Create and display the form
             */
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
                    new WeekThreeCalc().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton calcButton;
        private javax.swing.JButton clearButton;
        private javax.swing.JButton exitButton;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField lAmount;
        private javax.swing.JLabel lAmountLabel;
        private javax.swing.JTextField mPayment;
        private javax.swing.JLabel mPaymentLabel;
        private java.awt.ScrollPane results;
        private javax.swing.JComboBox termInt;
        private javax.swing.JLabel termIntLabel;
        // End of variables declaration
    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Strange boxes appearing

    these strange little boxes
    You should copy-paste that output, or it might be more helpful to you to use System.out.println to print the same string to you console. It could be that it's presented differently there, and might give you the clue you need to work out what's going wrong.

Similar Threads

  1. Problem with Bearing calculation appearing as NaN
    By welshcrossy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 23rd, 2012, 10:23 AM
  2. Replies: 1
    Last Post: August 15th, 2011, 09:26 AM
  3. Renaming labels & text boxes
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 17th, 2011, 02:11 PM
  4. Swing Dialog Boxes --- Have no clue why its not working
    By jap2008 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 18th, 2010, 03:20 PM
  5. how to write an if statement which evaluates 3 dialogue boxes
    By humdinger in forum Loops & Control Statements
    Replies: 6
    Last Post: January 14th, 2010, 12:28 PM