any operation with text area is not working,,,cant find bug...
import java.io.*;
import javax.swing.JMenu;
import java.io.FileWriter;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JSeparator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollBar;
//import javax.swing.JPopupMenu;
import java.awt.Container;
//import javax.swing.JFlowLayout;
import javax.swing.JScrollPane;
import java.awt.Color;
import java.awt.Font;
import java.awt.FlowLayout;
import javax.swing.JFileChooser;
import javax.swing.JColorChooser;
class Notepad extends JFrame implements ActionListener{
JMenu file;
JMenu edit ;
JMenu format ;
JMenu view;
JMenu help;
JMenuBar jb;
JMenuItem New ;
JMenuItem open;
JMenuItem save;
JMenuItem save1;
JMenuItem ps ;
JMenuItem print ;
JMenuItem exit;
JMenuItem undo;
JMenuItem cut;
JMenuItem copy;
JMenuItem paste;
JMenuItem delete;
JMenuItem find;
JMenuItem fnext;
JMenuItem replace;
JMenuItem gto;
JMenuItem sall;
JMenuItem tdate;
JMenuItem wwrap;
JMenuItem fon;
JMenuItem sbar;
JMenuItem vhelp;
JMenuItem anp;
JTextArea ja;
JScrollPane jsp;
JFileChooser jfc;
JColorChooser jcc;
//JPopupMenu popup;
Notepad(){
//JFrame jf= new JFrame("Program-Notepad");
//setLayout(new JFlowLayout());
//this.setLayout(new FlowLayout());
Container ct= this.getContentPane();
jb= new JMenuBar();
setJMenuBar(jb);
file = new JMenu("File");
edit = new JMenu("Edit");
format = new JMenu("Format");
view= new JMenu("View");
help= new JMenu("Help");
jb.add(file);
jb.add(edit);
jb.add(format);
jb.add(view);
jb.add(help);
New =new JMenuItem("New");
open =new JMenuItem("Open");
save =new JMenuItem("Save");
save1=new JMenuItem("Save AS");
ps =new JMenuItem("Page Setup");
print =new JMenuItem("Print");
exit=new JMenuItem("Exit");
file.add(New);
file.add(open);
file.add(save);
file.add(save1);
file.add(ps);
file.add(print);
file.add(exit);
undo=new JMenuItem("Undo");
cut=new JMenuItem("Cut");
copy=new JMenuItem("Copy");
paste=new JMenuItem("Paste");
delete=new JMenuItem("Delete");
find=new JMenuItem("Find");
fnext=new JMenuItem("Find Next");
replace=new JMenuItem("Replace");
gto=new JMenuItem("Goto");
sall=new JMenuItem("Select All");
tdate=new JMenuItem("Time/Date");
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(delete);
edit.add(find);
edit.add(fnext);
edit.add(find);
edit.add(fnext);
edit.add(replace);
edit.add(gto);
edit.add(sall);
edit.add(tdate);
JMenuItem wwrap=new JMenuItem("Word Wrap");
JMenuItem fon=new JMenuItem("Font..");
format.add(wwrap);
format.add(fon);
JMenuItem sbar=new JMenuItem("Status Bar");
view.add(sbar);
JMenuItem vhelp=new JMenuItem("View Help");
JMenuItem anp=new JMenuItem("About Notepad");
help.add(vhelp);
help.add(anp);
New.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
new Notepad();
}
});
//open.addActionListener(this);
//save.addActionListener(this);
//save1.addActionListener(this);
//ps.addActionListener(this);
//print.addActionListener(this);
exit.addActionListener(this);
sall.addActionListener(this);
copy.addActionListener(this);
cut.addActionListener(this);
paste.addActionListener(this);
open.addActionListener(this);
fon.addActionListener(this);
jfc= new JFileChooser();
jcc= new JColorChooser();
/*open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
//jfc.showOpenDialog(this);
}
});*/
save.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
}
}
);
save1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
}
}
);
ps.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(e.getActionCommand());
}
}
);
JTextArea ja= new JTextArea();
add(ja);
//jsp = new JScrollPane(this.ja);
//ct.add(jsp);
setTitle("Program-Notepad");
setVisible(true);
setSize(1024,768);
//setExtendedState(JFrame.MAXIMIZED_BOTH);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==sall){
System.out.println(e.getActionCommand());
System.out.println(ja.getText());
ja.selectAll();
}
if (e.getSource()==exit){
System.out.println(e.getActionCommand());
System.exit(0);
}
if (e.getSource()==copy){
System.out.println(e.getActionCommand());
ja.copy();
}
if (e.getSource()==cut){
System.out.println(e.getActionCommand());
ja.cut();
}
if (e.getSource()==paste){
System.out.println(e.getActionCommand());
ja.paste();
}
if (e.getActionCommand()=="Font.."){
System.out.println(e.getActionCommand());
Color c=jcc.showDialog(this,"ColorDailog",Color.red);
ja.setForeground(c);
}
if (e.getSource()==open){
System.out.println(e.getActionCommand());
jfc.showOpenDialog(this);
try{
/* FileReader fr=new FileReader(jfc.getSelectedFile());
BufferedReader br=new BufferedReader(fr);
ja.setText("");
String data="";
while((data=br.readLine())!=null)
{
ja.append(data+"\n");
}
fr.close();*/
}
catch(Exception e1)
{
System.out.println("error in reading "+e1);
}
}
}
}
public class Test$10{
public static void main(String args[]){
System.out.println("Notepad program");
new Notepad();
}
}