33import java .awt .event .KeyEvent ;
44
55import paintcomponents .TextPaintComponent ;
6+ import script .ExecutionErrorException ;
7+ import script .Interpreter ;
68
79public class KeyHandler {
810
11+ private static final int VERTICAL_OFFSET = 5 ;
912 private PaintPanel paintPanel ;
1013 private String pendingCommand ;
1114 private boolean inCommandMode ;
1215 private TextPaintComponent component ;
13-
16+ Interpreter interpreter ;
1417 public KeyHandler (PaintPanel paintPanel ) {
1518 pendingCommand = "" ;
1619 this .paintPanel = paintPanel ;
20+
21+ //initialize text component
1722 this .component = new TextPaintComponent ("" , 0 , 0 );
1823 this .paintPanel .addPaintComponent (this .component );
24+
25+ interpreter = new Interpreter (paintPanel );
26+
27+
28+ //not in command
1929 inCommandMode = false ;
2030 }
2131
@@ -55,6 +65,11 @@ public void keyPressed(KeyEvent e) {
5565
5666 private void executeCommand (String pendingCommand2 ) {
5767
68+ try {
69+ interpreter .interpreteLine (pendingCommand2 );
70+ } catch (ExecutionErrorException e ) {
71+ e .printStackTrace ();
72+ }
5873 }
5974
6075 private void update () {
@@ -67,7 +82,7 @@ private void update() {
6782 int height = paintPanel .getHeight ();
6883 int rowHeight = component .getRowHeight ();
6984 component .setX (0 );
70- component .setY (height - rowHeight );
85+ component .setY (height - rowHeight - VERTICAL_OFFSET );
7186 paintPanel .repaint ();
7287 }
7388
0 commit comments