Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

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)
        {
           

        }



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post