browser

browser

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");
    file.setMnemonic('F');
    JMenuItem newItem = new JMenuItem("New");
    newItem.setMnemonic('N');
    file.add(newItem);
    JMenuItem openItem = new JMenuItem("Open");
    openItem.setMnemonic('O');
    file.add(openItem); 
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic('x');
    file.add(exitItem);

    //adding action listener to menu items
    newItem.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                System.out.println("New is pressed");
            }
        }
    );
    openItem.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                System.out.println("Open is pressed");
            }
        }
    );
    exitItem.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                System.out.println("Exit is pressed");
            }
        }
    );                      
    JMenuBar bar = new JMenuBar();
    setJMenuBar(bar);
    bar.add(file);

    getContentPane();
    setSize(200, 200);
    setVisible(true);
}

public static void main(String[] args)
{
    Menu app = new Menu();
    app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

Ads









Related Tutorials/Questions & Answers:
browser
browser  how to make a browser
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
Advertisements
browser cache
browser cache  how can we clear browser cache
browser
prevent browser refresh
prevent browser refresh   prevent browser from refresh in Javascript
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
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 division.in 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 page.so
How to get browser time zone?
How to get browser time zone?  How to get browser Time Zone and browser date using java concept
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 making by java coding
Browser making by java coding  import javax.swing.*; import...*; import java.io.*; public class Browser extends JFrame implements...[]) { if(args.length==0) new Browser ("http:google.com"#; else new Browser#args#0
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
ModuleNotFoundError: No module named 'AFQ-Browser'
ModuleNotFoundError: No module named 'AFQ-Browser'  Hi, My Python... 'AFQ-Browser' How to remove the ModuleNotFoundError: No module named 'AFQ-Browser' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'AFQ-Browser'
ModuleNotFoundError: No module named 'AFQ-Browser'  Hi, My Python... 'AFQ-Browser' How to remove the ModuleNotFoundError: No module named 'AFQ-Browser' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'AFQ-Browser'
ModuleNotFoundError: No module named 'AFQ-Browser'  Hi, My Python... 'AFQ-Browser' How to remove the ModuleNotFoundError: No module named 'AFQ-Browser' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'bluesky-browser'
ModuleNotFoundError: No module named 'bluesky-browser'  Hi, My... named 'bluesky-browser' How to remove the ModuleNotFoundError: No module named 'bluesky-browser' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'browser-cat'
ModuleNotFoundError: No module named 'browser-cat'  Hi, My Python... 'browser-cat' How to remove the ModuleNotFoundError: No module named 'browser-cat' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'browser_compare'
ModuleNotFoundError: No module named 'browser_compare'  Hi, My... named 'browser_compare' How to remove the ModuleNotFoundError: No module named 'browser_compare' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'browser-cat'
ModuleNotFoundError: No module named 'browser-cat'  Hi, My Python... 'browser-cat' How to remove the ModuleNotFoundError: No module named 'browser-cat' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'browser_compare'
ModuleNotFoundError: No module named 'browser_compare'  Hi, My... named 'browser_compare' How to remove the ModuleNotFoundError: No module named 'browser_compare' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'browser-engine'
ModuleNotFoundError: No module named 'browser-engine'  Hi, My... named 'browser-engine' How to remove the ModuleNotFoundError: No module named 'browser-engine' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'browser-useragent'
ModuleNotFoundError: No module named 'browser-useragent'  Hi, My... named 'browser-useragent' How to remove the ModuleNotFoundError: No module named 'browser-useragent' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'browser_vulnerabilities'
ModuleNotFoundError: No module named 'browser_vulnerabilities'  Hi...: No module named 'browser_vulnerabilities' How to remove the ModuleNotFoundError: No module named 'browser_vulnerabilities' error? Thanks   
ModuleNotFoundError: No module named 'feed-browser'
ModuleNotFoundError: No module named 'feed-browser'  Hi, My Python... 'feed-browser' How to remove the ModuleNotFoundError: No module named 'feed-browser' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'FireSnake-Browser'
ModuleNotFoundError: No module named 'FireSnake-Browser'  Hi, My... named 'FireSnake-Browser' How to remove the ModuleNotFoundError: No module named 'FireSnake-Browser' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'FireSnake-Browser'
ModuleNotFoundError: No module named 'FireSnake-Browser'  Hi, My... named 'FireSnake-Browser' How to remove the ModuleNotFoundError: No module named 'FireSnake-Browser' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'insta_browser'
ModuleNotFoundError: No module named 'insta_browser'  Hi, My... 'insta_browser' How to remove the ModuleNotFoundError: No module named 'insta_browser' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jaeger_browser'
ModuleNotFoundError: No module named 'jaeger_browser'  Hi, My... named 'jaeger_browser' How to remove the ModuleNotFoundError: No module named 'jaeger_browser' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jaeger_browser'
ModuleNotFoundError: No module named 'jaeger_browser'  Hi, My... named 'jaeger_browser' How to remove the ModuleNotFoundError: No module named 'jaeger_browser' error? Thanks   Hi, In your python

Ads