File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Creating a RMI text editor???" Watch "Creating a RMI text editor???" New topic
Author

Creating a RMI text editor???

Tien Fu Liu
Greenhorn

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.*;
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;

}
}
Nathan Pruett
Bartender

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?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a RMI text editor???
 
Similar Threads
How to keep formatting while reading files
sms gateway
adding a save method
notepad
Database connection