This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes Creating a RMI text editor??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Creating a RMI text editor???" Watch "Creating a RMI text editor???" New topic

Creating a RMI text editor???

Tien Fu Liu

Joined: Jun 22, 2003
Posts: 8
i need help to program a distributed text editor. This editor will be used concurrently by different users on different machines and having the same interface to everybody. people will have to agree on some actions while working on the text file

Following is a simple text editor java file
help will be very much appreciated!
import java.awt.*;
import java.awt.event.*;

public class SimpleEditor extends Frame implements ActionListener {
private MenuBar menuBar;
private Menu fileMenu;
private TextArea text;
private FileDialog fileDialog;
private String fileName;

public SimpleEditor() {
super("Simple Editor");

menuBar = new MenuBar();
fileMenu = new Menu("File");

fileMenu.add(new MenuItem("New"));
fileMenu.add(new MenuItem("Open"));
fileMenu.add(new MenuItem("Save"));
fileMenu.add(new MenuItem("Save as..."));
fileMenu.add(new MenuItem("Exit"));

fileDialog = new FileDialog(this);

text = new TextArea("",20,70,TextArea.SCROLLBARS_BOTH);
text.setFont(new Font("Courier", Font.PLAIN, 12)); // const. width font

// actionPerformed handles menu selections

public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("Exit")) {
else if(cmd.equals("Open")) {;
fileName = fileDialog.getDirectory()+fileDialog.getFile();
else if(cmd.equals("Save")) {
if(fileName == null) {;
fileName = fileDialog.getDirectory()+fileDialog.getFile();
else if(cmd.equals("Save as...")) {;
fileName = fileDialog.getDirectory()+fileDialog.getFile();
else if(cmd.equals("New")) {
fileName = null;

// Method to write the text in the TextArea to a specified file

private void writeFile(String filename) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
String data = text.getText();
} catch(IOException ioe) {
System.out.println("Exception " + ioe);

// Method to read and display a file in the TextArea

private void displayFile(String fileName) {
String line;
text.setText(""); // Set text area to `nothing'
try {
BufferedReader br = new BufferedReader(new FileReader(fileName));
line = br.readLine();
while(line != null) { // While we have valid lines of text
text.append(line+'\n'); // Append lines to TextArea + \n
line = br.readLine(); // ... and get next line

} catch(IOException ioe) {
System.out.println("Exception " + ioe);

public static void main(String args[]) {
SimpleEditor f = new SimpleEditor();
if(args.length == 1) { // If we have a filename specified
f.fileName = args[0];
f.displayFile(f.fileName); // load the file and display it
f.fileName = null;

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You're going to need to make some decisions about how you want this to be distributed... Do the files only really exist on a central server, or can any of the various users host files? How will you handle multiple users editing the same file or line? How and when will it be decided that a file will be saved permanently?

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Creating a RMI text editor???
It's not a secret anymore!