saurav srivastav
1 Answer(s)      7 years ago
Posted in : Swing AWT

how to add menu items in the menu in java swing through java coding

View Answers

March 28, 2011 at 4:27 PM

This is a simple example for working with menu items...........

import javax.swing.*; import java.awt.event.*; public class Menu extends JFrame{ public Menu() { super("Menu example");

    JMenu file = new JMenu("File");
    JMenuItem newItem = new JMenuItem("New");
    JMenuItem openItem = new JMenuItem("Open");
    JMenuItem exitItem = new JMenuItem("Exit");

    //adding action listener to menu items
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
                System.out.println("New is pressed");
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
                System.out.println("Open is pressed");
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
                System.out.println("Exit is pressed");
    JMenuBar bar = new JMenuBar();

    setSize(200, 200);

public static void main(String[] args)
    Menu app = new Menu();



Related Tutorials/Questions & Answers:
browser  how to make a browser
browser  hello this is saurav srivastav, thank you for sending the cvode for creating the menu item, but I want the code for file open and save frame in the swing because I am working on my project Browser and one more problem
browser cache
browser cache  how can we clear browser cache
Browser issue
Browser issue  how can i close popup windows in mozilla browser and return back to the parent page
browser - WebSevices
browser  I use morzila as my default browser. i u to educate on how I can increase my browser's speed
prevent browser refresh
prevent browser refresh   prevent browser from refresh in Javascript
we browser - WebSevices
we browser  tell me the concept of web browser... can i develop a web browser
difference from browser to browser - JSP-Servlet
difference from browser to browser  I am developing a project in jsp. When browse in mozilla it works good and when I open it with IE there is a difference how to overcome this problem.Thanks in advance
Browser's back button
Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
Enable Browser's back button
Enable Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
Browser's back button
Browser's back button  how to redirect to a home page when browser's back button is pressed in jsp instead of displaying the previous page
SWT Browser
SWT Browser       This section shows you SWT Browser In SWT, the class Browser of package org.eclipse.swt.browser allows to create a browser. In the given example, the class
php download file browser
php download file browser  limiting downloading file system via browser only through my web application
HTML on a single browser
HTML on a single browser  My page looks good on one browser, but not on another
Resize browser in flex
Resize browser in flex  Hi........ Please tell me about How can I Resize the Internet Explorer browser window from flex ? please give me the appropriate answer Thanks  Ans: UsegetURL() to communicate
Closing the browser window
Closing the browser window  <BODY> <form> <input type=button value="Close Window" onClick="javascript:window.close();"> <...; thought that this will close the window of the browser but not working
browser back button
browser back button   hi...i created one page in JSF.that page had three form first form one add button is there.if i click that button move to second form,then i click browser back button ,it moves on another
disabling the browser's back button
disabling the browser's back button  I have following requirement, After submitting the form, user should not navigate to the previous page. I have tried with onbeforeunload(), but it is not working properly. Please help me
Browser Back/Forward - Struts
Browser Back/Forward  Hi, Greetings to all. I have developed a web application using Struts 2. Now, i want to enable browser back/forward/bookmarking in that. Can anyone post me some links/tutorial/examples or how to go
browser - JSP-Servlet
browser  Browser buttons In a website program with login and session concept, logout option is working properly in JSP pages. While pressing directly the back and front buttons in browser [Internet Explorer 6.0
Toolbar to a browser - Java Beginners
to display toolbar on the browser? Thanks  I want to create a website's... browser, some site ask us to download the application and install it. so i wanted
Browser making by java coding
Browser making by java coding  import javax.swing.*; import...*; import*; public class Browser extends JFrame implements...[]) { if(args.length==0) new Browser (""#; else new Browser#args#0
How to get browser time zone?
How to get browser time zone?  How to get browser Time Zone and browser date using java concept
Display PDF in browser - Struts
file in the browser using struts 2. Here i am using iText for pdf generation... ON Browser")); document.close(); HttpServletResponse response...(); But while access the browser it returns IllegalStateException like following
Java Web Browser Problem
Java Web Browser Problem  Hello When run my web browser this is not displaying complete page any of the website like other browser.So Plz help me...."); setTitle("NextVision Browser"); setSize(600,400); Container
how to disable browser back button
how to disable browser back button  Am doing a web application in that how to disable browser back button using java script
need code for file browser
need code for file browser  hi, i need to write a code to browse the file in my computer using Jsp or java.. what is the code for file browser?   JSP Code for browsing: 1)page.jsp: <%@ page language="java" %>
Browser tire - Java Interview Questions
Browser tire  If we use multithreading in my application then which tire is needed on clients browser so that application run successfully? Plz help me ass soon as possible
php browser detection script - PHP
php browser detection script   I need a browser detection script in PHP. I am creating my application compatible to firefor, mozila and IE too
Version of com.braintreepayments>browser-switch dependency
List of Version of com.braintreepayments>browser-switch dependency