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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Creating a RMI text editor???

 
Greenhorn
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.*;
import java.io.*;

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();
setMenuBar(menuBar);
fileMenu = new Menu("File");
menuBar.add(fileMenu);

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"));
fileMenu.addActionListener(this);

fileDialog = new FileDialog(this);

text = new TextArea("",20,70,TextArea.SCROLLBARS_BOTH);
text.setEditable(true);
text.setFont(new Font("Courier", Font.PLAIN, 12)); // const. width font
add(text);
pack();
show();
}

// actionPerformed handles menu selections

public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("Exit")) {
this.dispose();
System.exit(0);
}
else if(cmd.equals("Open")) {
fileDialog.show();
fileName = fileDialog.getDirectory()+fileDialog.getFile();
displayFile(fileName);
}
else if(cmd.equals("Save")) {
if(fileName == null) {
fileDialog.show();
fileName = fileDialog.getDirectory()+fileDialog.getFile();
}
writeFile(fileName);
}
else if(cmd.equals("Save as...")) {
fileDialog.show();
fileName = fileDialog.getDirectory()+fileDialog.getFile();
writeFile(fileName);
}
else if(cmd.equals("New")) {
text.setText("");
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();
bw.write(data);
bw.close();
} 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
}

br.close();
} 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
}
else
f.fileName = null;

}
}
 
Bartender
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic