package untitled1; import java.awt.*; import java.awt.event.*; import java.applet.*; import com.borland.jbcl.layout.*; public class calculatorupdate extends Applet { double startnum; boolean isResult = false; boolean flagAdd = false; boolean flagSub = false; boolean flagMul = false; boolean flagDiv = false; double endnum; String str = null; boolean isStandalone = false; Button button1 = new Button(); XYLayout xYLayout1 = new XYLayout(); Button button2 = new Button(); Button button3 = new Button(); Button button4 = new Button(); Button button5 = new Button(); Button button6 = new Button(); Button button7 = new Button(); Button button8 = new Button(); Button button9 = new Button(); Button button10 = new Button(); Button button11 = new Button(); Button button12 = new Button(); Button button13 = new Button(); Button button14 = new Button(); Button button15 = new Button(); Button button16 = new Button(); Button button17 = new Button(); TextField text = new TextField(); Button button18 = new Button(); Button button19 = new Button(); Button button20 = new Button(); Button button21 = new Button(); Button button22 = new Button(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public calculatorupdate() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { button1.setFont(new java.awt.Font("Dialog", 0, 10)); button1.setLabel("1"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(xYLayout1); button2.setFont(new java.awt.Font("Dialog", 0, 10)); button2.setLabel("2"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button3.setFont(new java.awt.Font("Dialog", 0, 10)); button3.setLabel("3"); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button4.setFont(new java.awt.Font("Dialog", 0, 10)); button4.setLabel("4"); button4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button5.setFont(new java.awt.Font("Dialog", 0, 10)); button5.setLabel("5"); button5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button6.setFont(new java.awt.Font("Dialog", 0, 10)); button6.setLabel("6"); button6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button7.setFont(new java.awt.Font("Dialog", 0, 10)); button7.setLabel("7"); button7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button8.setFont(new java.awt.Font("Dialog", 0, 10)); button8.setLabel("8"); button8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button9.setFont(new java.awt.Font("Dialog", 0, 10)); button9.setLabel("9"); button9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button10.setFont(new java.awt.Font("Dialog", 0, 10)); button10.setLabel("0"); button10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button11.setFont(new java.awt.Font("Dialog", 0, 10)); button11.setLabel("."); button11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button11_actionPerformed(e); } }); button12.setFont(new java.awt.Font("Dialog", 0, 10)); button12.setLabel("+"); button12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button12_actionPerformed(e); } }); button13.setFont(new java.awt.Font("Dialog", 0, 10)); button13.setLabel("c"); button13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button13_actionPerformed(e); } }); button14.setLabel("="); button14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button14_actionPerformed(e); } }); button15.setLabel("-"); button15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button15_actionPerformed(e); } }); button16.setLabel("*"); button16.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button16_actionPerformed(e); } }); button17.setLabel("/"); button17.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button17_actionPerformed(e); } }); text.setEditable(false); text.setText("0"); button18.setFont(new java.awt.Font("Dialog", 0, 8)); button18.setLabel("@"); button18.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button18_actionPerformed(e); } }); button19.setEnabled(false); button19.setLabel("!"); button19.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button19_actionPerformed(e); } }); button20.setEnabled(false); button20.setLabel("sin"); button21.setEnabled(false); button21.setLabel("cos"); button22.setEnabled(false); button22.setLabel("exp"); this.add(button1, new XYConstraints(60, 50, 40, 40)); this.add(button2, new XYConstraints(120, 50, 40, 40)); this.add(button3, new XYConstraints(180, 50, 40, 40)); this.add(button4, new XYConstraints(60, 100, 40, 40)); this.add(button5, new XYConstraints(120, 100, 40, 40)); this.add(button6, new XYConstraints(180, 100, 40, 40)); this.add(button7, new XYConstraints(60, 150, 40, 40)); this.add(button8, new XYConstraints(120, 150, 40, 40)); this.add(button9, new XYConstraints(180, 150, 40, 40)); this.add(button10, new XYConstraints(60, 200, 40, 40)); this.add(button11, new XYConstraints(120, 200, 40, 40)); this.add(button12, new XYConstraints(180, 200, 40, 40)); this.add(button13, new XYConstraints(10, 50, 40, 40)); this.add(button14, new XYConstraints(230, 50, 50, 40)); this.add(button15, new XYConstraints(60, 250, 40, 40)); this.add(button16, new XYConstraints(120, 250, 40, 40)); this.add(button17, new XYConstraints(180, 250, 40, 40)); this.add(text, new XYConstraints(60, 10, 160, 25)); this.add(button18, new XYConstraints(230, 10, 50, 30)); this.add(button19, new XYConstraints(230, 100, 60, 40)); this.add(button20, new XYConstraints(230, 150, 60, 40)); this.add(button21, new XYConstraints(230, 200, 60, 40)); this.add(button22, new XYConstraints(230, 250, 60, 40)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void button1_actionPerformed(ActionEvent e) { if (isResult){ text.setText("0"); isResult = !isResult; } str = text.getText(); if (str.equals("0")){ text.setText(e.getActionCommand()); } else{ str=str+e.getActionCommand(); text.setText(str); } } void button11_actionPerformed(ActionEvent e) { if(str.indexOf(".") str=str+"."; text.setText(str); } } void button12_actionPerformed(ActionEvent e) { startnum = Double.parseDouble(text.getText()); flagAdd = true; isResult = true; } void button15_actionPerformed(ActionEvent e) { startnum = Double.parseDouble(text.getText()); flagSub = true; isResult = true; } void button16_actionPerformed(ActionEvent e) { startnum = Double.parseDouble(text.getText()); flagMul = true; } void button17_actionPerformed(ActionEvent e) { startnum = Double.parseDouble(text.getText()); flagDiv = true; isResult = true; } void button13_actionPerformed(ActionEvent e) { text.setText("0"); } void button14_actionPerformed(ActionEvent e) { String strchip; int step; endnum = Double.parseDouble(text.getText()); if(flagAdd){ text.setText(String.valueOf(startnum+endnum)); isResult = true; flagAdd = !flagAdd; } if(flagSub){ text.setText(String.valueOf(startnum-endnum)); isResult = true; flagSub = !flagSub; } if(flagMul){ text.setText(String.valueOf(startnum*endnum)); isResult = true; flagMul = !flagMul; } if((flagDiv)&&(endnum!=0)){ text.setText(String.valueOf(startnum/endnum)); isResult = true; flagDiv = !flagDiv; } } void button18_actionPerformed(ActionEvent e) { button19.setEnabled(true); button20.setEnabled(true); button21.setEnabled(true); button22.setEnabled(true); text.setText("0"); } void button19_actionPerformed(ActionEvent e) { int Mull = 1; if(((text.getText()).indexOf(".")0)){ int x = Integer.parseInt(text.getText()); for(int i=1;i Mull = Mull*i; } text.setText(String.valueOf(Mull)); isResult = true; } } }