import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.applet.Applet; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.GridBagConstraints; import java.awt.Label; import java.awt.Font; import java.awt.Button; public class Calculator1 extends java.applet.Applet { int flagPoint = 0; String pv0 = ""; String pv1 = "0"; String i0 = ""; String i1 = "0"; String n0 = ""; String n1 = "0"; protected Label label1 ; protected Button button1 ; protected Button button2 ; protected Button button3 ; protected Button button4 ; protected Button button5 ; protected Button button6 ; protected Button button7 ; protected Button button8 ; protected Button button9 ; protected Button button10 ; protected Button button11 ; protected Button button12 ; protected Button button13 ; protected Button button14 ; protected Button button15 ; protected Button button16 ; protected Button button17 ; protected Button button18 ; protected Label label2 ; protected Button button19 ; // Method# 1 public Calculator1() { // this.setLayout( new java.awt.GridBagLayout() ); this.setBackground( new java.awt.Color(192,192,192) ); this.setCursor( java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR) ); this.setSize( new java.awt.Dimension(400,400) ); label1 = new Label(); label1.setText( "" ); label1.setAlignment( java.awt.Label.CENTER ); label1.setForeground( new java.awt.Color(0,255,0) ); label1.setBackground( new java.awt.Color(0,0,0) ); label1.setFont( new java.awt.Font("Dialog", 0, 16) ); button1 = new Button(); button1.setLabel( "1" ); button1.setForeground( new java.awt.Color(255,255,255) ); button1.setBackground( new java.awt.Color(128,128,128) ); button2 = new Button(); button2.setLabel( " 2 " ); button2.setForeground( new java.awt.Color(255,255,255) ); button2.setBackground( new java.awt.Color(128,128,128) ); button3 = new Button(); button3.setLabel( " 3 " ); button3.setForeground( new java.awt.Color(255,255,255) ); button3.setBackground( new java.awt.Color(128,128,128) ); button4 = new Button(); button4.setLabel( "4" ); button4.setForeground( new java.awt.Color(255,255,255) ); button4.setBackground( new java.awt.Color(128,128,128) ); button5 = new Button(); button5.setLabel( " 5 " ); button5.setForeground( new java.awt.Color(255,255,255) ); button5.setBackground( new java.awt.Color(128,128,128) ); button6 = new Button(); button6.setLabel( " 6 " ); button6.setForeground( new java.awt.Color(255,255,255) ); button6.setBackground( new java.awt.Color(128,128,128) ); button7 = new Button(); button7.setLabel( "7" ); button7.setForeground( new java.awt.Color(255,255,255) ); button7.setBackground( new java.awt.Color(128,128,128) ); button8 = new Button(); button8.setLabel( " 8 " ); button8.setForeground( new java.awt.Color(255,255,255) ); button8.setBackground( new java.awt.Color(128,128,128) ); button9 = new Button(); button9.setLabel( " 9 " ); button9.setForeground( new java.awt.Color(255,255,255) ); button9.setBackground( new java.awt.Color(128,128,128) ); button10 = new Button(); button10.setLabel( "0" ); button10.setForeground( new java.awt.Color(255,255,255) ); button10.setBackground( new java.awt.Color(128,128,128) ); button11 = new Button(); button11.setLabel( " . " ); button11.setForeground( new java.awt.Color(255,255,255) ); button11.setBackground( new java.awt.Color(128,128,128) ); button12 = new Button(); button12.setLabel( " C " ); button12.setForeground( new java.awt.Color(255,0,0) ); button12.setBackground( new java.awt.Color(128,128,128) ); button13 = new Button(); button13.setLabel( "n" ); button13.setForeground( new java.awt.Color(255,255,255) ); button13.setBackground( new java.awt.Color(128,128,128) ); button14 = new Button(); button14.setLabel( "i%" ); button14.setForeground( new java.awt.Color(255,255,255) ); button14.setBackground( new java.awt.Color(128,128,128) ); button15 = new Button(); button15.setLabel( "pv" ); button15.setForeground( new java.awt.Color(255,255,255) ); button15.setBackground( new java.awt.Color(128,128,128) ); button16 = new Button(); button16.setLabel( "comp pmt" ); button16.setForeground( new java.awt.Color(255,0,0) ); button16.setBackground( new java.awt.Color(128,128,128) ); button17 = new Button(); button17.setLabel( "clear all" ); button17.setForeground( new java.awt.Color(255,0,0) ); button17.setBackground( new java.awt.Color(128,128,128) ); button18 = new Button(); button18.setLabel( "credits" ); button18.setForeground( new java.awt.Color(0,0,255) ); button18.setBackground( new java.awt.Color(128,128,128) ); label2 = new Label(); label2.setText( "THE MORTGAGE CALCULATOR" ); label2.setAlignment( java.awt.Label.CENTER ); label2.setForeground( new java.awt.Color(0,255,255) ); label2.setBackground( new java.awt.Color(0,0,0) ); label2.setFont( new java.awt.Font("Dialog", 0, 14) ); button19 = new Button(); button19.setLabel( " help " ); button19.setForeground( new java.awt.Color(0,255,255) ); button19.setBackground( new java.awt.Color(128,128,128) ); { GridBagConstraints grid = new GridBagConstraints(); grid.fill = GridBagConstraints.HORIZONTAL; grid.gridwidth = 4; grid.gridx = GridBagConstraints.REMAINDER; grid.gridy = GridBagConstraints.REMAINDER; grid.ipady = 35; this.add(label1, grid, -1); grid.gridy = 1; this.add(label2, grid, -1); grid.gridwidth = 1; grid.gridy = 2; grid.ipadx = 35; grid.ipady = 30; this.add(button1, grid, -1); grid.gridx = 1; this.add(button2, grid, -1); grid.gridx = 2; this.add(button3, grid, -1); grid.gridx = GridBagConstraints.REMAINDER; grid.gridy = 3; this.add(button4, grid, -1); grid.gridx = 1; this.add(button5, grid, -1); grid.gridx = 2; this.add(button6, grid, -1); grid.gridx = GridBagConstraints.REMAINDER; grid.gridy = 4; this.add(button7, grid, -1); grid.gridx = 1; this.add(button8, grid, -1); grid.gridx = 2; this.add(button9, grid, -1); grid.gridx = GridBagConstraints.REMAINDER; grid.gridy = 5; this.add(button10, grid, -1); grid.gridx = 1; this.add(button11, grid, -1); grid.gridx = 2; this.add(button12, grid, -1); grid.gridx = GridBagConstraints.REMAINDER; grid.gridy = 6; this.add(button18, grid, -1); grid.gridx = 1; this.add(button19, grid, -1); grid.gridwidth = 2; grid.gridx = 2; grid.ipadx = 70; this.add(button17, grid, -1); grid.gridwidth = 1; grid.gridx = 3; grid.gridy = 2; grid.ipadx = 35; this.add(button15, grid, -1); grid.gridy = 3; this.add(button14, grid, -1); grid.gridy = 4; this.add(button13, grid, -1); grid.gridy = 5; this.add(button16, grid, -1); } // // class MouseListenerAdapter implements MouseListener { public void mouseClicked( MouseEvent e ) { String nada = ""; String point = "."; String zero1 = "0"; String zero2; String current1; float pvdot1; // dot=float Float pvdotF1; float idot1; Float idotF1; float idot2; float ndot1; Float ndotF1; float stat = 0; int nShalem = 0; float maanas = 0; float pmtdot1; int j; if ( e.getSource().equals( button11 ) ) { if ( flagPoint == 0 ) { current1 = label1.getText(); label1.setText(current1+"."); flagPoint = 1; return; } return; } if ( e.getSource().equals( button10 ) ) { zero2 = label1.getText(); if ( zero2.equals( zero1 ) ) { return; } else { current1 = label1.getText(); label1.setText(current1+"0"); return; } } if ( e.getSource().equals( button9 ) ) { current1 = label1.getText(); label1.setText(current1+"9"); return; } if ( e.getSource().equals( button8 ) ) { current1 = label1.getText(); label1.setText(current1+"8"); return; } if ( e.getSource().equals( button7 ) ) { current1 = label1.getText(); label1.setText(current1+"7"); return; } if ( e.getSource().equals( button6 ) ) { current1 = label1.getText(); label1.setText(current1+"6" ); return; } if ( e.getSource().equals( button5 ) ) { current1 = label1.getText(); label1.setText(current1+"5"); return; } if ( e.getSource().equals( button4 ) ) { current1 = label1.getText(); label1.setText(current1+"4"); return; } if ( e.getSource().equals( button3 ) ) { current1 = label1.getText(); label1.setText(current1+"3"); return; } if ( e.getSource().equals( button2 ) ) { current1 = label1.getText(); label1.setText(current1+"2"); return; } if ( e.getSource().equals( button1 ) ) { current1 = label1.getText(); label1.setText(current1+"1"); return; } if ( e.getSource().equals( button19 ) ) { label2.setText( "INSERT: p.v , i , n THEN PRESS:comp pmt" ); return; } if ( e.getSource().equals( button18 ) ) { label2.setText( "Meny Yotam - The college of Management" ); return; } if ( e.getSource().equals( button17 ) ) { label2.setText( "please insert new data" ); pv1 = "0"; i1 = "0"; n1 = "0"; label1.setText( "" ); flagPoint = 0; return; } if ( e.getSource().equals( button16 ) ) { pvdotF1 = Float.valueOf(pv1); idotF1 = Float.valueOf(i1); ndotF1 = Float.valueOf(n1); // pvdot1=Float.floatValue(pvdotF1); // idot1=Float.floatValue(idotF1); // ndot1=Float.floatValue(ndotF1); pvdot1 = pvdotF1.floatValue(); // idot1 = idotF1.floatValue(); // // ndot1=ndotF1.floatValue(); nShalem = ndotF1.intValue(); if ( nShalem == 0 ) { label2.setText( "n must be 1 or higher" ); n1 = "0"; label1.setText( "" ); flagPoint = 0; return; } idot2 = (1+idot1/100); stat = idot2; for (j = 1;j < nShalem;j++) { idot2*= stat; } maanas = (1-(1/idot2))/(idot1/100); pmtdot1 = pvdot1/maanas; label1.setText( "" ); label2.setText( "pv="+pv1+" i="+i1+"% n="+nShalem+" pmt is:"+pmtdot1 ); flagPoint = 0; return; } if ( e.getSource().equals( button15 ) ) { pv0 = label1.getText(); if ( pv0.equals( nada ) || pv0.equals( point ) || pv0.equals ( zero1 )) { label2.setText( "insert value to p.v." ); flagPoint = 0; label1.setText( "" ); return; } else { pv1 = label1.getText(); label2.setText( "pv="+pv1); flagPoint = 0; label1.setText( "" ); return; } } if ( e.getSource().equals( button14 ) ) { i0 = label1.getText(); if ( i0.equals( nada ) || i0.equals( point ) || i0.equals ( zero1 )) { label2.setText( "insert value to i%" ); flagPoint = 0; label1.setText( "" ); return; } else { i1 = label1.getText(); label2.setText( "i="+i1); label1.setText( "" ); flagPoint = 0; return; } } if ( e.getSource().equals( button13 ) ) { n0 = label1.getText(); if ( n0.equals( nada ) || n0.equals( point ) || n0.equals ( zero1 )) { label2.setText( "insert value to n" ); flagPoint = 0; label1.setText( "" ); return; } else { n1 = label1.getText(); label2.setText( "n="+n1); label1.setText( "" ); flagPoint = 0; return; } } if ( e.getSource().equals( button12 ) ) { label1.setText( "" ); flagPoint = 0; return; } } public void mouseExited( MouseEvent e ) { } public void mouseEntered( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { } public void mouseReleased( MouseEvent e ) { } } button1.addMouseListener(new MouseListenerAdapter()); button12.addMouseListener(new MouseListenerAdapter()); button2.addMouseListener(new MouseListenerAdapter()); button3.addMouseListener(new MouseListenerAdapter()); button4.addMouseListener(new MouseListenerAdapter()); button5.addMouseListener(new MouseListenerAdapter()); button6.addMouseListener(new MouseListenerAdapter()); button7.addMouseListener(new MouseListenerAdapter()); button8.addMouseListener(new MouseListenerAdapter()); button9.addMouseListener(new MouseListenerAdapter()); button10.addMouseListener(new MouseListenerAdapter()); button11.addMouseListener(new MouseListenerAdapter()); button13.addMouseListener(new MouseListenerAdapter()); button14.addMouseListener(new MouseListenerAdapter()); button15.addMouseListener(new MouseListenerAdapter()); button16.addMouseListener(new MouseListenerAdapter()); button17.addMouseListener(new MouseListenerAdapter()); button18.addMouseListener(new MouseListenerAdapter()); button19.addMouseListener(new MouseListenerAdapter()); } } //