/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * SimpleHypotheekApplet.java * * Created on 22-mei-2009, 15:36:10 */ /** * * * Copyright (c) Wishnu Prasetya, 2009. */ package Hypotheek; import java.awt.Color; import java.awt.Graphics ; import java.awt.Graphics2D ; import java.awt.Stroke ; import java.util.* ; import static Hypotheek.Util.* ; /** * * @author Wishnu Prasetya */ public class SimpleHypotheekApplet extends javax.swing.JApplet { /** Initializes the applet SimpleHypotheekApplet */ public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jPanel4 = new javax.swing.JPanel(); jSeparator8 = new javax.swing.JSeparator(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); jLabel1 = new javax.swing.JLabel(); loan_field = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); duration_field = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); interestRate_field = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); monthlypay_field = new javax.swing.JTextField(); jLabel9 = new javax.swing.JLabel(); jSeparator2 = new javax.swing.JSeparator(); jLabel5 = new javax.swing.JLabel(); salary_field = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); age_field = new javax.swing.JTextField(); jSeparator3 = new javax.swing.JSeparator(); jSeparator4 = new javax.swing.JSeparator(); jLabel12 = new javax.swing.JLabel(); year_to_show_field = new javax.swing.JTextField(); jSeparator5 = new javax.swing.JSeparator(); jSeparator6 = new javax.swing.JSeparator(); jSeparator7 = new javax.swing.JSeparator(); bereken_button = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); housepriceGrowth_field = new javax.swing.JTextField(); jLabel14 = new javax.swing.JLabel(); purchaseOverheadPecentage = new javax.swing.JTextField(); jLabel15 = new javax.swing.JLabel(); premie_levenverz_field = new javax.swing.JTextField(); jTabbedPane2 = new javax.swing.JTabbedPane(); jScrollPane1 = new javax.swing.JScrollPane(); overviewreport_area = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); yearreport_area = new javax.swing.JTextArea(); graph_area = new javax.swing.JPanel(); jPanel4.setBackground(new java.awt.Color(153, 153, 255)); jPanel4.setLayout(new java.awt.GridLayout(4, 0)); jSeparator8.setBackground(new java.awt.Color(153, 153, 255)); jSeparator8.setForeground(new java.awt.Color(153, 153, 255)); jPanel4.add(jSeparator8); jLabel10.setFont(new java.awt.Font("Arial", 1, 18)); jLabel10.setForeground(new java.awt.Color(204, 204, 255)); jLabel10.setText(" Hypotheek X-press-Calculator (2009)"); jPanel4.add(jLabel10); jLabel10.getAccessibleContext().setAccessibleName("Hypotheek X-press-Calculator "); jLabel11.setFont(new java.awt.Font("Arial", 2, 10)); jLabel11.setForeground(new java.awt.Color(153, 204, 255)); jLabel11.setText(" Copyright (c) W. Prasetya, 2009"); jPanel4.add(jLabel11); getContentPane().add(jPanel4, java.awt.BorderLayout.NORTH); jPanel3.setBackground(new java.awt.Color(204, 204, 255)); jPanel3.setFont(new java.awt.Font("Arial", 0, 12)); jPanel3.setMinimumSize(new java.awt.Dimension(800, 400)); jPanel3.setPreferredSize(new java.awt.Dimension(800, 400)); jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS)); jTabbedPane1.setBackground(new java.awt.Color(204, 204, 255)); jTabbedPane1.setFont(new java.awt.Font("Arial", 0, 12)); jTabbedPane1.setMinimumSize(new java.awt.Dimension(300, 400)); jTabbedPane1.setPreferredSize(new java.awt.Dimension(300, 400)); jPanel1.setBackground(new java.awt.Color(204, 204, 255)); jPanel1.setFont(new java.awt.Font("Arial", 0, 12)); jPanel1.setLayout(new java.awt.GridLayout(14, 0)); jLabel7.setFont(new java.awt.Font("Arial", 1, 12)); jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel7.setText(" Leninggegevens:"); jLabel7.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); jPanel1.add(jLabel7); jSeparator1.setBackground(new java.awt.Color(204, 204, 255)); jSeparator1.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator1); jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel1.setText(" Lening (euro)"); jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); jPanel1.add(jLabel1); loan_field.setColumns(8); loan_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); loan_field.setText("100000"); jPanel1.add(loan_field); jLabel6.setFont(new java.awt.Font("Arial", 0, 12)); jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel6.setText(" Leenperiode (jaar)"); jPanel1.add(jLabel6); duration_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); duration_field.setText("30"); jPanel1.add(duration_field); jLabel8.setFont(new java.awt.Font("Arial", 0, 12)); jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel8.setText(" Jaarrente (in %)"); jPanel1.add(jLabel8); interestRate_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); interestRate_field.setText("5.10"); jPanel1.add(interestRate_field); jLabel13.setFont(new java.awt.Font("Arial", 0, 12)); jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel13.setText(" Hypotheekvorm"); jPanel1.add(jLabel13); jComboBox1.setFont(new java.awt.Font("Arial", 0, 12)); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Annuiteitenhypotheek", "Spaarhypotheek" })); jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); jPanel1.add(jComboBox1); jLabel3.setFont(new java.awt.Font("Arial", 0, 12)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel3.setText(" Uw maandelijks betaling "); jLabel3.setToolTipText("Bedrag die u per maand kan/wil betalen (in euro)"); jPanel1.add(jLabel3); monthlypay_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); monthlypay_field.setText("800"); monthlypay_field.setToolTipText("Bedrag die u per maand kan/wil betalen (in euro)"); jPanel1.add(monthlypay_field); jLabel9.setFont(new java.awt.Font("Arial", 1, 12)); jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel9.setText(" Uw gegevens:"); jPanel1.add(jLabel9); jSeparator2.setBackground(new java.awt.Color(204, 204, 255)); jSeparator2.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator2); jLabel5.setFont(new java.awt.Font("Arial", 0, 12)); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel5.setText(" Uw bruto jaarsalaris"); jPanel1.add(jLabel5); salary_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); salary_field.setText("20000"); jPanel1.add(salary_field); jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel2.setText(" Leeftijd (jaar)"); jPanel1.add(jLabel2); age_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); age_field.setText("30"); jPanel1.add(age_field); jSeparator3.setBackground(new java.awt.Color(204, 204, 255)); jSeparator3.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator3); jSeparator4.setBackground(new java.awt.Color(204, 204, 255)); jSeparator4.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator4); jLabel12.setFont(new java.awt.Font("Arial", 0, 12)); jLabel12.setText(" Toon details van jaar:"); jLabel12.setToolTipText("Uw aflossing van dit jaar wordt in details in de \"Jaar details\"-tab aangetoond."); jPanel1.add(jLabel12); year_to_show_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); year_to_show_field.setText("1"); year_to_show_field.setToolTipText("Uw aflossing van dit jaar wordt in details in de \"Jaar details\"-tab aangetoond."); jPanel1.add(year_to_show_field); jSeparator5.setBackground(new java.awt.Color(204, 204, 255)); jSeparator5.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator5); jSeparator6.setBackground(new java.awt.Color(204, 204, 255)); jSeparator6.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator6); jSeparator7.setBackground(new java.awt.Color(204, 204, 255)); jSeparator7.setForeground(new java.awt.Color(204, 204, 255)); jPanel1.add(jSeparator7); bereken_button.setBackground(new java.awt.Color(153, 153, 255)); bereken_button.setFont(new java.awt.Font("Arial", 1, 12)); bereken_button.setText("Bereken"); bereken_button.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); bereken_button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bereken_buttonActionPerformed(evt); } }); jPanel1.add(bereken_button); jTabbedPane1.addTab("Gegevens", jPanel1); jPanel2.setBackground(new java.awt.Color(204, 204, 255)); jPanel2.setFont(new java.awt.Font("Arial", 0, 12)); jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); jLabel4.setText("Verwachte huisprijs groei (in %)"); jLabel4.setToolTipText("Verwachte jaarlijksgroei (in %) van huisprijs. Dit wordt gebruikt in uw winst berekening."); housepriceGrowth_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); housepriceGrowth_field.setText("2.00"); housepriceGrowth_field.setToolTipText("Verwachte jaarlijksgroei (in %) van huisprijs. Dit wordt gebruikt in uw winst berekening."); jLabel14.setFont(new java.awt.Font("Arial", 0, 12)); jLabel14.setText("Bijkomende koopkosten (%)"); jLabel14.setToolTipText("Overdrachtsbelasting, makelaarkosten, enz, die u ook uit de lening laat bekostigen. Rente over deze kosten is niet belastingaftrekbaar."); purchaseOverheadPecentage.setHorizontalAlignment(javax.swing.JTextField.RIGHT); purchaseOverheadPecentage.setText("10"); purchaseOverheadPecentage.setToolTipText("Overdrachtsbelasting, makelaarkosten, enz, die u ook uit de lening laat bekostigen. Rente over deze kosten is niet belastingaftrekbaar."); jLabel15.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel15.setText("Premie levensverz. (eur/maand)"); premie_levenverz_field.setHorizontalAlignment(javax.swing.JTextField.RIGHT); premie_levenverz_field.setText("0"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(16, 16, 16) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(premie_levenverz_field, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(purchaseOverheadPecentage, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(housepriceGrowth_field, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE))) .addGap(67, 67, 67)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(housepriceGrowth_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(purchaseOverheadPecentage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel15) .addComponent(premie_levenverz_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(430, 430, 430)) ); jTabbedPane1.addTab("Meer opties", jPanel2); jPanel3.add(jTabbedPane1); jTabbedPane2.setBackground(new java.awt.Color(204, 204, 255)); jTabbedPane2.setFont(new java.awt.Font("Arial", 0, 12)); jTabbedPane2.setMinimumSize(new java.awt.Dimension(500, 400)); jTabbedPane2.setPreferredSize(new java.awt.Dimension(500, 400)); overviewreport_area.setColumns(20); overviewreport_area.setFont(new java.awt.Font("Monospaced", 0, 12)); overviewreport_area.setForeground(new java.awt.Color(51, 51, 51)); overviewreport_area.setRows(5); jScrollPane1.setViewportView(overviewreport_area); jTabbedPane2.addTab("Rapport", jScrollPane1); jScrollPane2.setBackground(new java.awt.Color(255, 255, 255)); yearreport_area.setColumns(20); yearreport_area.setFont(new java.awt.Font("Monospaced", 0, 12)); yearreport_area.setRows(5); jScrollPane2.setViewportView(yearreport_area); jTabbedPane2.addTab("Jaar details", jScrollPane2); graph_area.setBackground(new java.awt.Color(255, 255, 255)); graph_area.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { graph_areaComponentShown(evt); } }); javax.swing.GroupLayout graph_areaLayout = new javax.swing.GroupLayout(graph_area); graph_area.setLayout(graph_areaLayout); graph_areaLayout.setHorizontalGroup( graph_areaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 544, Short.MAX_VALUE) ); graph_areaLayout.setVerticalGroup( graph_areaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 537, Short.MAX_VALUE) ); jTabbedPane2.addTab("Grafiek", graph_area); jPanel3.add(jTabbedPane2); getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER); }// //GEN-END:initComponents private void bereken_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bereken_buttonActionPerformed int selectedYearToReport ; try { H.setLoan(euro2cent(parse_IntegralInput(loan_field.getText(),"lening",1,div(Hypotheek.MAX_LOAN,100)))) ; H.setDuration(12 * parse_IntegralInput(duration_field.getText(),"leenperiode",1,div(Hypotheek.MAX_LOAN_DURATION,12))) ; H.setMonthlyPayment(euro2cent(parse_IntegralInput(monthlypay_field.getText(),"maandelijks bedrag",1,div(Hypotheek.MAX_LOAN,100)))) ; H.setIncome(euro2cent(parse_IntegralInput(salary_field.getText(),"salaris",1,div(Hypotheek.MAX_LOAN,100)))) ; H.setAge(parse_IntegralInput(age_field.getText(),"leeftijd",0,Hypotheek.MAX_AGE)) ; selectedYearToReport = parse_IntegralInput(year_to_show_field.getText() ,"opgegeven jaar om in details te raporteren",1,div(H.duration,12)) ; float x ; x = parse_Float2DigInput(interestRate_field.getText(),"rente",0f, toFloat(div(Hypotheek.MAX_INTEREST_RATE,100))) ; H.setIterest(toInt(x * 100f)); x = parse_Float2DigInput(housepriceGrowth_field.getText(),"gegeven groei-percentage van huisprijs",0f, toFloat(div(Hypotheek.MAX_INTEREST_RATE,100))) ; H.setAssumedHousePriceIncrRate(toInt(x * 100f)); x = parse_Float2DigInput(purchaseOverheadPecentage.getText(), "percentage van bijkomende koopkosten",0f,100f) ; H.setPurchaseCostPerctage(toInt(x * 100)); H.setLifeInsurancePremium(euro2cent(parse_IntegralInput(premie_levenverz_field.getText(), "premie van levensverzekering",0,Hypotheek.MAX_LOAN) )) ; } catch (NumberFormatException e) { return ; } R = H.calculate() ; String overviewReport = H.printGenStatistics(R) ; overviewreport_area.setForeground(Color.BLACK); overviewreport_area.setText(overviewReport) ; if (R != null) { String yearReport = H.printYearReport(R,selectedYearToReport) ; yearreport_area.setText(yearReport); } plotGraph() ; }//GEN-LAST:event_bereken_buttonActionPerformed private void graph_areaComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_graph_areaComponentShown repaint() ; }//GEN-LAST:event_graph_areaComponentShown private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed String selected_hypform = (String) ((javax.swing.JComboBox)evt.getSource()).getSelectedItem() ; if (selected_hypform.equals("Spaarhypotheek")) H.switchToPureSpaarHypotheek(); if (selected_hypform.equals("Annuiteitenhypotheek")) H.setPercentageToSave(0); }//GEN-LAST:event_jComboBox1ActionPerformed Hypotheek.Result R = null ; Hypotheek H = new Hypotheek() ; private int parse_IntegralInput(String input, String msg, int minval, int maxval ) throws NumberFormatException { int x ; try { x = parseInt(input,minval,maxval) ; } catch (NumberFormatException e) { overviewreport_area.setForeground(Color.RED); overviewreport_area.setText("** FOUT in uw invoer: uw " + msg + " moet een geheel getal (zonder punt of comma) tussen " + minval + " en " + maxval + " zijn.") ; throw e ; } return x ; } // parsing float, with rounded to 2 digits behind the comma private float parse_Float2DigInput(String input, String msg, float minval, float maxval ) throws NumberFormatException { float x ; try { x = parseFloat(input,minval,maxval) ; } catch (NumberFormatException e) { overviewreport_area.setForeground(Color.RED); overviewreport_area.setText("** FOUT in uw invoer: uw " + msg + " moet een getal tussen " + minval + " en " + maxval + " zijn.") ; throw e ; } return x ; } public void paint(Graphics g) { super.paint(g) ; plotGraph() ; } static int GRAPH_WIDTH = 400 ; static int GRAPH_HEIGHT = 200 ; static int TOP_MARGIN = 50 ; static int LEFT_MARGIN = 80 ; static int SEP = 8 ; private void plotGraph() { if (! graph_area.isShowing()) return ; Graphics2D g = (Graphics2D) graph_area.getGraphics() ; g.clearRect(0,0,graph_area.getWidth(),graph_area.getHeight()); if (R == null) return ; List cummulativeLoanPaid = H.calcYearlyCummulativeProgressOfLoanPaid(R) ; List cummulativeSaving = H.calcYearlyCummulativeProgressOfSaving(R) ; List cummulativeTaxReduction = H.calcYearlyCummulativeProgressOfTaxReduction(R) ; //System.out.println(">>>" + cummulativeLoanPaid + " size " + cummulativeLoanPaid.size()) ; //System.out.println(">>>" + cummulativeSaving + " size " + cummulativeSaving.size()) ; assert cummulativeLoanPaid.size() == cummulativeSaving.size() ; assert cummulativeLoanPaid.size() == cummulativeTaxReduction.size() ; int N = cummulativeLoanPaid.size() ; int loan = H.loan ; List line1 = new LinkedList() ; for (int i=0; i line2 = new LinkedList() ; for (int tr : cummulativeTaxReduction) { Float val = toFloat(tr) / toFloat(loan) ; line2.add(val) ; } List line3 = new LinkedList() ; float growth = 1f + toFloat(H.assumedHousePriceIncrRate) / 10000f ; for (int m=0; m