Home Answers Viewqa Java-Beginners save and open jmenu item

 
 


MANOJKUMAR
save and open jmenu item
1 Answer(s)      11 months ago
Posted in : Java Beginners

How to create a save and open jmenu item in java desktop application.

View Answers

June 14, 2012 at 5:28 PM


Here is a simple JMenuItem example in java swing through which you can perform open and save operations on File.

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class SwingMenu{
    final JTextArea txtArea=new JTextArea(0,0); 
    JFrame frame = new JFrame();
    String Filename;
    String filename;
  public static void main(String[] args) {
  SwingMenu s = new SwingMenu();
  }
   void ReadFile()
         {
         BufferedReader d;
         StringBuffer sb = new StringBuffer();
         try
             {
             d = new BufferedReader(new FileReader(filename));
             String line;
             while((line=d.readLine())!=null)
             sb.append(line + "\n");
             txtArea.setText(sb.toString());
             d.close();
         }
         catch(FileNotFoundException fe)
             {
             System.out.println("File not Found");
         }
         catch(IOException ioe){}
     }

  public SwingMenu(){


   JScrollPane scroll=new JScrollPane(txtArea);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JMenuBar menubar = new JMenuBar();
  JMenu filemenu = new JMenu("File");
  JMenuItem fileItem1 = new JMenuItem("Open");
  JMenuItem fileItem2 = new JMenuItem("Save");
  filemenu.add(fileItem1);
  filemenu.add(fileItem2);
  menubar.add(filemenu);

      fileItem1.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e)
             {
             FileDialog fd = new FileDialog(frame, "select File",FileDialog.LOAD);
             fd.show();
             if (fd.getFile()!=null)
                 {
                 filename = fd.getDirectory() + fd.getFile();
                 frame.setTitle(filename);
                 ReadFile();
             }
             txtArea.requestFocus();
         }
      });


      fileItem2.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e)
             {
             FileDialog fd = new FileDialog(frame,"Save File",FileDialog.SAVE);
             fd.show();
             if (fd.getFile()!=null)
                 {
                 filename = fd.getDirectory() + fd.getFile();
                 frame.setTitle(filename);
                 try
                     {
                     DataOutputStream d = new DataOutputStream(new FileOutputStream(filename));
                     String line = txtArea.getText();
                     BufferedReader br = new BufferedReader(new StringReader(line));
                     while((line = br.readLine())!=null)
                         {
                         d.writeBytes(line + "\r\n");

                     }
                     d.close();
                 }
                 catch(Exception ex)
                     {
                     System.out.println("File not found");
                 }
                 txtArea.requestFocus();
             }
         }
          });

  frame.setJMenuBar(menubar);
  frame.add(txtArea);
  frame.setSize(400,400);
  frame.setVisible(true);
  }
}









