[Image]

Editor

Can open a file in a text-editor box.  The user can make changes, then save the file and view it.  This could be used as a code editor for HTML files.


Important Commands

extends EasyIO
EasyIO extends Frame, and adds the IBIO Input/Output methods, as well as enabling the close-application button [x].

aEditor.setFont(new Font("Monospaced",0,12));
Changes the font in the Editor box to a fixed-pitch font (Courier).

public String chooseFile()
The method returns a String - this means it is a User-Defined Function.

JFileChooser fileChooser = new JFileChooser();
Use the standard file-chooser dialog to find a file-name.


BufferedReader textFile = 
 new 
BufferedReader(new FileReader(fileName));

Opens a file for reading (normally a text-file).

PrintWriter textFile =
 new PrintWriter(new FileWriter(fileName));

Opens a file writing (normally a text-file).

output("Save failed \n" + e.toString());}
Use \n to force a new-line in text output.

Runtime.getRuntime().exec("explorer.exe " + fileName);
Runs explorer.exe and loads and displays filename - only works in Windows.


Comments

This class will only compile if you also have EasyIO.java (or EasyIO.class) available.  

This is not a "real" editor - it needs a lot more safety features.

The readFile method reads the file one line at a time.  This is not necessary - it is possible to read the entire file at once.  This code is provided as an example of how to read a text file line by line.

The saveFile saves the entire text with a single command.  It is also possible to write into the file one line at a time, using .println.  But in this case that would be difficult, as the text is only available as one big String.