See my comments:
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class RekenMaskin extends Frame
implements WindowListener, ActionListener { // actionlistener for buttons
TextField disp=null;
public RekenMaskin (String title) {
super (title);
addWindowListener (this);
setLayout (new BorderLayout());
disp=new TextField(); // add textfield for display
Panel p = new Panel() ;
p.setLayout (new GridLayout (4,3));
Button b1 = new Button ("1");
Button b2 = new Button ("2");
Button b3 = new Button ("3");
Button b4 = new Button ("4");
Button b5 = new Button ("5");
Button b6 = new Button ("6");
Button b7 = new Button ("7");
Button b8 = new Button ("8");
Button b9 = new Button ("9");
Button Clear = new Button ("Clear");
Button b0 = new Button ("0");
Button Stop = new Button ("Stop");
b0.addActionListener(this); // add this frame to the buttons actionlisteners
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
Clear.addActionListener(this);
Stop.addActionListener(this);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(b9);
p.add(Clear);
p.add(b0);
p.add(Stop);
add (p,BorderLayout.CENTER);
add(disp, BorderLayout.NORTH);
}
public void windowClosing (WindowEvent e) {
System.exit (0);
}
public void windowActivated (WindowEvent e) { }
public void windowClosed (WindowEvent e) { }
public void windowDeactivated (WindowEvent e) { }
public void windowDeiconified (WindowEvent e) { }
public void windowIconified (WindowEvent e) { }
public void windowOpened (WindowEvent e) { }
public static void main (String [ ] argv) {
RekenMaskin ld = new RekenMaskin ("RekenMaskin");
ld.setSize (300, 400);
ld.setVisible (true);
}
public void actionPerformed (ActionEvent e) {
String s=e.getActionCommand();
if (s.equals("Clear")) {
this.disp.setText("");
} else if (s.equals("Stop")) {
this.dispose();
} else {
String ss=this.disp.getText().trim()+s;
disp.setText(ss);
}
}
// whats this code doing here...?
public void ActionListener (ActionEvent e)
{
}
}
Bookmarks