import java.awt.*; import java.awt.event.*; public class Works extends TextField { protected int accumulator; protected int oldval; protected char pending; public Works() { super(10); accumulator=0; oldval=0; pending=' '; } public void update_display() { setText(""+accumulator); } public void digit(int n) { accumulator=accumulator*10+n; update_display(); } protected void do_pending() { switch (pending) { case ' ': break; case '+': accumulator=oldval+accumulator; break; case '-': accumulator=oldval-accumulator; break; case '*': accumulator=oldval*accumulator; break; case '/': accumulator=oldval/accumulator; break; } pending=' '; update_display(); oldval=accumulator; accumulator=0; } public void plus() { do_pending(); pending='+'; } public void minus() { do_pending(); pending='-'; } public void times() { do_pending(); pending='*'; } public void divide() { do_pending(); pending='/'; } public void equals() { do_pending(); accumulator=oldval; } }