import java.lang.*;import java.util.*;import java.io.*;import javax.swing.*;import java.awt.*;import javax.swing.filechooser.*;import java.awt.event.*;import java.awt.print.*;import javax.swing.JPanel;import javax.swing.event.CaretEvent;import javax.swing.event.CaretListener;import java.awt.event.ActionListener;import javax.swing.event.DocumentEvent;import java.awt.event.ItemListener;import java.awt.event.ItemEvent;import javax.swing.undo.CannotRedoException;import javax.swing.undo.CannotUndoException;import javax.swing.undo.UndoManager;import java.awt.EventQueue;import javax.swing.event.DocumentListener;import javax.swing.text.Document;public class NotePad extends JFrame implements ActionListener{ JFrame frame,frame2; JMenuBar mbar,t; JMenuItem x,y,u1,u2; JLabel lbl1; JButton btn1,btn2; JCheckBox q1; JPanel pane1,panel2,panel3; JComboBox ab,bb,cb; String se,p,a=”abc.txt”; String dirName = “herongswing”; String fileName = “editor.txt”; JEditorPane myPane = null; Scanner input; JScrollPane k; Scanner tcd=new Scanner(System.in); String chaList = new String1000; String ghaList = new String1000; JTextArea textArea; JMenu menu1,menu2,menu3,menu4,menu5,menu6; JMenuItem mitem1,mitem2,mitem3,mitem4,mitem5,mitem6,mitem7; JMenuItem mitem8,mitem9,mitem10,mitem11,mitem12,mitem13,mitem14,mitem15,mitem16,mitem17,mitem18; NotePad () { frame=new JFrame(“NOTE PAD”); textArea=new JTextArea(60,60); mbar=new JMenuBar(); menu1 = new JMenu(“File”);menu2 = new JMenu(“Edit”); menu3 = new JMenu(“Format”);menu4 = new JMenu(“View”);menu5 = new JMenu(“Help”); btn2=new JButton(“Enter”); redo=new JMenuItem(“REDO”); mI1=new JMenuItem(“New”);mI2=new JMenuItem(“Open”);mI3=new JMenuItem(“Save”); mI4=new JMenuItem(“SaveAs”);mI5=new JMenuItem(“Print”); panel1=new JPanel(new GridLayout(1,1,0,0)); mitem8=new JMenuItem(“Undo”);mitem9=new JMenuItem(“Cut”); mitem10=new JMenuItem(“Copy”);mitem11=new JMenuItem(“paste”); mitem12=new JMenuItem(“Delete”);mitem13=new JMenuItem(“Find”); mitem14=new JMenuItem(“Replace”);mitem15=new JMenuItem(“GO to”);mitem16=new JMenuItem(“Select all”); x=new JMenuItem(“Word rap”); y=new JMenuItem(“Font”); mI1.addActionListener(this);mI2.addActionListener(this);mI3.addActionListener(this); mI4.addActionListener(this);mI5.addActionListener(this); mitem8.addActionListener(this);mitem9.addActionListener(this); mitem10.addActionListener(this); mitem11.addActionListener(this); mitem12.addActionListener(this);mitem13.addActionListener(this); mitem14.addActionListener(this);mitem15.addActionListener(this); mitem16.addActionListener(this); x.addActionListener(this); y.addActionListener(this); btn2.addActionListener(this); q1=new JCheckBox(“Status bar”,true); u1=new JMenuItem(“View help”); u2=new JMenuItem(“About TextEditor”); u1.addActionListener(this); u2.addActionListener(this); q1.addActionListener(this); redo.addActionListener(this); textArea.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { try{ for(int i=0;i<=100;i++) { if(chaListi==null) { chaListi=t1.getText(); break; } } } catch(Exception u){}} public void removeUpdate(DocumentEvent e) { for(int i=0;i<=100;i++){ if(chaListi==null){ chaListi=textArea1.getText(); break; }}} public void changedUpdate(DocumentEvent e) { for(int i=0;i<=100;i++){ if(chaListi==null){ chaListi=textArea.getText(); break;}}}}); textArea.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }); mitem8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String toField= JOptionPane.showInputDialog("Find wprd"); String Field= JOptionPane.showInputDialog("Replace"); Document doc = t1.getDocument(); String text = doc.getText(0, doc.getLength()); int pos = 0; while ((pos = text.toUpperCase().indexOf(toField.toUpperCase(), pos)) >= 0) { int start = textArea.getText().indexOf(toField); textArea.replaceRange(Field,pos,pos+toField.length()); pos += toField.length(); } } catch (Exception e) {}}}); menu1.add(mI1);menu1.add(mI2);menu1.add(mI3); menu1.add(mI4);menu1.add(mI5); mbar.add(menu1);mbar.add(menu2); mbar.add(menu3);mbar.add(menu4);mbar.add(menu5); menu2.add(mitem8);menu2.add(mitem9); menu2.add(mitem10);menu2.add(mitem11); menu2.add(mitem12);menu2.add(mitem13); menu2.add(mitem14);menu2.add(mitem15); menu2.add(mitem16); menu3.add(r1); menu3.add(r2); menu4.add(q1); menu5.add(u1); menu5.add(u2); menu6.add(k1); panel1.add(mbar); panel3=new Panel(); frame.add(panel3,BorderLayout.PAGE_END); k=new JScrollPane(t1); k.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); textArea.setEditable(true); textArea.setVisible(true); frame.add(panel1); frame.add(k); frame.setSize(500,500); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel1,BorderLayout.PAGE_START); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(dirName)); chooser.setSelectedFile(new File(fileName)); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if(e.getSource()==mitem2){ try { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); input=new Scanner(new File(selectedFile.getName())); while(input.hasNext()) { p=input.next(); } textArea.setText(p); } } catch(IOException ioex){ System.out.println(ioex); }} if(e.getSource()==e6){ String color=”RED”;} f(e.getSource()==mitem6){ PrinterJob job = PrinterJob.getPrinterJob(); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (Exception ex) {} } } if(e.getSource()==mitem5){ } if(e.getSource()==mitem17){ textArea.selectAll(); } if(e.getSource()==mitem1) { String a=textArea.getText(); if(chaList0==null){ textArea.setText(“”); } else { String ch=JOptionPane.showInputDialog(“Do you want to save?”); if(ch.equals(“1″)) { try { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showSaveDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String text=textArea.getText(); FileWriter fw = new FileWriter(selectedFile+”.txt”); fw.write(text); fw.close(); } } catch(IOException ioex){ System.out.println(ioex);} } } } if(e.getSource()==mitem3) { try { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showSaveDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String text2=textArea.getText(); FileWriter fw = new FileWriter(selectedFile+”.txt”); fw.write(text2); fw.close(); } } catch(IOException ioex) { System.out.println(ioex); } } if(e.getSource()==u1) { JOptionPane.showMessageDialog(frame,”custom dialog”,JOptionPane.INFORMATION_MESSAGE);} if(e.getSource()==mitem12) { System.exit(0); } if(e.getSource()==mitem13) { textArea.setText(“”); } if(e.getSource()==mitem10) { textArea.cut(); } if(e.getSource()==u2){} if(e.getSource()==mitem11) { textArea.copy(); } if(e.getSource()==mitem12) { textArea.paste(); } if(e.getSource()==r1) { textArea.setWrapStyleWord(true); textArea.setLineWrap(true); } if(e.getSource()==mitem4) { try { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showSaveDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String a=textArea.getText(); FileWriter fw = new FileWriter(selectedFile+”.txt”); fw.write(a); fw.close(); } } catch(IOException ioex) { System.out.println(“NOt saved”); } } if(e.getSource()==q1) { if(q1.isSelected()==true) { lbl1.setEnabled(true); } if(q1.isSelected()==false) { lbl1.setEnabled(false); } } if(e.getSource()==mitem8) { try { for(int i=0;i<=100;i++) { if(chaListi==null&&T!=0) { int u=i-1; T=T+1; textArea.setText(chaListu); ghaListu=chaListu; chaListu=null; break; } if(chaListi==null&&T==0) { int u=i-2; T=T+1; textArea.setText(chaListu); ghaListu=chaListu; chaListu=null; break; } } } catch(IOException ioex){} System.out.println(k); } if(e.getSource()==redo) { try { for(int i=100;i>=0;i–) { if(ghaListi!=null) { int b=i; textArea.setText(ghaListb); } } } catch(Exception ek){} } if(e.getSource()==mitem18) { if(e.getSource()==r2) { String FontState = new String3; FontState0=”Regular”;FontState1=”underlined”;FontState2=”Bold”; String state; state=(String)JOptionPane.showInputDialog(frame, “Choose Font Style”, “Input”, JOptionPane.QUESTION_MESSAGE,null,FontState, “Arial”); String FontStyle = new String3; FontStyle0=”Arial”;FontStyle1=”TimesRoman”;FontStyle2=”Calibri”; String style; style=(String)JOptionPane.showInputDialog(frame, “Choose Font”, “Input”, JOptionPane.QUESTION_MESSAGE,null, FontStyle,”Arial”); Font font = new Font(style,Font.bold,w1); String FontSize = new String10; FontSize0=”2″;FontSize1=”4″;FontSize2=”8″;FontSize3=”16″;FontSize4=”18″;FontSize5=”20″;FontSize6=”22″;FontSize7=”24″;FontSize8=”26″;FontSize10=”28″; String size=(String)JOptionPane.showInputDialog(frame, “Enter Size”, “Input”, JOptionPane.QUESTION_MESSAGE,null,bList, “Arial”); size=”Font.”+size; int w1=Integer.parseInt(state); textArea.setFont(font); } if(e.getSource()==btn2) { String h=String.valueOf(cb); int w1=Integer.parseInt(h); String a=String.valueOf(ab); Font fon = new Font(“Broadway”,Font.ITALIC,18); textArea.setFont(fon); frame2.setVisible(false); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } if(e.getSource()==textArea) { CaretListener listener = new CaretListener() { public void caretUpdate(CaretEvent caretEvent) { System.out.println(“dot:”+ caretEvent.getDot()); System.out.println(“mark”+caretEvent.getMark()); } }; textArea.addCaretListener(listener); } } public static void main(String aa){ NotePad np = new NotePad(); } }