answersLogoWhite

0

import java.awt.*;

import java.awt.event.*;

import java.awt.datatransfer.*;

import java.io.*;

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");

n.addActionListener(new New());

F.add(n);

o.addActionListener(new Open());

F.add(o);

s.addActionListener(new Save());

F.add(s);

e.addActionListener(new Exit());

F.add(e);

mb.add(F);

Menu E = new Menu("Edit");

MenuItem cut = new MenuItem("Cut");

MenuItem copy = new MenuItem("Copy");

MenuItem paste = new MenuItem("Paste");

cut.addActionListener(new Cut());

E.add(cut);

copy.addActionListener(new Copy());

E.add(copy);

paste.addActionListener(new Paste());

E.add(paste);

mb.add(E);

setMenuBar(mb);

mylistener mylist = new mylistener();

addWindowListener(mylist);

}

class mylistener extends WindowAdapter

{

public void windowClosing (WindowEvent e)

{

System.exit(0);

}

}

class New implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

tx.setText(" ");

setTitle(filename);

}

}

class Open implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

FileDialog fd = new FileDialog(Editor.this, "select File",FileDialog.LOAD);

fd.show();

if (fd.getFile()!=null)

{

filename = fd.getDirectory() + fd.getFile();

setTitle(filename);

ReadFile();

}

tx.requestFocus();

}

}

class Save implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

FileDialog fd = new FileDialog(Editor.this,"Save File",FileDialog.SAVE);

fd.show();

if (fd.getFile()!=null)

{

filename = fd.getDirectory() + fd.getFile();

setTitle(filename);

try

{

DataOutputStream d = new DataOutputStream(new FileOutputStream(filename));

String line = tx.getText();

BufferedReader br = new BufferedReader(new StringReader(line));

while((line = br.readLine())!=null)

{

d.writeBytes(line + "\r\n");

d.close();

}

}

catch(Exception ex)

{

System.out.println("File not found");

}

tx.requestFocus();

}

}

}

class Exit implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

}

void ReadFile()

{

BufferedReader d;

StringBuffer sb = new StringBuffer();

try

{

d = new BufferedReader(new FileReader(filename));

String line;

while((line=d.readLine())!=null)

sb.append(line + "\n");

tx.setText(sb.toString());

d.close();

}

catch(FileNotFoundException fe)

{

System.out.println("File not Found");

}

catch(IOException ioe){}

}

class Cut implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

String sel = tx.getSelectedText();

StringSelection ss = new StringSelection(sel);

clip.setContents(ss,ss);

tx.replaceRange(" ",tx.getSelectionStart(),tx.getSelectionEnd());

}

}

class Copy implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

String sel = tx.getSelectedText();

StringSelection clipString = new StringSelection(sel);

clip.setContents(clipString,clipString);

}

}

class Paste implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

Transferable cliptran = clip.getContents(Editor.this);

try

{

String sel = (String) cliptran.getTransferData(DataFlavor.stringFlavor);

tx.replaceRange(sel,tx.getSelectionStart(),tx.getSelectionEnd());

}

catch(Exception exc)

{

System.out.println("not string flavour");

}

}

}

public static void main(String args[])

{

Frame f = new Editor();

f.setSize(500,400);

f.setVisible(true);

f.show();

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

What kind of file contain java source code?

'.java' files contain java source code. One can access these files on windows by using 'notepad'.


How many editor in which you can create java source code?

Java source code is a plain text file, so you can use practically any editor, for example NotePad (included in Windows) or better programs such as the freeware NotePad++. However, it is usually more convenient to use the editor included in an IDE that has support for Java.


What is Java editor?

A Java editor is nothing but a tool that can be used to edit java source files. Ex: Textpad, Notepad, Eclipse etc...


Where does source code come from in java?

Source code comes from the programmer...


Why do you write your code in a Notepad file?

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.

Related Questions

What kind of file contain java source code?

'.java' files contain java source code. One can access these files on windows by using 'notepad'.


How many editor in which you can create java source code?

Java source code is a plain text file, so you can use practically any editor, for example NotePad (included in Windows) or better programs such as the freeware NotePad++. However, it is usually more convenient to use the editor included in an IDE that has support for Java.


What is Java editor?

A Java editor is nothing but a tool that can be used to edit java source files. Ex: Textpad, Notepad, Eclipse etc...


Where does source code come from in java?

Source code comes from the programmer...


Why do you write your code in a Notepad file?

Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.Notepad is a text editor. What it saves is the source code of the programming language. Any source code is just a text file, so Notepad or any text editor can save a program's code.


Is NotePad Plus Plus a compiler?

Notepad++ is a text editor, not a compiler. You can however, enter source code into Notepad++ and then compile it with a compiler such as GCC.


What does the Java compiler translate Java source code to?

The Java compiler translates Java source code to Java byte code.


Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java


How do you save a notepad file into a java file?

just add an extension .java when you save your notepad text file


Differencitate between source code and bytcode in java?

The source code is just the set of statements written in (any included) java language by a programer (in this case our source code is a text file with .java extension). And in other hand a bytecode is the resulting code of compile a .java file, It is not machine code, but it can be interpreted and executed by the jvm.


What does a compiler perform?

A compiler converts high-level source code into native machine. In the case of Java, source code is compiled to Java byte code suitable for interpretation by the Java virtual machine which produces the machine code.


Where does bytecode come from java?

It is created by the Java compiler, based on the source code (the .java file).