Hallo ich soll ein Taschenrechner programmieren, aber ich weiss nicht wo ich anfangen soll hab bis jetzt nur die Oberfläche! Könnt ihr mir sagen wie ich daran gehen soll???Danke
Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class Rechner1 extends JFrame implements ActionListener {
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,
b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27;
TextField tf;
public Rechner1() {
setSize(260, 260);
setLocation(200, 200);
setVisible(true);
tf = new TextField();
tf.setSize(235, 23);
tf.setLocation(8, 20);
add(tf);
tf.setVisible(true);
b1 = new Button("C");
b1.setSize(55, 27);
b1.setLocation(175, 60);
add(b1);
b1.addActionListener(this);
b2 = new Button("CE");
b2.setSize(55, 27);
b2.setLocation(115, 60);
b2.setVisible(true);
add(b2);
b2.addActionListener(this);
b3 = new Button("Rücktaste");
b3.setSize(55, 27);
b3.setLocation(55, 60);
add(b3);
b3.addActionListener(this);
b4 = new Button("MC");
b4.setSize(30, 27);
b4.setLocation(8, 92);
add(b4);
b4.addActionListener(this);
b5 = new Button("MR");
b5.setSize(30, 27);
b5.setLocation(8, 124);
add(b5);
b5.addActionListener(this);
b6 = new Button("MS");
b6.setSize(30, 27);
b6.setLocation(8, 156);
add(b6);
b6.addActionListener(this);
b7 = new Button("M+");
b7.setSize(30, 27);
b7.setLocation(8, 188);
add(b7);
b7.addActionListener(this);
b8 = new Button("0");
b8.setSize(30, 27);
b8.setLocation(55, 188);
add(b8);
b8.addActionListener(this);
b9 = new Button("1");
b9.setSize(30, 27);
b9.setLocation(55, 156);
add(b9);
b9.addActionListener(this);
b10 = new Button("2");
b10.setSize(30, 27);
b10.setLocation(90, 156);
add(b10);
b10.addActionListener(this);
b11 = new Button("3");
b11.setSize(30, 27);
b11.setLocation(125, 156);
add(b11);
b11.addActionListener(this);
b12 = new Button("4");
b12.setSize(30, 27);
b12.setLocation(55, 124);
add(b12);
b12.addActionListener(this);
b13 = new Button("5");
b13.setSize(30, 27);
b13.setLocation(90, 124);
add(b13);
b13.addActionListener(this);
b14 = new Button("6");
b14.setSize(30, 27);
b14.setLocation(125, 124);
add(b14);
b14.addActionListener(this);
b15 = new Button("7");
b15.setSize(30, 27);
b15.setLocation(55, 92);
add(b15);
b15.addActionListener(this);
b16 = new Button("8");
b16.setSize(30, 27);
b16.setLocation(90, 92);
add(b16);
b16.addActionListener(this);
b17 = new Button("9");
b17.setSize(30, 27);
b17.setLocation(125, 92);
add(b17);
b17.addActionListener(this);
b18 = new Button("+/-");
b18.setSize(30, 27);
b18.setLocation(90, 188);
add(b18);
b18.addActionListener(this);
b19 = new Button(".");
b19.setSize(30, 27);
b19.setLocation(125, 188);
add(b19);
b19.addActionListener(this);
b20 = new Button("/");
b20.setSize(30, 27);
b20.setLocation(160, 92);
add(b20);
b20.addActionListener(this);
b21 = new Button("*");
b21.setSize(30, 27);
b21.setLocation(160, 124);
add(b21);
b21.addActionListener(this);
b22 = new Button("-");
b22.setSize(30, 27);
b22.setLocation(160, 156);
add(b22);
b22.addActionListener(this);
b23 = new Button("+");
b23.setSize(30, 27);
b23.setLocation(160, 188);
add(b23);
b23.addActionListener(this);
b24 = new Button("=");
b24.setSize(30, 27);
b24.setLocation(195, 188);
add(b24);
b24.addActionListener(this);
b25 = new Button("1/x");
b25.setSize(30, 27);
b25.setLocation(195, 156);
add(b25);
b25.addActionListener(this);
b26 = new Button("%");
b26.setSize(30, 27);
b26.setLocation(195, 124);
add(b26);
b26.addActionListener(this);
b27 = new Button("sqrt");
b27.setSize(30, 27);
b27.setLocation(195, 92);
add(b27);
b27.addActionListener(this);
}
public static void main(String Args[]){
new Rechner1();
}
public void actionPerformed(ActionEvent arg0) {
}
}