Home Answers Viewqa Java-Beginners jmenu item in java desktop application

 
 


MANOJKUMAR
jmenu item in java desktop application
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:
Java Spring Desktop application
Java Spring Desktop application  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe package desktopapplication2
Simple Java Desktop Upload application
Simple Java Desktop Upload application  I try do simple example for upload applicationtake file from c:\ put to d:\ :) PLEASE HELP
desktop application
desktop application  how to transfer data swing text field to browser text field to their corresponding label/caption. please reply as soon as possible. thanks vijay
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
Java Spring Desktop application with multiple classes and jframe
Java Spring Desktop application with multiple classes and jframe  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe
EasyEclipse Desktop Java
EasyEclipse Desktop Java       EasyEclipse Desktop Java For development of Desktop... for Windows - Run Java application on Sun Java(tm) runtime, packaged
Remote mobile desktop - MobileApplications
Remote mobile desktop  I am doing my research to implement a java mobile application to access another remote mobile phone with the authentication.This application will have to use the service provider's network and a server
path setting for tomcat to java for Desktop PC - JDBC
path setting for tomcat to java for Desktop PC  Hi sir, I want to connect my java programms to Database which of either sql,oracle,mysql... or configuration about the Tomcat Server in Java. Kindly visit them . We hope
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application
ssl comunication between a desktop application and a web application
ssl comunication between a desktop application and a web application  Hi Lusiano, I am trying to implement a ssl comunication between a desktop application and a web application. can you please share code with me. Please
How to launch my web application from my desktop without opening Netbeans IDE everytime i run the application?
How to launch my web application from my desktop without opening Netbeans IDE... dont want all these steps, so i knw that java application can be launched using Java Web Start but dont knw abt web application, Is there any way to do
java--desktop appilication - JDBC
java--desktop appilication  when class.forName() is called ,,,a class is loaded...once after the class is loaded ..if we call class.forName, it will call the class which is already present.......what to do if we want to load
DESKTOP SHARING USING JAVA
DESKTOP SHARING USING JAVA  Sir i have the following code for scren capturing it is capturing in png format but when i am sending it over other m/c it is taking delay of around 16 seconds..i think it is because this line of code
Problem to display checkbox item
;/div>   2) gettable.jsp: <%@page language="java" import
Works when run from desktop but....
Works when run from desktop but....  I used the code provided here for a pie chart using swing in Java, and when I saved it to my desktop, it ran fine, and worked as explained, but then I tried to add the same code to NetBeans
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
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
Java program to get the desktop Path
Java program to get the desktop Path  ... the desktop path of the system. In the java environment we can get the desktop path also with the system's property. For getting the desktop path we have to add
Problem in setting IP address for a JFrame Class Desktop Application
Problem in setting IP address for a JFrame Class Desktop Application  I have designed a browser for our final year project, it is working well. But when we put it in a system which has a proxy setting for internet connection
Create a Desktop Pane Container in Java
Create a Desktop Pane Container in Java   ... pane container in Java. The desktop pane container is a container, which has... under the desktop pane. Following figure shows the JDesktopPane component of Java
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
i want to create an icon on my desktop... with this i want to open my web application
i want to create an icon on my desktop... with this i want to open my web application  i want to create an icon on my desktop... with this i want to open my web application(automatically run my server... )how
Google Desktop Search
Google Desktop Search     ... capabilities, this plug-in uses the Google Desktop Search Engine instead. Usage The search can be started from either the Search menu or the Google Desktop
Item Renderer in AdvancedDataGrid
Item Renderer in AdvancedDataGrid: In this example you can see how we can use a item renderer property in AdvanceddataGrid control. The tag of item... a pie chart as a item renderer and displayed in AdvancedDataGrid. Example
Chart Item Event in Flex4
Chart Item Event in Flex4: Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package... you will show the value of item when you click on the data item. If you click
Using the Desktop class to launch a URL
Using the Desktop class to launch a URL with default browser...; Using the Desktop class to launch a URL with default browser in Java  This article describes the new Desktop API
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
linux desktop on windows without using vn or any other ? - Java Magazine
linux desktop on windows without using vn or any other ?  linux desktop on windows without using vn or any other ?. I have a linux pc and windows xp pc but i am not able to connect the linux pc on windows .why? .windows
Custom Item in J2ME
Custom Item in J2ME      ... and they can also set their look and feel as these custom item have their own method called paint(). Also CustomItem is a extendable class, and extends the Item class
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
converter application
converter application  Develop a converter application using event-driven programming paradigm of Java. Procedure: 1. Design a menu bar with two..., and Temperature. 3. The second menu has Help and Exit options. 4. When a menu item
Rich Internet Application
Rich Internet Application       Rich Internet Application The term RIA (Rich Internet... of traditional desktop applications, it means Rich Internet Applications are a cross
Skinning Data Item in Chart in Flex4
Skinning Data Item in Chart in Flex4: In this section you can see how we can provide the skin to data item in chart control. We will use the itemRenderer for providing the skin to data item. In this example we change
User-friendly Desktop Internet GIS (UDIG)
User-friendly Desktop Internet GIS (UDIG)       The User-friendly Desktop Internet GIS (uDig) is both a GeoSpatial application and a platform through which
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
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
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
J2ME Image Item Example
J2ME Image Item Example       This application illustrates how to create the image and imageItem using...;ImageItem.LAYOUT_DEFAULT, "image");         The Application
How can I open my Java desktop app by clicking on its file?
How can I open my Java desktop app by clicking on its file?  How can I open my Java desktop app by clicking on the file it creates? This app creates files when selecting its "Save as" option with an extension specificaly defined
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
J2ME Item State Listener Example
J2ME Item State Listener Example       In this application we are going to shows how to implement.... The ItemStateListener interface having only one method that is: itemStateChanged(Item item
Java
the application with Java technology. Here is the list of few tools: NetBeans...Java Java is one the programming language suited for the construction of many type of applications. It can be used to develop: Desktop applications
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
Java Application
Java Application  Hi, What is the applications of Java in development of software? What type of applications can be developed using Java programming Language? Can anyone tell me the url for downloading sample projects in Java
Swing application
the application not through web browsers, instead through a Swing desktop application GUIs. Please help me to develop such an application...Swing application  Hello, I want to develop a Swing application
delete an item from database
delete an item from database  how to delete an item from the database using jsp
Rich Internet Application
Rich Internet Application      ... that have the features and functionality of traditional desktop applications... and traditional desktop applications that shift some of the essential processing among

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.