Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Creating a RMI text editor???

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
    Bookmark Topic Watch Topic
  • New Topic