0% found this document useful (0 votes)
9 views9 pages

Java Text Editor with Clipboard Support

This document defines an Editor class that extends Frame and implements basic text editing functionality like opening, saving, and copying/pasting text. It includes inner classes to handle menu item actions for file operations like new, open, save, and exit. It also includes classes to handle clipboard copy/cut/paste operations on selected text in a TextArea widget. The main method creates an Editor frame to display the text area and menu bar.

Uploaded by

teenapal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Java Text Editor with Clipboard Support

This document defines an Editor class that extends Frame and implements basic text editing functionality like opening, saving, and copying/pasting text. It includes inner classes to handle menu item actions for file operations like new, open, save, and exit. It also includes classes to handle clipboard copy/cut/paste operations on selected text in a TextArea widget. The main method creates an Editor frame to display the text area and menu bar.

Uploaded by

teenapal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].*; import [Link].*; import [Link].*; import [Link].

*; public class Editor extends Frame { String filename; TextArea tx; Clipboard clip = getToolkit().getSystemClipboard(); Editor() { setLayout(new GridLayout(1,1)); tx = new TextArea(); add(tx); MenuBar mb = new MenuBar(); Menu F = new Menu("file"); MenuItem n = new MenuItem("New"); MenuItem o = new MenuItem("Open"); MenuItem s = new MenuItem("Save"); MenuItem e = new MenuItem("Exit"); [Link](new New()); [Link](n); [Link](new Open()); [Link](o); [Link](new Save());

[Link](s); [Link](new Exit()); [Link](e); [Link](F); Menu E = new Menu("Edit"); MenuItem cut = new MenuItem("Cut"); MenuItem copy = new MenuItem("Copy"); MenuItem paste = new MenuItem("Paste"); [Link](new Cut()); [Link](cut); [Link](new Copy()); [Link](copy); [Link](new Paste()); [Link](paste); [Link](E); setMenuBar(mb);

mylistener mylist = new mylistener(); addWindowListener(mylist); }

class mylistener extends WindowAdapter { public void windowClosing (WindowEvent e) {

[Link](0); } }

class New implements ActionListener { public void actionPerformed(ActionEvent e) { [Link](" "); setTitle(filename); } }

class Open implements ActionListener { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog([Link], "select File",[Link]); [Link](); if ([Link]()!=null) { filename = [Link]() + [Link](); setTitle(filename); ReadFile(); }

[Link](); } }

class Save implements ActionListener { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog([Link],"Save File",[Link]); [Link](); if ([Link]()!=null) { filename = [Link]() + [Link](); setTitle(filename); try { DataOutputStream d = new DataOutputStream(new FileOutputStream(filename)); String line = [Link](); BufferedReader br = new BufferedReader(new StringReader(line)); while((line = [Link]())!=null) { [Link](line + "\r\n"); [Link](); } }

catch(Exception ex) { [Link]("File not found"); } [Link](); } } }

class Exit implements ActionListener { public void actionPerformed(ActionEvent e) { [Link](0); } } void ReadFile() { BufferedReader d; StringBuffer sb = new StringBuffer(); try { d = new BufferedReader(new FileReader(filename)); String line; while((line=[Link]())!=null)

[Link](line + "\n"); [Link]([Link]()); [Link](); } catch(FileNotFoundException fe) { [Link]("File not Found"); } catch(IOException ioe){} }

class Cut implements ActionListener { public void actionPerformed(ActionEvent e) { String sel = [Link](); StringSelection ss = new StringSelection(sel); [Link](ss,ss); [Link](" ",[Link](),[Link]()); } }

class Copy implements ActionListener { public void actionPerformed(ActionEvent e)

{ String sel = [Link](); StringSelection clipString = new StringSelection(sel); [Link](clipString,clipString); } }

class Paste implements ActionListener { public void actionPerformed(ActionEvent e) { Transferable cliptran = [Link]([Link]); try { String sel = (String) [Link]([Link]); [Link](sel,[Link](),[Link]()); } catch(Exception exc) { [Link]("not string flavour"); } } }

public static void main(String args[])

{ Frame f = new Editor(); [Link](500,400); [Link](true); [Link](); } }

You might also like