Create Notepad using Swing:-

0

Swing Provide Multiple Set of Component to Create Notepad


1 Menu:-  It provides option set to display multiple menus under the menu bar
2 MenuBar:-  It provides a complete strip to contain the menu
3 MenuItem:-  It will be displayed as a list when we click on the particular menu item
4 Textarea:-  It is used to write the multiple contents
Menu Item will use the ActionPerformed Event Method to perform the operation
Code to Save File:-
JFileChooser obj1=null;
                    try
        {
       
         if(this.getTitle().toString()=="")
        {
          obj1= new JFileChooser();
          obj1.showSaveDialog(this);
          path=obj1.getSelectedFile().getAbsolutePath();
          this.setTitle(obj1.getSelectedFile().getName());
        }
        File f = new File(path);
        FileWriter fw = new FileWriter(f);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(jTextArea1.getText());
        bw.close();
             }
        catch(IOException ex)
        {JFileChooser obj = new JFileChooser();
        obj.showOpenDialog(this);
         try
        {
        File f = new File(obj.getSelectedFile().getAbsolutePath());
        FileReader fr = new FileReader(f);
        BufferedReader br = new BufferedReader(fr);
        String data="";
        String s;
        while(( s= br.readLine())!=null)
        {
            data=data+s;
        }
        jTextArea1.setText(data);
        br.close();
        }
        catch(IOException ex)
        {
                   }
         }

Code to Open File:-
        JFileChooser obj = new JFileChooser();
        obj.showOpenDialog(this);
         try
        {
        File f = new File(obj.getSelectedFile().getAbsolutePath());
        FileReader fr = new FileReader(f);
        BufferedReader br = new BufferedReader(fr);
        String data="";
        String s;
        while(( s= br.readLine())!=null)
        {
            data=data+s;
        }
        jTextArea1.setText(data);
        br.close();
        }
        catch(IOException ex)
        {
                   }

Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)