Java  1.0
TextIOApplet.java
Go to the documentation of this file.
1 
2 
3 import java.io.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import javax.swing.*;
7 import java.util.IllegalFormatException;
8 import java.util.regex.Matcher;
9 import java.util.regex.Pattern;
10 
11 
46 abstract public class TextIOApplet extends JApplet {
47 
48  /* Modified November 2007 to empty the TextIO input buffer when switching from one
49  * input source to another. This fixes a bug that allows input from the previous input
50  * source to be read after the new source has been selected. This bug also allowed
51  * input to carry over from one call to the runProgram() program to the next.
52  */
53 
54  /* Modified December 2010; added a "catch" handler for Error to the try..catch statement
55  * in the run() method in class ProgRun . Without this, errors such as StackOverflowError would
56  * not be displayed in the applet. (It's not a good idea to catch Errors in general, but the
57  * thread is going to end anyway.)
58  */
59 
60  //**************** Stuff that is relevant to concrete subclasses of this class ***************
61 
66  abstract protected void runProgram();
67 
72  protected TextIOObject TextIO;
73 
81  protected BogusSystem System;
82 
88  protected String getDefaultAppletTitle() {
89  return "TextIO Applet";
90  }
91 
95  protected String getTitle() {
96  return message.getText();
97  }
98 
105  protected void setTitle(String title) {
106  message.setText(title);
107  }
108 
116  protected void doDelay(int milliseconds) {
117  console.checkAbort();
118  if (milliseconds <= 0)
119  Thread.yield();
120  else {
121  synchronized(console) {
122  try {
123  console.wait(milliseconds);
124  }
125  catch (InterruptedException e) {
126  }
127  }
128  }
129  }
130 
141  protected void checkAbort() {
142  console.checkAbort();
143  }
144 
153  protected static class AbortException extends RuntimeException {
154  }
155 
166  protected class BogusSystem {
167  PrintWriter out;
168  BufferedReader in;
169  public long currentTimeMillis() {
170  return java.lang.System.currentTimeMillis();
171  }
172  public void exit(int ignored) {
173  throw new RuntimeException("Program ended with System.exit().");
174  }
175  }
176 
177  //************* Everything after this point is implementation **************************
178 
179  //************* Implementing the applet ************************************************
180 
181  private volatile Thread runner; // For executing the runProgram() method in a separate thread.
182  private volatile boolean aborted; // Set to true when the user clicks the "Abort" button.
183  private volatile boolean programIsRunning; // Set to true when the runProgram() method is running.
184 
185  private JButton runAgainButton; // Button can be clicked after program ends to run it again.
186  private JButton abortButton; // Button can be clicked to abort a program that is running.
187  private JLabel message; // The message displayed at the top of the applet.
188 
189  public TextIOApplet() {
190  console = new Console();
191  System = new BogusSystem();
192  System.in = in = standardInput = console.inputStream;
193  System.out = out = standardOutput = console.outputStream;
194  TextIO = new TextIOObject();
195  JPanel bottom = new JPanel();
196  abortButton = new JButton("Abort Program");
197  bottom.add(abortButton);
198  abortButton.setEnabled(false);
199  abortButton.addActionListener( new ActionListener() {
200  public void actionPerformed(ActionEvent evt) {
201  synchronized(console) {
202  aborted = true;
203  abortButton.setEnabled(false);
204  abortButton.setText("Aborting...");
205  console.notify();
206  }
207  }
208  });
209  runAgainButton = new JButton("Run the Program");
210  runAgainButton.addActionListener( new ActionListener() {
211  public void actionPerformed(ActionEvent evt) {
212  synchronized(console) {
213  programIsRunning = true;
214  console.notify();
215  }
216  }
217  });
218  bottom.add(runAgainButton);
219  bottom.setBackground(Color.LIGHT_GRAY);
220  runAgainButton.setBackground(Color.LIGHT_GRAY);
221  abortButton.setBackground(Color.LIGHT_GRAY);
222  message = new JLabel(getDefaultAppletTitle(),JLabel.CENTER);
223  message.setForeground(Color.RED);
224  message.setBackground(Color.LIGHT_GRAY);
225  Font f = message.getFont();
226  message.setFont(new Font(f.getName(),Font.BOLD,(int)(f.getSize()*1.12)));
227  JPanel top = new JPanel();
228  top.setLayout(new BorderLayout());
229  top.setBackground(Color.LIGHT_GRAY);
230  top.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
231  top.add(message);
232  JPanel panel = new JPanel();
233  panel.setLayout(new BorderLayout(2,2));
234  panel.setBackground(Color.DARK_GRAY);
235  panel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY,3));
236  panel.add(console,BorderLayout.CENTER);
237  panel.add(console.scroller,BorderLayout.EAST);
238  panel.add(bottom,BorderLayout.SOUTH);
239  panel.add(top,BorderLayout.NORTH);
240  setContentPane(panel);
241  }
242 
243  private class ProgRun extends Thread { // Defines the thread that runs the program.
244  public void run() {
245  while (true) {
246  synchronized(console) {
247  while (!programIsRunning) {
248  try {
249  console.wait(1000);
250  }
251  catch (InterruptedException e) {
252  }
253  }
254  }
255  message.setText(getDefaultAppletTitle());
256  abortButton.setEnabled(true);
257  runAgainButton.setEnabled(false);
258  console.clear();
259  console.requestFocus();
260  try {
261  if (programIsRunning) {
262  aborted = false;
263  runProgram();
264  }
265  }
266  catch (AbortException e) {
267  aborted = false;
268  console.putString("\n\n\n ***** PROGRAM ABORTED BY USER *****\n\n\n");
269  }
270  catch (Exception e) {
271  aborted = false;
272  console.putString("\n\n\n ***** PROGRAM TERMINATED BY EXCEPTION ***** \n\n\n");
273  e.printStackTrace(standardOutput);
274  }
275  catch (Error e) {
276  aborted = false;
277  console.putString("\n\n\n ***** PROGRAM TERMINATED BY Error ***** \n\n");
278  console.putString(" ***** " + e.toString() + "\n\n");
279  }
280  finally {
281  programIsRunning = false;
282  console.doingInput = false;
283  aborted = false;
284  abortButton.setEnabled(false);
285  abortButton.setText("Abort Program");
286  runAgainButton.setEnabled(true);
287  runAgainButton.setText("Run Program Again");
290  }
291  }
292  }
293  }
294 
298  public void init() {
299  runner = new ProgRun();
300  programIsRunning = false;
301  runner.start();
302  }
303 
308  protected class TextIOObject {
309 
314  public final char EOF = (char)0xFFFF;
315 
320  public final char EOLN = '\n'; // The value returned by peek() when at end-of-line.
321 
322 
328  public void readStandardInput() {
330  return;
331  try {
332  in.close();
333  }
334  catch (Exception e) {
335  }
336  emptyBuffer(); // Added November 2007
337  in = standardInput;
338  inputFileName = null;
339  readingStandardInput = true;
340  inputErrorCount = 0;
341  }
342 
349  public void readStream(InputStream inputStream) {
350  if (inputStream == null)
352  else
353  readStream(new InputStreamReader(inputStream));
354  }
355 
362  public void readStream(Reader inputStream) {
363  if (inputStream == null)
365  else {
366  if ( inputStream instanceof BufferedReader)
367  in = (BufferedReader)inputStream;
368  else
369  in = new BufferedReader(inputStream);
370  emptyBuffer(); // Added November 2007
371  inputFileName = null;
372  readingStandardInput = false;
373  inputErrorCount = 0;
374  }
375  }
376 
386  public void readFile(String fileName) {
387  if (fileName == null) // Go back to reading standard input
389  else {
390  BufferedReader newin;
391  try {
392  newin = new BufferedReader( new FileReader(fileName) );
393  }
394  catch (Exception e) {
395  throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for input.\n"
396  + "(Error :" + e + ")");
397  }
398  if (! readingStandardInput) { // close current input stream
399  try {
400  in.close();
401  }
402  catch (Exception e) {
403  }
404  }
405  emptyBuffer(); // Added November 2007
406  in = newin;
407  readingStandardInput = false;
408  inputErrorCount = 0;
409  inputFileName = fileName;
410  }
411  }
412 
428  public boolean readUserSelectedFile() {
429  if (fileDialog == null)
430  fileDialog = new JFileChooser();
431  fileDialog.setDialogTitle("Select File for Input");
432  int option = fileDialog.showOpenDialog(console);
433  if (option != JFileChooser.APPROVE_OPTION)
434  return false;
435  File selectedFile = fileDialog.getSelectedFile();
436  BufferedReader newin;
437  try {
438  newin = new BufferedReader( new FileReader(selectedFile) );
439  }
440  catch (Exception e) {
441  throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for input.\n"
442  + "(Error :" + e + ")");
443  }
444  if (!readingStandardInput) { // close current file
445  try {
446  in.close();
447  }
448  catch (Exception e) {
449  }
450  }
451  emptyBuffer(); // Added November 2007
452  in = newin;
453  inputFileName = selectedFile.getName();
454  readingStandardInput = false;
455  inputErrorCount = 0;
456  return true;
457  }
458 
464  public void writeStandardOutput() {
466  return;
467  try {
468  out.close();
469  }
470  catch (Exception e) {
471  }
472  outputFileName = null;
473  outputErrorCount = 0;
475  writingStandardOutput = true;
476  }
477 
478 
485  public void writeStream(OutputStream outputStream) {
486  if (outputStream == null)
488  else
489  writeStream(new PrintWriter(outputStream));
490  }
491 
498  public void writeStream(PrintWriter outputStream) {
499  if (outputStream == null)
501  else {
502  out = outputStream;
503  outputFileName = null;
504  outputErrorCount = 0;
505  writingStandardOutput = false;
506  }
507  }
508 
509 
523  public void writeFile(String fileName) {
524  if (fileName == null) // Go back to reading standard output
526  else {
527  PrintWriter newout;
528  try {
529  newout = new PrintWriter(new FileWriter(fileName));
530  }
531  catch (Exception e) {
532  throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for output.\n"
533  + "(Error :" + e + ")");
534  }
535  if (!writingStandardOutput) {
536  try {
537  out.close();
538  }
539  catch (Exception e) {
540  }
541  }
542  out = newout;
543  writingStandardOutput = false;
544  outputFileName = fileName;
545  outputErrorCount = 0;
546  }
547  }
548 
560  public boolean writeUserSelectedFile() {
561  if (fileDialog == null)
562  fileDialog = new JFileChooser();
563  fileDialog.setDialogTitle("Select File for Output");
564  File selectedFile;
565  while (true) {
566  int option = fileDialog.showSaveDialog(console);
567  if (option != JFileChooser.APPROVE_OPTION)
568  return false; // user canceled
569  selectedFile = fileDialog.getSelectedFile();
570  if (selectedFile.exists()) {
571  int response = JOptionPane.showConfirmDialog(console,
572  "The file \"" + selectedFile.getName() + "\" already exists. Do you want to replace it?",
573  "Replace existing file?",
574  JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
575  if (response == JOptionPane.YES_OPTION)
576  break;
577  }
578  else {
579  break;
580  }
581  }
582  PrintWriter newout;
583  try {
584  newout = new PrintWriter(new FileWriter(selectedFile));
585  }
586  catch (Exception e) {
587  throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for output.\n"
588  + "(Error :" + e + ")");
589  }
590  if (!writingStandardOutput) {
591  try {
592  out.close();
593  }
594  catch (Exception e) {
595  }
596  }
597  out = newout;
598  writingStandardOutput = false;
599  outputFileName = selectedFile.getName();
600  outputErrorCount = 0;
601  return true;
602  }
603 
604 
609  public String getInputFileName() {
610  return inputFileName;
611  }
612 
613 
618  public String getOutputFileName() {
619  return outputFileName;
620  }
621 
622 
623  // *************************** Output Methods *********************************
624 
630  public void put(Object x) {
631  out.print(x);
632  out.flush();
633  if (out.checkError())
634  outputError("Error while writing output.");
635  }
636 
648  public void put(Object x, int minChars) {
649  if (minChars <= 0)
650  out.print(x);
651  else {
652  out.printf("%" + minChars + "s", x);
653  out.flush();
654  }
655  if (out.checkError())
656  outputError("Error while writing output.");
657  }
658 
662  public void putln(Object x) {
663  out.println(x);
664  out.flush();
665  if (out.checkError())
666  outputError("Error while writing output.");
667  }
668 
672  public void putln(Object x, int minChars) {
673  put(x,minChars);
674  out.println();
675  out.flush();
676  if (out.checkError())
677  outputError("Error while writing output.");
678  }
679 
683  public void putln() {
684  out.println();
685  out.flush();
686  if (out.checkError())
687  outputError("Error while writing output.");
688  }
689 
699  public void putf(String format, Object... items) {
700  if (format == null)
701  throw new IllegalArgumentException("Null format string in TextIO.putf() method.");
702  try {
703  out.printf(format,items);
704  }
705  catch (IllegalFormatException e) {
706  throw new IllegalArgumentException("Illegal format string in TextIO.putf() method.");
707  }
708  out.flush();
709  if (out.checkError())
710  outputError("Error while writing output.");
711  }
712 
713  // *************************** Input Methods *********************************
714 
720  public boolean eoln() {
721  return peek() == '\n';
722  }
723 
729  public boolean eof() {
730  return peek() == EOF;
731  }
732 
741  public char getAnyChar() {
742  return readChar();
743  }
744 
752  public char peek() {
753  return lookChar();
754  }
755 
762  public void skipBlanks() {
763  char ch=lookChar();
764  while (ch != EOF && ch != '\n' && Character.isWhitespace(ch)) {
765  readChar();
766  ch = lookChar();
767  }
768  }
769 
776  private void skipWhitespace() {
777  char ch=lookChar();
778  while (ch != EOF && Character.isWhitespace(ch)) {
779  readChar();
780  if (ch == '\n' && readingStandardInput && writingStandardOutput) {
781  out.print("? ");
782  out.flush();
783  }
784  ch = lookChar();
785  }
786  }
787 
794  public byte getlnByte() {
795  byte x=getByte();
796  emptyBuffer();
797  return x;
798  }
799 
806  public short getlnShort() {
807  short x=getShort();
808  emptyBuffer();
809  return x;
810  }
811 
818  public int getlnInt() {
819  int x=getInt();
820  emptyBuffer();
821  return x;
822  }
823 
830  public long getlnLong() {
831  long x=getLong();
832  emptyBuffer();
833  return x;
834  }
835 
842  public float getlnFloat() {
843  float x=getFloat();
844  emptyBuffer();
845  return x;
846  }
847 
854  public double getlnDouble() {
855  double x=getDouble();
856  emptyBuffer();
857  return x;
858  }
859 
867  public char getlnChar() {
868  char x=getChar();
869  emptyBuffer();
870  return x;
871  }
872 
882  public boolean getlnBoolean() {
883  boolean x=getBoolean();
884  emptyBuffer();
885  return x;
886  }
887 
895  public String getlnWord() {
896  String x=getWord();
897  emptyBuffer();
898  return x;
899  }
900 
904  public String getlnString() {
905  return getln();
906  }
907 
915  public String getln() {
916  StringBuffer s = new StringBuffer(100);
917  char ch = readChar();
918  while (ch != '\n') {
919  s.append(ch);
920  ch = readChar();
921  }
922  return s.toString();
923  }
924 
931  public byte getByte() {
932  return (byte)readInteger(-128L,127L);
933  }
934 
941  public short getShort() {
942  return (short)readInteger(-32768L,32767L);
943  }
944 
951  public int getInt() {
952  return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE);
953  }
954 
961  public long getLong() {
962  return readInteger(Long.MIN_VALUE, Long.MAX_VALUE);
963  }
964 
971  public char getChar() {
972  skipWhitespace();
973  return readChar();
974  }
975 
982  public float getFloat() {
983  float x = 0.0F;
984  while (true) {
985  String str = readRealString();
986  if (str == null) {
987  errorMessage("Floating point number not found.",
988  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
989  }
990  else {
991  try {
992  x = Float.parseFloat(str);
993  }
994  catch (NumberFormatException e) {
995  errorMessage("Illegal floating point input, " + str + ".",
996  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
997  continue;
998  }
999  if (Float.isInfinite(x)) {
1000  errorMessage("Floating point input outside of legal range, " + str + ".",
1001  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
1002  continue;
1003  }
1004  break;
1005  }
1006  }
1007  inputErrorCount = 0;
1008  return x;
1009  }
1010 
1017  public double getDouble() {
1018  double x = 0.0;
1019  while (true) {
1020  String str = readRealString();
1021  if (str == null) {
1022  errorMessage("Floating point number not found.",
1023  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
1024  }
1025  else {
1026  try {
1027  x = Double.parseDouble(str);
1028  }
1029  catch (NumberFormatException e) {
1030  errorMessage("Illegal floating point input, " + str + ".",
1031  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
1032  continue;
1033  }
1034  if (Double.isInfinite(x)) {
1035  errorMessage("Floating point input outside of legal range, " + str + ".",
1036  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
1037  continue;
1038  }
1039  break;
1040  }
1041  }
1042  inputErrorCount = 0;
1043  return x;
1044  }
1045 
1053  public String getWord() {
1054  skipWhitespace();
1055  StringBuffer str = new StringBuffer(50);
1056  char ch = lookChar();
1057  while (ch == EOF || !Character.isWhitespace(ch)) {
1058  str.append(readChar());
1059  ch = lookChar();
1060  }
1061  return str.toString();
1062  }
1063 
1073  public boolean getBoolean() {
1074  boolean ans = false;
1075  while (true) {
1076  String s = getWord();
1077  if ( s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t") ||
1078  s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") ||
1079  s.equals("1") ) {
1080  ans = true;
1081  break;
1082  }
1083  else if ( s.equalsIgnoreCase("false") || s.equalsIgnoreCase("f") ||
1084  s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") ||
1085  s.equals("0") ) {
1086  ans = false;
1087  break;
1088  }
1089  else
1090  errorMessage("Illegal boolean input value.",
1091  "one of: true, false, t, f, yes, no, y, n, 0, or 1");
1092  }
1093  inputErrorCount = 0;
1094  return ans;
1095  }
1096 
1097  private String readRealString() { // read chars from input following syntax of real numbers
1098  skipWhitespace();
1099  if (lookChar() == EOF)
1100  return null;
1101  if (floatMatcher == null)
1102  floatMatcher = floatRegex.matcher(buffer);
1103  floatMatcher.region(pos,buffer.length());
1104  if (floatMatcher.lookingAt()) {
1105  String str = floatMatcher.group();
1106  pos = floatMatcher.end();
1107  return str;
1108  }
1109  else
1110  return null;
1111  }
1112 
1113  private String readIntegerString() { // read chars from input following syntax of integers
1114  skipWhitespace();
1115  if (lookChar() == EOF)
1116  return null;
1117  if (integerMatcher == null)
1118  integerMatcher = integerRegex.matcher(buffer);
1119  integerMatcher.region(pos,buffer.length());
1120  if (integerMatcher.lookingAt()) {
1121  String str = integerMatcher.group();
1122  pos = integerMatcher.end();
1123  return str;
1124  }
1125  else
1126  return null;
1127  }
1128 
1129  private long readInteger(long min, long max) { // read long integer, limited to specified range
1130  long x=0;
1131  while (true) {
1132  String s = readIntegerString();
1133  if (s == null){
1134  errorMessage("Integer value not found in input.",
1135  "Integer in the range " + min + " to " + max);
1136  }
1137  else {
1138  String str = s.toString();
1139  try {
1140  x = Long.parseLong(str);
1141  }
1142  catch (NumberFormatException e) {
1143  errorMessage("Illegal integer input, " + str + ".",
1144  "Integer in the range " + min + " to " + max);
1145  continue;
1146  }
1147  if (x < min || x > max) {
1148  errorMessage("Integer input outside of legal range, " + str + ".",
1149  "Integer in the range " + min + " to " + max);
1150  continue;
1151  }
1152  break;
1153  }
1154  }
1155  inputErrorCount = 0;
1156  return x;
1157  }
1158 
1159 
1160  private void errorMessage(String message, String expecting) { // Report error on input.
1161  console.clearTypeAhead();
1163  // inform user of error and force user to re-enter.
1164  out.println();
1165  out.print(" *** Error in input: " + message + "\n");
1166  out.print(" *** Expecting: " + expecting + "\n");
1167  out.print(" *** Discarding Input: ");
1168  if (lookChar() == '\n')
1169  out.print("(end-of-line)\n\n");
1170  else {
1171  while (lookChar() != '\n') // Discard and echo remaining chars on the current line of input.
1172  out.print(readChar());
1173  out.print("\n\n");
1174  }
1175  out.print("Please re-enter: ");
1176  out.flush();
1177  readChar(); // discard the end-of-line character
1178  inputErrorCount++;
1179  if (inputErrorCount >= 10)
1180  throw new IllegalArgumentException("Too many input consecutive input errors on standard input.");
1181  }
1182  else if (inputFileName != null)
1183  throw new IllegalArgumentException("Error while reading from file \"" + inputFileName + "\":\n"
1184  + message + "\nExpecting " + expecting);
1185  else
1186  throw new IllegalArgumentException("Error while reading from inptu stream:\n"
1187  + message + "\nExpecting " + expecting);
1188  }
1189 
1190  private char lookChar() { // return next character from input
1191  if (buffer == null || pos > buffer.length())
1192  fillBuffer();
1193  if (buffer == null)
1194  return EOF;
1195  else if (pos == buffer.length())
1196  return '\n';
1197  else
1198  return buffer.charAt(pos);
1199  }
1200 
1201  private char readChar() { // return and discard next character from input
1202  char ch = lookChar();
1203  if (buffer == null) {
1205  throw new IllegalArgumentException("Attempt to read past end-of-file in standard input???");
1206  else
1207  throw new IllegalArgumentException("Attempt to read past end-of-file in file \"" + inputFileName + "\".");
1208  }
1209  pos++;
1210  return ch;
1211  }
1212 
1213  private void fillBuffer() { // Wait for user to type a line and press return,
1214  try {
1215  buffer = in.readLine();
1216  }
1217  catch (Exception e) {
1218  if (e instanceof AbortException)
1219  throw (AbortException)e;
1220  else if (readingStandardInput)
1221  throw new IllegalArgumentException("Error while reading standard input???");
1222  else if (inputFileName != null)
1223  throw new IllegalArgumentException("Error while attempting to read from file \"" + inputFileName + "\".");
1224  else
1225  throw new IllegalArgumentException("Errow while attempting to read form an input stream.");
1226  }
1227  pos = 0;
1228  floatMatcher = null;
1229  integerMatcher = null;
1230  }
1231 
1232  private void emptyBuffer() { // discard the rest of the current line of input
1233  buffer = null;
1234  }
1235 
1236  private void outputError(String message) { // Report an error on output.
1237  if (writingStandardOutput) {
1238  java.lang.System.err.println("Error occurred in TextIO while writing to standard output!!");
1239  outputErrorCount++;
1240  if (outputErrorCount >= 10) {
1241  outputErrorCount = 0;
1242  throw new IllegalArgumentException("Too many errors while writing to standard output.");
1243  }
1244  }
1245  else if (outputFileName != null){
1246  throw new IllegalArgumentException("Error occurred while writing to file \""
1247  + outputFileName+ "\":\n " + message);
1248  }
1249  else {
1250  throw new IllegalArgumentException("Error occurred while writing to output stream:\n " + message);
1251  }
1252  }
1253  }
1254 
1255  // ******************************* Defining the GUI ***************************************
1256 
1264  private class Console extends JPanel {
1265  JScrollBar scroller;
1266  BufferedReader inputStream;
1267  PrintWriter outputStream;
1268  String[] lines;
1269  int topLine;
1270  int lineCount;
1271  int rows, columns;
1272  volatile boolean doingInput;
1273  volatile String inputBuffer;
1274  volatile boolean cursorOn = true;
1275  volatile int inputStartLine, inputStartColumn;
1276  volatile String typeAheadBuffer = "";
1277  FontMetrics fontMetrics;
1278  int lineSkip;
1279  int charWidth;
1280  final int MARGIN = 6;
1281  final Color CURSOR_COLOR = new Color(200,0,0);
1282 
1283  Console() {
1284  Font f = getFont();
1285  f = new Font("Monospaced",Font.PLAIN,f.getSize());
1286  setFont(f);
1287  fontMetrics = getFontMetrics(f);
1288  lineSkip = (int)(fontMetrics.getHeight() * 1.2);
1289  charWidth = fontMetrics.charWidth('W');
1290  setPreferredSize(new Dimension(2*MARGIN + 80*charWidth, 2*MARGIN + (25-1)*lineSkip + fontMetrics.getAscent() + fontMetrics.getDescent()));
1291  setBackground(Color.WHITE);
1292  setForeground(Color.BLACK);
1293  setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 3));
1294  addFocusListener( new FocusListener() {
1295  public void focusLost(FocusEvent evt) {
1296  setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,3));
1297  }
1298  public void focusGained(FocusEvent evt) {
1299  setBorder(BorderFactory.createLineBorder(Color.CYAN,3));
1300  }
1301  } );
1302  addMouseListener( new MouseAdapter() {
1303  public void mousePressed(MouseEvent evt) {
1304  requestFocus();
1305  }
1306  } );
1307  addKeyListener( new KeyAdapter() {
1308  public void keyTyped(KeyEvent evt) {
1309  char ch = evt.getKeyChar();
1310  if (ch == KeyEvent.CHAR_UNDEFINED)
1311  return;
1312  if (!doingInput) {
1313  typeAheadBuffer += ch;
1314  return;
1315  }
1316  synchronized(Console.this) {
1317  doInputChar(ch);
1318  Console.this.notify();
1319  }
1320  }
1321  } );
1322  lines = new String[2000];
1323  lineCount = 1;
1324  lines[0] = "";
1325  scroller = new JScrollBar(JScrollBar.VERTICAL,0,80,0,80);
1326  scroller.setEnabled(false);
1327  scroller.addAdjustmentListener( new AdjustmentListener() {
1328  public void adjustmentValueChanged(AdjustmentEvent evt) {
1329  topLine = scroller.getValue();
1330  repaint();
1331  }
1332  });
1333  inputStream = new BufferedReader(new CIN());
1334  outputStream = new PrintWriter(new COUT());
1335  }
1336 
1337  public void paintComponent(Graphics g) {
1338  super.paintComponent(g);
1339  if (rows == 0) {
1340  columns = (getWidth() - 2*MARGIN + 1) / charWidth;
1341  rows = 1 + (getHeight() - 2*MARGIN - fontMetrics.getAscent()) / lineSkip;
1342  scroller.setBlockIncrement(rows - 2);
1343  scrollToEnd();
1344  }
1345  for (int i = topLine; i < topLine + rows && i < lineCount; i++)
1346  g.drawString(lines[i],MARGIN,MARGIN+(i-topLine)*lineSkip + fontMetrics.getAscent());
1347  if (doingInput && cursorOn) {
1348  g.setColor(CURSOR_COLOR);
1349  int x = MARGIN + fontMetrics.stringWidth(lines[lineCount-1])+1;
1350  int y1 = MARGIN + (lineCount-1-topLine)*lineSkip + fontMetrics.getAscent() + fontMetrics.getDescent();
1351  int y2 = y1 - fontMetrics.getAscent() - fontMetrics.getDescent();
1352  g.drawLine(x,y1,x,y2);
1353  g.drawLine(x+1,y1,x+1,y2);
1354  }
1355  }
1356 
1357  synchronized void newLine() {
1358  checkAbort();
1359  try {
1360  Thread.sleep(20);
1361  }
1362  catch (InterruptedException e) {
1363  }
1364  if (lineCount == lines.length) {
1365  for (int i = 0; i < lines.length-1; i++)
1366  lines[i] = lines[i+1];
1367  lines[lines.length-1] = "";
1368  if (doingInput)
1369  inputStartLine--;
1370  }
1371  else {
1372  lines[lineCount] = "";
1373  lineCount++;
1374  }
1375  scrollToEnd();
1376  repaint();
1377  }
1378  synchronized void putChar(char ch) {
1379  checkAbort();
1380  if (ch == '\n') {
1381  newLine();
1382  return;
1383  }
1384  if (ch == '\t')
1385  ch = ' ';
1386  if (!Character.isDefined(ch) || Character.isISOControl(ch))
1387  return;
1388  if (columns > 0 && lines[lineCount-1].length() >= columns)
1389  newLine();
1390  lines[lineCount-1] += ch;
1391  }
1392 
1393  synchronized void deleteChar() {
1394  if (lineCount == 0)
1395  return;
1396  if (inputStartLine == lineCount-1 && inputStartColumn >= lines[lineCount-1].length())
1397  return;
1398  if (lines[lineCount-1].length() > 0)
1399  lines[lineCount-1] = lines[lineCount-1].substring(0,lines[lineCount-1].length()-1);
1400  else {
1401  lineCount--;
1402  scrollToEnd();
1403  }
1404  }
1405 
1406  synchronized private void putString(String str) {
1407  for (int i = 0; i < str.length(); i++)
1408  putChar(str.charAt(i));
1409  scrollToEnd();
1410  repaint();
1411  }
1412 
1413  void scrollToEnd() {
1414  if (rows == 0)
1415  return;
1416  if (lineCount <= rows) {
1417  topLine = 0;
1418  scroller.setEnabled(false);
1419  }
1420  else {
1421  topLine = lineCount - rows;
1422  scroller.setEnabled(true);
1423  }
1424  scroller.setValues(topLine,rows,0,rows+topLine);
1425  }
1426 
1427  synchronized void doInputChar(char ch) {
1428  checkAbort();
1429  if (ch == 8 || ch == 127) {
1430  deleteChar();
1431  if (inputBuffer.length() > 0)
1432  inputBuffer = inputBuffer.substring(0,inputBuffer.length()-1);
1433  }
1434  else if (ch == 13 || ch == 10) {
1435  newLine();
1436  doingInput = false;
1437  }
1438  else {
1439  putChar(ch);
1440  if (ch == '\t')
1441  ch = ' ';
1442  if (Character.isDefined(ch) && ! Character.isISOControl(ch))
1443  inputBuffer += ch;
1444  }
1445  scrollToEnd();
1446  repaint();
1447  }
1448 
1449  synchronized void clearTypeAhead() {
1450  typeAheadBuffer = "";
1451  }
1452 
1453  synchronized void clear() {
1454  buffer = null;
1455  clearTypeAhead();
1456  lineCount = 1;
1457  lines[0] = "";
1458  topLine = 0;
1459  scrollToEnd();
1460  }
1461 
1462  void checkAbort() {
1463  if (aborted)
1464  throw new AbortException();
1465  }
1466 
1467  class CIN extends Reader { // "Standard input" is replaced in TextIO with an object of this type.
1468  String buffer;
1469  int pos;
1470  public void close() {
1471  }
1472  public int read(char[] b, int offset, int length) throws IOException {
1473  int ct = 0;
1474  int ch;
1475  do {
1476  ch = read();
1477  b[offset + ct] = (char)ch;
1478  ct++;
1479  } while (ch != 10);
1480  return ct;
1481  }
1482  public int read() {
1483  if (buffer != null && pos < buffer.length()) {
1484  pos++;
1485  return buffer.charAt(pos-1);
1486  }
1487  synchronized(Console.this) {
1488  inputStartLine = lineCount - 1;
1489  inputStartColumn = lines[lineCount-1].length();
1490  char ch = 0;
1491  scrollToEnd();
1492  inputBuffer = "";
1493  while (typeAheadBuffer.length() > 0) {
1494  ch = typeAheadBuffer.charAt(0);
1495  typeAheadBuffer = typeAheadBuffer.substring(1);
1496  if (ch == 13 || ch == 10)
1497  break;
1498  doInputChar(ch);
1499  repaint();
1500  try {
1501  Console.this.wait(25);
1502  }
1503  catch (InterruptedException e) {
1504  }
1505  }
1506  if (ch != 13 && ch != 10) {
1507  doingInput = true;
1508  cursorOn = true;
1509  requestFocus();
1510  while (doingInput) {
1511  try {
1512  Console.this.wait(300);
1513  cursorOn = !cursorOn;
1514  repaint();
1515  }
1516  catch (InterruptedException e) {
1517  cursorOn = true;
1518  repaint();
1519  }
1520  checkAbort();
1521  }
1522  cursorOn = false;
1523  repaint();
1524  }
1525  buffer = inputBuffer + (char)10;
1526  pos = 1;
1527  return buffer.charAt(0);
1528  }
1529  }
1530  }
1531 
1532  class COUT extends Writer { // "Standard output" is replaced in TextIO with an object of this type.
1533  public void write(int b) {
1534  write(new char[] { (char)(b & 0xFFFF) }, 0, 1);
1535  }
1536  public void write(char[] b, int offset, int length) {
1537  for (int i = offset; i < offset+length; i++) {
1538  putChar(b[i]);
1539  }
1540  }
1541  public void write(char[] b) {
1542  write(b,0,b.length);
1543  }
1544  public void close() {
1545  }
1546  public void flush() {
1547  }
1548  }
1549 
1550  } // end nested class Console
1551 
1552  //************************ Shared private member variables *************************
1553 
1554  private String inputFileName; // Name of file that is the current input source, or null if the source is not a file.
1555  private String outputFileName; // Name of file that is the current output destination, or null if the destination is not a file.
1556 
1557  private JFileChooser fileDialog; // Dialog used by readUserSelectedFile() and writeUserSelectedFile()
1558 
1559  private final BufferedReader standardInput; // wraps the input stream from Console. (Set in initializer.)
1560  private final PrintWriter standardOutput; // wraps the output stream. (Set in initializer.)
1561 
1562  private BufferedReader in; // Stream that data is read from; the current input source. (Set in initializer.)
1563  private PrintWriter out; // Stream that data is written to; the current output destination. (Set in initializer.)
1564 
1565  private boolean readingStandardInput = true;
1566  private boolean writingStandardOutput = true;
1567 
1568  private int inputErrorCount; // Number of consecutive errors on standard input; reset to 0 when a successful read occurs.
1569  private int outputErrorCount; // Number of errors on standard output since it was selected as the output destination.
1570 
1571  private Matcher integerMatcher; // Used for reading integer numbers; created from the integer Regex Pattern.
1572  private Matcher floatMatcher; // Used for reading floating point numbers; created from the floatRegex Pattern.
1573  private final Pattern integerRegex = Pattern.compile("(\\+|-)?[0-9]+");
1574  private final Pattern floatRegex = Pattern.compile("(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?");
1575 
1576  private String buffer = null; // One line read from input.
1577  private int pos = 0; // Position of next char in input line that has not yet been processed.
1578 
1579  private Console console; // The GUI IO widget used for simulated input/output.
1580 
1581 
1582 
1583 } // end of class TextIO
TextIOApplet.TextIOObject.getBoolean
boolean getBoolean()
Skips whitespace characters and then reads a value of type boolean from input.
Definition: TextIOApplet.java:1073
TextIO.writeStandardOutput
static void writeStandardOutput()
After this method is called, output will be written to standard output (as it is in the default state...
Definition: TextIO.java:195
TextIOApplet.getTitle
String getTitle()
This returns the message that is currently displayed at the top of the applet.
Definition: TextIOApplet.java:95
TextIOApplet.TextIOObject.getlnDouble
double getlnDouble()
Skips whitespace characters and then reads a value of type double from input, discarding the rest of ...
Definition: TextIOApplet.java:854
TextIOApplet.TextIOObject.skipBlanks
void skipBlanks()
Skips over any whitespace characters, except for end-of-lines.
Definition: TextIOApplet.java:762
TextIOApplet.TextIOObject.getlnLong
long getlnLong()
Skips whitespace characters and then reads a value of type long from input, discarding the rest of th...
Definition: TextIOApplet.java:830
TextIOApplet.TextIOObject.getFloat
float getFloat()
Skips whitespace characters and then reads a value of type float from input.
Definition: TextIOApplet.java:982
TextIOApplet.TextIOObject.getShort
short getShort()
Skips whitespace characters and then reads a value of type short from input.
Definition: TextIOApplet.java:941
TextIOApplet.TextIOObject.peek
char peek()
Returns the next character in the current input source, without actually removing that character from...
Definition: TextIOApplet.java:752
TextIOApplet.TextIOObject.getlnShort
short getlnShort()
Skips whitespace characters and then reads a value of type short from input, discarding the rest of t...
Definition: TextIOApplet.java:806
TextIOApplet.inputFileName
String inputFileName
Definition: TextIOApplet.java:1554
TextIOApplet.TextIOObject.readStream
void readStream(Reader inputStream)
After this method is called, input will be read from inputStream, provided it is non-null.
Definition: TextIOApplet.java:362
TextIOApplet.programIsRunning
volatile boolean programIsRunning
Definition: TextIOApplet.java:183
TextIOApplet.ProgRun.run
void run()
Definition: TextIOApplet.java:244
TextIOApplet.TextIOObject.readChar
char readChar()
Definition: TextIOApplet.java:1201
TextIOApplet.checkAbort
void checkAbort()
When the user presses the "Abort Program" button, it does not actually stop the program; it merely se...
Definition: TextIOApplet.java:141
TextIOApplet.TextIOObject.EOF
final char EOF
The value returned by the peek() method when the input is at end-of-file.
Definition: TextIOApplet.java:314
TextIOApplet.pos
int pos
Definition: TextIOApplet.java:1577
TextIOApplet.runAgainButton
JButton runAgainButton
Definition: TextIOApplet.java:185
TextIOApplet.BogusSystem.exit
void exit(int ignored)
Definition: TextIOApplet.java:172
TextIOApplet.BogusSystem
A class for implementing the "System.out/System.in" kludge.
Definition: TextIOApplet.java:166
TextIOApplet.TextIOObject.getlnInt
int getlnInt()
Skips whitespace characters and then reads a value of type int from input, discarding the rest of the...
Definition: TextIOApplet.java:818
TextIOApplet.TextIOObject.writeStream
void writeStream(OutputStream outputStream)
After this method is called, output will be sent to outputStream, provided it is non-null.
Definition: TextIOApplet.java:485
TextIOApplet.outputFileName
String outputFileName
Definition: TextIOApplet.java:1555
TextIOApplet.TextIOObject.writeStandardOutput
void writeStandardOutput()
After this method is called, output will be written to standard output (as it is in the default state...
Definition: TextIOApplet.java:464
TextIOApplet.floatMatcher
Matcher floatMatcher
Definition: TextIOApplet.java:1572
TextIOApplet.TextIOObject.readInteger
long readInteger(long min, long max)
Definition: TextIOApplet.java:1129
TextIOApplet.TextIOObject.putln
void putln(Object x, int minChars)
This is equivalent to put(x,minChars), followed by an end-of-line.
Definition: TextIOApplet.java:672
TextIOApplet.TextIOObject.readFile
void readFile(String fileName)
Opens a file with a specified name for input.
Definition: TextIOApplet.java:386
TextIOApplet.TextIOObject.getByte
byte getByte()
Skips whitespace characters and then reads a value of type byte from input.
Definition: TextIOApplet.java:931
TextIOApplet.standardOutput
final PrintWriter standardOutput
Definition: TextIOApplet.java:1560
TextIOApplet.doDelay
void doDelay(int milliseconds)
You can call this to insert a delay of a specified number of milliseconds into your program.
Definition: TextIOApplet.java:116
TextIOApplet.TextIOObject.putln
void putln()
Write an end-of-line character to the current output destination.
Definition: TextIOApplet.java:683
TextIOApplet.integerRegex
final Pattern integerRegex
Definition: TextIOApplet.java:1573
TextIOApplet.TextIOObject.readIntegerString
String readIntegerString()
Definition: TextIOApplet.java:1113
TextIOApplet.Console.putString
synchronized void putString(String str)
Definition: TextIOApplet.java:1406
TextIOApplet.TextIOObject.getlnWord
String getlnWord()
Skips whitespace characters and then reads one "word" from input, discarding the rest of the current ...
Definition: TextIOApplet.java:895
TextIOApplet.TextIOObject.putln
void putln(Object x)
This is equivalent to put(x), followed by an end-of-line.
Definition: TextIOApplet.java:662
TextIOApplet.TextIOObject.skipWhitespace
void skipWhitespace()
Skips over any whitespace characters, including for end-of-lines.
Definition: TextIOApplet.java:776
TextIOApplet.TextIOObject.readStandardInput
void readStandardInput()
After this method is called, input will be read from standard input (as it is in the default state).
Definition: TextIOApplet.java:328
TextIOApplet.TextIOObject.getlnBoolean
boolean getlnBoolean()
Skips whitespace characters and then reads a value of type boolean from input, discarding the rest of...
Definition: TextIOApplet.java:882
TextIOApplet.TextIOObject.errorMessage
void errorMessage(String message, String expecting)
Definition: TextIOApplet.java:1160
TextIOApplet.aborted
volatile boolean aborted
Definition: TextIOApplet.java:182
TextIOApplet.TextIOObject.getAnyChar
char getAnyChar()
Reads the next character from the current input source.
Definition: TextIOApplet.java:741
TextIOApplet.TextIOObject.getWord
String getWord()
Skips whitespace characters and then reads one "word" from input.
Definition: TextIOApplet.java:1053
TextIOApplet.buffer
String buffer
Definition: TextIOApplet.java:1576
TextIOApplet.inputErrorCount
int inputErrorCount
Definition: TextIOApplet.java:1568
TextIOApplet.in
BufferedReader in
Definition: TextIOApplet.java:1562
TextIOApplet.TextIOObject.getInputFileName
String getInputFileName()
If TextIO is currently reading from a file, then the return value is the name of the file.
Definition: TextIOApplet.java:609
TextIOApplet.TextIOObject.emptyBuffer
void emptyBuffer()
Definition: TextIOApplet.java:1232
TextIOApplet.TextIOObject.getln
String getln()
Reads all the characters from the current input source, up to the next end-of-line.
Definition: TextIOApplet.java:915
TextIOApplet.TextIOObject.writeFile
void writeFile(String fileName)
Opens a file with a specified name for output.
Definition: TextIOApplet.java:523
TextIOApplet.readingStandardInput
boolean readingStandardInput
Definition: TextIOApplet.java:1565
TextIOApplet.TextIOObject.getChar
char getChar()
Skips whitespace characters and then reads a single non-whitespace character from input.
Definition: TextIOApplet.java:971
TextIOApplet.TextIOObject.getDouble
double getDouble()
Skips whitespace characters and then reads a value of type double from input.
Definition: TextIOApplet.java:1017
TextIOApplet.TextIOObject.getInt
int getInt()
Skips whitespace characters and then reads a value of type int from input.
Definition: TextIOApplet.java:951
TextIOApplet.TextIOObject.eof
boolean eof()
Test whether the next character in the current input source is an end-of-file.
Definition: TextIOApplet.java:729
TextIOApplet.TextIOObject.eoln
boolean eoln()
Test whether the next character in the current input source is an end-of-line.
Definition: TextIOApplet.java:720
TextIOApplet.runner
volatile Thread runner
Definition: TextIOApplet.java:181
TextIOApplet.floatRegex
final Pattern floatRegex
Definition: TextIOApplet.java:1574
TextIOApplet.TextIOObject.getlnString
String getlnString()
This is identical to getln().
Definition: TextIOApplet.java:904
TextIOApplet.integerMatcher
Matcher integerMatcher
Definition: TextIOApplet.java:1571
TextIOApplet.standardInput
final BufferedReader standardInput
Definition: TextIOApplet.java:1559
TextIOApplet.init
void init()
Creates and starts the program running thread when the applet is inited.
Definition: TextIOApplet.java:298
TextIOApplet.TextIOObject.getlnByte
byte getlnByte()
Skips whitespace characters and then reads a value of type byte from input, discarding the rest of th...
Definition: TextIOApplet.java:794
TextIOApplet.TextIOObject.readRealString
String readRealString()
Definition: TextIOApplet.java:1097
TextIOApplet.TextIOObject
The TextIO member variable refers to an object of this class, which implements all the functionality ...
Definition: TextIOApplet.java:308
TextIO
TextIO provides a set of static methods for reading and writing text.
Definition: TextIO.java:34
TextIOApplet.abortButton
JButton abortButton
Definition: TextIOApplet.java:186
TextIOApplet.message
JLabel message
Definition: TextIOApplet.java:187
TextIOApplet.AbortException
The applet includes an "Abort Program" button.
Definition: TextIOApplet.java:153
TextIO.readStandardInput
static void readStandardInput()
After this method is called, input will be read from standard input (as it is in the default state).
Definition: TextIO.java:59
TextIOApplet.TextIOObject.fillBuffer
void fillBuffer()
Definition: TextIOApplet.java:1213
TextIOApplet.TextIOApplet
TextIOApplet()
Definition: TextIOApplet.java:189
TextIOApplet.setTitle
void setTitle(String title)
This sets the message that is displayed at the top of the applet.
Definition: TextIOApplet.java:105
TextIOApplet.TextIO
TextIOObject TextIO
This is the object that takes the place of the usual TextIO class.
Definition: TextIOApplet.java:72
TextIOApplet.System
BogusSystem System
This is the object that your program is referring to when it says "System.out" or "System....
Definition: TextIOApplet.java:81
TextIOApplet.writingStandardOutput
boolean writingStandardOutput
Definition: TextIOApplet.java:1566
TextIOApplet.TextIOObject.readStream
void readStream(InputStream inputStream)
After this method is called, input will be read from inputStream, provided it is non-null.
Definition: TextIOApplet.java:349
TextIOApplet.TextIOObject.getlnChar
char getlnChar()
Skips whitespace characters and then reads a value of type char from input, discarding the rest of th...
Definition: TextIOApplet.java:867
TextIOApplet.TextIOObject.putf
void putf(String format, Object... items)
Writes formatted output values to the current output destination.
Definition: TextIOApplet.java:699
TextIOApplet.console
Console console
Definition: TextIOApplet.java:1579
TextIOApplet.TextIOObject.getOutputFileName
String getOutputFileName()
If TextIO is currently writing to a file, then the return value is the name of the file.
Definition: TextIOApplet.java:618
TextIOApplet.TextIOObject.EOLN
final char EOLN
The value returned by the peek() method when the input is at end-of-line.
Definition: TextIOApplet.java:320
TextIOApplet.Console
A "Console" is a panel which simulates standard input/output.
Definition: TextIOApplet.java:1264
TextIOApplet.out
PrintWriter out
Definition: TextIOApplet.java:1563
TextIOApplet.BogusSystem.currentTimeMillis
long currentTimeMillis()
Definition: TextIOApplet.java:169
TextIOApplet
An abstract base class for writing applets that simulate programs that use TextIO or standard I/O.
Definition: TextIOApplet.java:46
TextIOApplet.runProgram
abstract void runProgram()
A subclass must override this method.
TextIOApplet.TextIOObject.getlnFloat
float getlnFloat()
Skips whitespace characters and then reads a value of type float from input, discarding the rest of t...
Definition: TextIOApplet.java:842
TextIOApplet.Console.paintComponent
void paintComponent(Graphics g)
Definition: TextIOApplet.java:1337
TextIOApplet.TextIOObject.outputError
void outputError(String message)
Definition: TextIOApplet.java:1236
TextIOApplet.outputErrorCount
int outputErrorCount
Definition: TextIOApplet.java:1569
TextIOApplet.TextIOObject.put
void put(Object x, int minChars)
Write a single value to the current output destination, using the default format and outputting at le...
Definition: TextIOApplet.java:648
TextIOApplet.fileDialog
JFileChooser fileDialog
Definition: TextIOApplet.java:1557
TextIOApplet.TextIOObject.writeStream
void writeStream(PrintWriter outputStream)
After this method is called, output will be sent to outputStream, provided it is non-null.
Definition: TextIOApplet.java:498
TextIOApplet.TextIOObject.writeUserSelectedFile
boolean writeUserSelectedFile()
Puts a GUI file-selection dialog box on the screen in which the user can select an output file.
Definition: TextIOApplet.java:560
TextIOApplet.TextIOObject.getLong
long getLong()
Skips whitespace characters and then reads a value of type long from input.
Definition: TextIOApplet.java:961
TextIOApplet.TextIOObject.put
void put(Object x)
Write a single value to the current output destination, using the default format and no extra spaces.
Definition: TextIOApplet.java:630
TextIOApplet.TextIOObject.readUserSelectedFile
boolean readUserSelectedFile()
Puts a GUI file-selection dialog box on the screen in which the user can select an input file.
Definition: TextIOApplet.java:428
TextIOApplet.TextIOObject.lookChar
char lookChar()
Definition: TextIOApplet.java:1190
TextIOApplet.getDefaultAppletTitle
String getDefaultAppletTitle()
The return value of this method is used as the initial message that appears at the top of the applet.
Definition: TextIOApplet.java:88
TextIOApplet.ProgRun
Definition: TextIOApplet.java:243