Home Answers Viewqa Java-Beginners open jmenu item in java

 
 


MANOJKUMAR
open jmenu item in java
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:27 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:
Java JComboBox Get Selected Item Value
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.... In this tutorial we are discussing about how to store the selected item value
Problem to display checkbox item
;/div>   2) gettable.jsp: <%@page language="java" import
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 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
awt list item* - Swing AWT
awt list item*  how do i make an item inside my listitem...); choice.add("Java "); choice.add("Jsp"); choice.add("Servlets... information. http://www.roseindia.net/java/example/java/awt/ Thanks
Open Source HTML
;   Open Source HTML Parsers in Java NekoHTML is a simple 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
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
select one item name throug combo box than other combobox show item price
select one item name throug combo box than other combobox show item price  i have one table in database item master..if i select one item name through combo box than other combobox show item price only select item name... how i
open document
open document  open a word document using jsp   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
Open Source Workflow Engines in Java
Open Source Workflow Engines in Java The Open For Business Project: Workflow... upon restart. Open Source Graphical XPDL Java Workflow Editor Enhydra JaWE (Java Workflow Editor) is the first open source graphical Java workflow process
remove item from list box using java script - Java Beginners
remove item from list box using java script  remove item from list box using java script  Hi friend, Code to remove list box item using java script : Add or Remove Options in Javascript function addItem
how to open java
how to open Java  how to open java file simple Java Example
java swings - Java Beginners
click on the menu than another frame open which contain the some data like as item... JMenuItem("Item 1"); JMenuItem item2 = new JMenuItem("Item 2"); JMenu menu2 = new JMenu("Menu 2"); JMenuItem item3 = new JMenuItem("Item 3"); JMenuItem
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...(); } public SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing
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... SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane
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
open source - Java Beginners
open source  hi! what is open source? i heard that SUN has released open source .what is re requisite to understand that open source. i know core concepts only  Hi friend, Open source is an approach to design
navigation between panels when item is selected from jcombobox - Swing AWT
navigation between panels when item is selected from jcombobox  hi...(2nd panel).the combo box is in main panel. when a item is selected from combobox the 2nd panel should navigate to other panel. for now i have 4 item in the combo
Open Source Testing Tools in Java
Open Source Testing Tools in Java
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
Java open source software
Open source software for Java In this page we will tell list down the most used Open source in Java. Java is one of the programming language used... is the list of java open source software used for the development and deployment
open source project
open source project  i am a b.tec 3rd year ,i want to work in some open source java project, please suggest me
Open Source Java
Open Source Java Open Source Software in Java AspectJ...-source Java Sun's Java technology evangelist Raghavan Srinivas said an open... to be the first time Sun has explicitly stated its intention to open-source Java. Sun
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open taps CRM
open taps CRM  hi Plese guide to me how to forecase in Java Ofbiz Opentaps CRM Module Thanks hasim
How can i select a particular item in jpopup menu through java programs
How can i select a particular item in jpopup menu through java programs ... a perticular menu item in jpopup menu to be selected. I created a gui where it has... menu item in it. assume that the user pressing down key 3 times. I need to show
How to open an Acroform in iText?
How to open an Acroform in iText?  I modified a client's Acroform in Acrobat Pro 9, and now the client says he can't open it in iText. I had never even heard of iText before this. It's been a while since I did any Java coding
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
java code to open and display MS-word document
java code to open and display MS-word document  java code to open and display MS-word document
How to open a file in java using JFileChooser
How to open a file in java using JFileChooser  How to open a file in java using JFileChooser
Open Jgraph Problem - Java Beginners
Open Jgraph Problem  Hi, I have go through the example given in http://sourceforge.net/projects/openjgraph/ for Open Jgraph by Jesus M. Salvo Jr... on this. I am a newbie in Java language. Thank you. Ulamraja
Open Source software written in Java
Open Source software written in Java Open Source Software  or OSS... Code Coverage Open Source Java Collections API... Purpose ERP/CRM Written in Java Open Source
Open Source Software
; Open Source Aspect-Oriented Frameworks in Java AspectJ...Open Source Software Open Source Software Open source doesn't just mean access to the source code
Open Source DRM
Open Source DRM SideSpace releases open source DRM solution SideSpace Solutions released Media-S, an open-source DRM solution. Media-S is format-independent, though the first release only supports the Ogg Vorbis open-source audio
Open Source Jobs
transfers.     Open Source Job Schedulers in Java On some... developers and architects how to integrate Quartz with leading open source Java...Open Source Jobs Open Source Professionals Search firm
Open Source Directory
Open Source Directory Open Source Java Directory The Open Source Java... Java Open Application Server and Tomcat, part of the Apache Jakarta Project... - to many different platforms.    Open Source Java Directory
delete an item from database
delete an item from database  how to delete an item from the database using jsp
how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open
Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file
Open Source Midi
Sound API package (javax.sound.midi). Plumstone is an open source Java project...Open Source Midi Open Source Midi Proprietary software Being the best... share. As proponents of open source software, it should not be beneath us
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
Open-jACOB
Open-jACOB       Open-jACOB is a Java rapid application development tool (RAD) based on Eclipse... on Ajax with Java backend. Read full Description
Open Source Software
Open Source Software In this section we are discussing Open source software... Open source software available on the internet that can be used in the company. Open source software is very useful because source code also distributed
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
Open Source JMS
Open Source JMS Open Source JMS OpenJMS is an open source implementation of Sun Microsystems's Java Message Service API 1.0.2 Specification. Features... detection .    Open Source JMS Implementations JMS4Spread
Dojo Menu and Menu Item
Dojo Menu and Menu Item           In this section, you will learn about the menu and how to create it in dojo. Menu : This is the widget models a context
Dojo Menu and Menu Item
Dojo Menu and Menu Item           In this section, you will learn about the menu and how to create it in dojo. Menu : This is the widget models a context

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.