Related Pages:
save excel file with save and open dilog box
save excel file with save and open dilog box  following is my jsp code it is working correct.. i want to save excel file throgh jsp bt not by hard...");) user should have freedom to save the file in any location so plz give me
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try the following code: import java.sql.*; import javax.swing.*; import
retaining save dialog box even after clicking save button - Java Beginners
when i open save dialog box and input a file name that is already present... get it back??(even if i cal save dialog box again it would open again from...retaining save dialog box even after clicking save button  I am
Java JComboBox Get Selected Item Value
in the corresponding columns and to save the table try to close the open window it will ask...Java JComboBox Get Selected Item Value In this section we will discuss about how to get the selected item value form JComboBox. javax.swing.JComboBox
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog
How to save data - Swing AWT
How to save data  Hi, I have a problem about how to save data ,but first before data save to dababase, data must view in jLisit or Jtable... save data from jList and Jtable(in jList or jTable data will be many).Thank's
how to capture IE browser FileDownload box open ,save and cancel event - JSP-Servlet
how to capture IE browser FileDownload box open ,save and cancel event  I have a JSP page which allows user to download a file.When user click... to capture open,save and cancel event of filedownload box in javascript. Please
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when...()) { FileItem item = (FileItem) itr.next(); if (item.isFormField
open source help desk
Open Source Help Desk Open Source Help Desk Software As my help desk... of the major open source help desk software offerings. I?m not doing... or two. What I?m really looking to do is build relationships with the best open
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using QTP
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using... Flex controls. But i am not able to select any item from Spark Combo Box. I tied using .Open (Its not opening the drop down list) , also i tried using Select
Open Source HTML
Open Source HTML HTML Tidy Library Project A quorum... that you need to work on yourself. Each item found is listed with the line...;   Open Source HTML Parsers in Java NekoHTML is a simple HTML
Open Source Windows
Open Source Windows      ...; Gnucleus Gnucleus was the beginning of a few open-source Gnutella related... for new devices.   Open Offece.org OpenOffice.org 2 is the leading
delete an item from database
delete an item from database  how to delete an item from the database using jsp
Open Source VoIP
Open Source VoIP/TelePhony Open source VoIP/Telephony One of the first open source VoIP projects -and one of the earliest VoIP PBXes... for the platform, both commercial and open source.     
Dojo Menu and Menu Item
Dojo Menu and Menu Item     ...; function save_function() {   alert("Save Button");   }   function save_as_function(choice) 
Dojo Menu and Menu Item
Dojo Menu and Menu Item     ...; function save_function() {   alert("Save Button");   }   function save_as_function(choice) 
Item renderer in flex
Item renderer in flex  Hi...... please tell me about How to create item renderers in flex? give an example for that Thanks
Dojo Menu and Menu Item
Dojo Menu and Menu Item        ... it in dojo. Try Online: Menu and Menu Item Menu : This is the widget models...; function save_function() {   alert("Save 
navigation item back button
navigation item back button  I wants to add a navigationBar on the top of my UIWebView also a navigation item "back button". can anyone please explain how the back and refresh button works
Item renderer in flex
Item renderer in flex  Hi..... How does item renderer work? How do I add item renderer at runtime? Please me the right answer so i cam implement this in my apps. Thanks  Ans: The base class for Spark item
Item renderer in flex
Item renderer in flex  Hi... Please tell me about what does listData contain in ItemRenderers? What is the Type of listData? please give an example for that........ Thanks
Item renderer in flex
Item renderer in flex  Hi..... I have a problem How do you call a method in particular ItemRenderer. Also the ItemRenderer is your own Custom Component? please give me an example for that...... Thanks
highlight menu item html
highlight menu item html  highlight menu item in html or CSS   <body id="index"> <div id="menu"> <ul> <li class="index" ><a href="index.html">Index page</a></li> <
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code: import java.awt.*; import javax.swing.... index = list.locationToIndex(event.getPoint()); CheckListItem item
Open The Default Editor to Edit the File
Open The Default Editor to Edit the File   ... of opening the file in the default editor to edit and save the file. Here... the things that helps to open the file in the default editor to edit the file. When
Open Source e-commerce
Open Source e-commerce Open Source Online Shop E-Commerce Solutions Open source Commerce is an Open... of an osCommerce online store. osCommerce combines Open Source solutions to provide a free
MIT Open Source
MIT Open Source Open Source at MIT The goal of this project is to provide a central location for storing, maintaining and tracking Open Source... open-source story brings bloggers in Wouldn't you know it? I finally caught
Hibernate save()
This tutorial explain how save() works in hibernate
Open Source Workflow Engines in Java
Open Source Workflow Engines in Java The Open For Business Project: Workflow Engine Guide The Open for Business Workflow Engine is based on the WfMC and OMG... upon restart. Open Source Graphical XPDL Java Workflow Editor Enhydra JaWE (Java
upload and save the file
upload and save the file  upload and save a file from a computer to specific location of remote computer using jsp
awt list item* - Swing AWT
awt list item*  how do i make an item inside my listitem not visible  Hi friend, import java.awt.*; import java.awt.event.*; public class ChoiceListDemo{ public static void main(String[] args) { Frame
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please... save to database from JButton.Please give me a tutorial and source code...[]) { try{ // Open the file that is the first // command line parameter
Regarding GUI Applications
open jmenu item in java  How to create a save and open jmenu item... in java swing through which you can perform open and save operations on File. import...("Open"); JMenuItem fileItem2 = new JMenuItem("Save"); filemenu.add(fileItem1
How to store JComboBox item into database
How to store JComboBox item into database   import...(javax.swing.SwingConstants.CENTER); jLabel2.setText("Item Code"); getContentPane().add(jLabel2,new...); jLabel3.setText("Item Name"); getContentPane().add(jLabel3,new AbsoluteConstraints(27
Regarding GUI Applications
jmenu item in java desktop application  How to create a save and open jmenu item in java desktop application.   Here is a simple JMenuItem example in java swing through which you can perform open and save operations
Open Source Download
Open Source Download Downloads - UNIX & Open Source A modification of the free/open source GNU Image Manipulation Program (GIMP), intended..., etc. remain available.     The official AWeb Open Source
Item Events in Java
Item Events in Java       Introduction In this section, you will learn about handling item events in java. This demonstrates that the event generated when you select an item
Open or Open Source Software
Open or Open Source Software  what is mean by open or open source software in Computer Terminology?   In a computer terminology, open or open source software means any technology or a software that are freely available
Regarding GUI Applications
save and open jmenu item  How to create a save and open jmenu item... in java swing through which you can perform open and save operations on File...("Open"); JMenuItem fileItem2 = new JMenuItem("Save"); filemenu.add
Struts File Upload and Save
Struts File Upload and Save  ... code illustrating how to  save the file on the server . Now, the current... Upload and Save Example</title> <html:base/> <
Open Source Installer
Open Source Installer Open source installer tool NSIS (Null soft Scriptable Install System) is a professional open source system to create..., install or update shared components.    Open Source Java Tool
Save Table - SQL
Save Table  Where Oracle Tables or Database is saved? How to see Oracle Tables ? What are the websites to learn step by step Oracle. Help Me
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
How to save value in JSP
How to save value in JSP  Employee Name Time-IN Time-OUT Date t1 9 7 2012-12-12 t2... 324 2012-12-12 save i want to save dis value jsp to action ...how
save uiimage to photo library
save uiimage to photo library  How to saved the clicked picture...; Save UIImage to photo library Creating a camera application in iPhone need three simple steps to follow? 1) Role Camera 2) Save the captured image
Open Source Email Archiving - Open source software to achieve emails
Open Source Email Archiving - Open source software to achieve emails In this section we will see the features open source email archiving software available... the best open source email archiving software as per your business requirement

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.