Commit 847d3774 authored by Joost Rijneveld's avatar Joost Rijneveld

Added promptCharArray and trap 4 to push a series of characters to the stack

parent 9776d888
......@@ -165,6 +165,7 @@ public class Instruction
protected final static int TR_PR_CHAR = 1 ;
protected final static int TR_IN_INT = 2 ;
protected final static int TR_IN_CHAR = 3 ;
protected final static int TR_IN_CHAR_ARRAY = 4;
/**
* Metas
......
......@@ -496,6 +496,12 @@ public class Machine
case Instruction.TR_IN_CHAR :
push(messenger.promptChar());
break;
case Instruction.TR_IN_CHAR_ARRAY :
push(0);
for (int i : messenger.promptCharArray()) {
push(i);
}
break;
default : break ;
}
break ;
......
......@@ -24,4 +24,10 @@ public interface Messenger
*/
public int promptChar();
/**
* Asks the user for a string (i.e. via a dialog)
* @return Returns an array of unicode integer code points
*/
public int[] promptCharArray();
}
\ No newline at end of file
......@@ -686,6 +686,19 @@ public class SSMRunner extends JFrame
return s.codePointAt(0);
}
}
public int[] promptCharArray() {
String s = JOptionPane.showInputDialog(this,
"Please enter a string.","String requested", JOptionPane.QUESTION_MESSAGE);
if (s == null || s.length() == 0) {
return new int[0];
}
int[] result = new int[s.length()];
for(int i = 0; i < s.length(); i++) {
result[i] = s.codePointAt(i);
}
return result;
}
// Close the window when the close box is clicked
void thisWindowClosing(java.awt.event.WindowEvent e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment