sclass ForwardAndBackButtons { JTextField tf; O onClick; // runnable JButton btnBack, btnForw; new L history; int historyIdx; *(JTextField *tf, O *onClick) { btnBack = jbutton(resizeImage(loadImage2(#1007466), 32), r { back() }); btnForw = jbutton(resizeImage( img_getCenterPortion(loadImage2(#1007467), 198, 198), 32), r { forward() }); update(); } JPanel buttons() { ret hstackWithSpacing(6, btnBack, btnForw); } void back { if (historyIdx <= 1) ret; --historyIdx; tf.setText(history.get(historyIdx-1)); go(); } void forward { if (historyIdx >= l(history)) ret; ++historyIdx; tf.setText(history.get(historyIdx-1)); go(); } void go { update(); pcallF(onClick); } void submitted { subList(history, historyIdx).clear(); history.add(getTextTrim(tf)); ++historyIdx; update(); } void update { btnBack.setEnabled(historyIdx > 1); btnForw.setEnabled(historyIdx < l(history)); } }