import [Link].
*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class Editor extends JFrame implements ActionListener {
JTextArea t;
JFrame f;
Editor() {
f = new JFrame("Editor");
// Text component
t = new JTextArea();
// Create a menubar
JMenuBar mb = new JMenuBar();
// Create a menu for File
JMenu m1 = new JMenu("File");
// Create menu items
JMenuItem mi1 = new JMenuItem("New");
JMenuItem mi2 = new JMenuItem("Open");
JMenuItem mi3 = new JMenuItem("Save");
JMenuItem mi9 = new JMenuItem("Print");
// Add action listener
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](mi1);
[Link](mi2);
[Link](mi3);
[Link](mi9);
// Create a menu for Edit
JMenu m2 = new JMenu("Edit");
// Create menu items
JMenuItem mi4 = new JMenuItem("Cut");
JMenuItem mi5 = new JMenuItem("Copy");
JMenuItem mi6 = new JMenuItem("Paste");
// Add action listener
[Link](this);
[Link](this);
[Link](this);
[Link](mi4);
[Link](mi5);
[Link](mi6);
JMenuItem mc = new JMenuItem("Close");
[Link](this);
[Link](m1);
[Link](m2);
[Link](mc);
[Link](mb);
[Link](t);
[Link](500, 500);
[Link](true); // Corrected to set the JFrame visible
}
// If a button is pressed
public void actionPerformed(ActionEvent e) {
String s = [Link]();
if ([Link]("Cut")) {
[Link]();
} else if ([Link]("Copy")) {
[Link]();
} else if ([Link]("Paste")) {
[Link]();
} else if ([Link]("Save")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");
// Invoke the showsSaveDialog function to show the save dialog
int r = [Link](null);
if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory
File fi = new File([Link]().getAbsolutePath());
try {
// Create a file writer
FileWriter wr = new FileWriter(fi, false);
// Create buffered writer to write
BufferedWriter w = new BufferedWriter(wr);
// Write
[Link]([Link]());
[Link]();
[Link]();
} catch (Exception evt) {
[Link](f, [Link]());
}
} else {
[Link](f, "The user cancelled the operation");
}
} else if ([Link]("Print")) {
try {
// Print the file
[Link]();
} catch (Exception evt) {
[Link](f, [Link]());
}
} else if ([Link]("Open")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");
// Invoke the showsOpenDialog function to show the open dialog
int r = [Link](null);
// If the user selects a file
if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory
File fi = new File([Link]().getAbsolutePath());
try {
// String
String s1 = "", sl = "";
// File reader
FileReader fr = new FileReader(fi);
// Buffered reader
BufferedReader br = new BufferedReader(fr);
// Initialize sl
sl = [Link]();
// Take the input from the file
while ((s1 = [Link]()) != null) {
sl = sl + "\n" + s1;
}
// Set the text
[Link](sl);
} catch (Exception evt) {
[Link](f, [Link]());
}
} else {
[Link](f, "The user cancelled the operation");
}
} else if ([Link]("New")) {
[Link]("");
} else if ([Link]("Close")) {
[Link](false);
}
}
// Main class
public static void main(String args[]) {
Editor e = new Editor();
}
}