package taschenrechner; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Applet1 extends Applet { boolean isStandalone = false; Panel panel1 = new Panel(); Button button1 = new Button(); 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(); GridLayout gridLayout1 = new GridLayout(4,4); Button button12 = new Button(); Button button13 = new Button(); Button button14 = new Button(); Button button15 = new Button(); Button button16 = new Button(); TextField textField1 = new TextField(); Label label1 = new Label(); Label label2 = new Label(); Button button17 = new Button(); /**Parameterwert holen*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Das Applet konstruieren*/ public Applet1() { } /**Das Applet initialisieren*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Initialisierung der Komponenten*/ private void jbInit() throws Exception { this.setLayout(null); panel1.setBounds(new Rectangle(38, 118, 169, 160)); panel1.setLayout(gridLayout1); button1.setLabel("7"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setLabel("8"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); button3.setLabel("/"); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button3_actionPerformed(e); } }); button4.setLabel("="); button4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button4_actionPerformed(e); } }); button5.setLabel("."); button5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button5_actionPerformed(e); } }); button6.setLabel("0"); button7.setLabel("3"); button7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button7_actionPerformed(e); } }); button8.setLabel("2"); button8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button8_actionPerformed(e); } }); button9.setLabel("1"); button9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button9_actionPerformed(e); } }); button10.setLabel("+"); button10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button10_actionPerformed(e); } }); button11.setLabel("9"); button11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button11_actionPerformed(e); } }); button12.setLabel("4"); button12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button12_actionPerformed(e); } }); button13.setLabel("5"); 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("6"); 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); } }); //textField1.setText("textField1"); textField1.setBounds(new Rectangle(40, 74, 166, 27)); label1.setText("label1"); label1.setBounds(new Rectangle(50, 28, 141, 17)); label2.setText("label2"); label2.setBounds(new Rectangle(209, 26, 34, 17)); button17.setLabel("Clear"); button17.setBounds(new Rectangle(212, 120, 64, 29)); button17.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button17_actionPerformed(e); } }); this.add(panel1, null); panel1.add(button1, null); panel1.add(button2, null); panel1.add(button11, null); panel1.add(button10, null); panel1.add(button12, null); panel1.add(button13, null); panel1.add(button15, null); panel1.add(button14, null); panel1.add(button9, null); panel1.add(button8, null); panel1.add(button7, null); panel1.add(button16, null); panel1.add(button6, null); panel1.add(button5, null); panel1.add(button4, null); panel1.add(button3, null); this.add(textField1, null); this.add(button17, null); this.add(label2, null); this.add(label1, null); } /**Applet-Information holen*/ public String getAppletInfo() { return "Applet-Information"; } /**Parameter-Infos holen*/ public String[][] getParameterInfo() { return null; } void zahlrein(int i) { textField1.setText(textField1.getText()+i); } void operation(String c) { label1.setText(textField1.getText()); textField1.setText(""); label2.setText(c); } void button15_actionPerformed(ActionEvent e) { zahlrein(6); } void button1_actionPerformed(ActionEvent e) { zahlrein(7); } void button2_actionPerformed(ActionEvent e) { zahlrein(8); } void button11_actionPerformed(ActionEvent e) { zahlrein(9); } void button12_actionPerformed(ActionEvent e) { zahlrein(4); } void button13_actionPerformed(ActionEvent e) { zahlrein(5); } void button9_actionPerformed(ActionEvent e) { zahlrein(1); } void button8_actionPerformed(ActionEvent e) { zahlrein(2); } void button7_actionPerformed(ActionEvent e) { zahlrein(3); } void button5_actionPerformed(ActionEvent e) { textField1.setText(textField1.getText()+'.'); } void button10_actionPerformed(ActionEvent e) { operation("+"); } void button17_actionPerformed(ActionEvent e) { textField1.setText(""); label1.setText(""); label2.setText(""); } void button14_actionPerformed(ActionEvent e) { operation("*"); } void button16_actionPerformed(ActionEvent e) { operation("-"); } void button3_actionPerformed(ActionEvent e) { operation("/"); } void button4_actionPerformed(ActionEvent e) { float a,b,c; c=0; //textField1.setText("HUHUsteng"); a= Float.valueOf(label1.getText()).floatValue(); b= Float.valueOf (textField1.getText()).floatValue(); if (label2.getText() =="+") c=a+b; else if (label2.getText() =="*") c=a*b; else if (label2.getText() =="-") c=a-b; else if (label2.getText() =="/") c=a/b; textField1.setText(Float.toString(c)); label1.setText(""); label2.setText(""); } }