package diary; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; public class Notepad implements ActionListener{ JFrame f; JMenuBar mb; JMenu file,edit,process; JMenuItem cut,copy,paste,selectAll,open,save,decrypt,encrypt; JLabel date; public JTextArea ta; int[] key = new int[3]; String[] res= new String[3]; String file_name = null; String kfile_name = null; String dir_diary = "D:/diary/"; String dir_key = "D:/Keys/"; String keys; String fil; Notepad(){ //Creating the Notepad file_name = dir_diary; kfile_name = dir_key; f=new JFrame("Notepad"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); cut=new JMenuItem("cut"); copy=new JMenuItem("copy"); paste=new JMenuItem("paste"); selectAll=new JMenuItem("selectAll"); save= new JMenuItem("save"); decrypt = new JMenuItem("Decrypt"); encrypt = new JMenuItem("Encrypt"); cut.addActionListener(this); copy.addActionListener(this); paste.addActionListener(this); selectAll.addActionListener(this); save.addActionListener(this); mb=new JMenuBar(); file=new JMenu("File"); edit=new JMenu("Edit"); process=new JMenu("Process"); //To display the date in the menubar //***FILE NAME OF THE DIARY CONTENT IS THE CURRENT DATE*** String la = "Date: "; la=la.concat(datedisplay()); date = new JLabel(la); open=new JMenuItem("Open File"); open.addActionListener(this); //Adding menuitems to menubar file.add(open);file.add(save); edit.add(cut);edit.add(copy);edit.add(paste);edit.add(selectAll); process.add(encrypt);process.add(decrypt); decrypt.setVisible(false); encrypt.addActionListener(this); decrypt.addActionListener(this); //Adding the menus to the menubar mb.add(file);mb.add(edit);mb.add(process); //Method to righ align the next menu mb.add(Box.createHorizontalGlue()); mb.add(date); //Setting the position of the menubar in the frame mb.setBounds(0,0,808,20); ta=new JTextArea(); ta.setBounds(2,20,810,500); //Method to wrap the exeding text ta.setLineWrap(true); //Adding the components to the frame f.add(mb);f.add(ta); f.setLayout(null); f.setSize(815,500); f.setResizable(false); } //Funtion to get the return the currentdate in DD/MM/YY format String datedisplay() { String date; Calendar c = Calendar.getInstance(); int day = c.get(Calendar.DATE); int month = c.get(Calendar.MONTH); //month count starts from 0 month+=1; int year = c.get(Calendar.YEAR); res[0] = Integer.toString(day); res[1] = Integer.toString(month); res[2] = Integer.toString(year); for(int i =0;i<3;i++) { //Generating the file name to store the cont file_name = file_name.concat(res[i]); } for(int i =0;i<3;i++) { //Generating the file name to store the encryptionkey kfile_name = kfile_name.concat(res[i]); } for(int i =1;i<3;i++) { res[0]= res[0].concat("/"); res[0]= res[0].concat(res[i]); } //res is dd/mm/yyyy return res[0]; } //Saving the textArea characters to the file void saver() throws IOException { String txt; Boolean b; int count; txt = ta.getText(); count = txt.length(); char[] c = new char[count]; c=txt.toCharArray(); file_name.concat(".txt"); File fi; fi = new File(file_name); if(!fi.exists()) try { b=fi.createNewFile(); } catch (IOException ex) { } //Note:FileWriter writes the text content as character to the file FileWriter writer = new FileWriter(fi); for(int i=0;i