Handling event of a particular menuitem

hi,
I've created a form with a Jmenu,but i m unable to listen the event of a particular menuitem. I'm sending my code in which when i click on any of the menu item it is listening to all the remaining menuitems also. so what changes are required in my below code in order to listen to a particular menu item?
And ya my second question regarding this code is i want my frame to be opened in maximized form so that it cannod be moved. My frame seems to b opened as maximized but its actually not bcoz its still movable,so is there any way to open it maximized?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class menu implements ActionListener
JMenu m;
JMenuItem n,s,sa;
JMenuBar mb;
JFrame f = new JFrame();
menu() //constructor
f.getContentPane().setBackground(new Color(146,187,237));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
f.setSize(screenSize.width,screenSize.height);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mb = new JMenuBar();
m = new JMenu("File");
mb.add(m);
n= new JMenuItem("New");
n.addActionListener(this);
m.add(n);
s= new JMenuItem("Save");
s.addActionListener(this);
m.add(s);
sa = new JMenuItem("Save As");
sa.addActionListener(this);
m.add(sa);
f.setJMenuBar(mb);
f.setVisible(true);
public void actionPerformed(ActionEvent e)
if(e.getSource()==n);
try
System.out.println("new");
catch(Exception e1)
e1.getMessage();
if(e.getSource()==s);
try
System.out.println("Save");
catch(Exception e1)
e1.getMessage();
if(e.getSource()==sa);
try
System.out.println("Save As");
catch(Exception e1)
e1.getMessage();
public static void main(String args[])
menu a = new menu();
}

How to use Menus
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
just scroll down at the bottom of the page for examples.
If you want to maximize a frame use setExtendedState(JFrame.MAXIMIZED_BOTH)

Similar Messages

  • How to open page in new window while handling event on link.

    Hi all
    I have a requirement where page should be opened in new window when I click on link.My item style is 'link'.Despite of mentioning target frame _blank, I m not able to open it in new window.I m handling event by setting Action Type as fireAction.I hope this might be the reason because of that this happened. Can somebody suggest some solution so that I can open it in new window.
    Thanks,
    Bhupendra

    Hi ,
    though i am not able to answer, i can get some answer for my question.
    How the link item is handled thru the ActionType and event in the Client Action..?
    The reason for this question is that we are trying to extend the customer search page in AR - EBSR12. there the search result page has the Account Name as a link and the Action event says viewAccountName and the action type says firePartialAction. I am trying to understand this so that i can add more parameters to the link so that i can use them in the target page of the link..
    Any help is appreciated..
    Thanks
    Chidam

  • How to handle events in Swng

    Hi!
    I would like to know which one of the following is the best way to handle events in Swing application.
    Method 1
    Write annonymus inner classes in the same class
    Method 2
    =======
    Write a seperate class which extends the adapter class of the event handling and create an object of that in the main class and assign it to the components with addActionHandler() method.
    I am trying to use the second one and I have the following design issue.
    I have a class frmMain.java in which I have a frame and to that frame I am adding a panel which consists of 'N' No. of components.
    I want to make this panel added to the frame when I click on a menu item (login) and want to remove the panel from frame when I click on a menu item(logout).
    I have a main class called Application.java where I create the object of my frame(frmMain.java).
    Thanks in advance,
    AV

    1. Your JFrame is now subject to receive action events from anywhere. You will have to be more careful that you respond only to the right events.
    2. If you have a lot of possible consequences to an event(for example, based on button pressed), you'll need a long if...then...else statement to determine what to do based on the source of the event.
    3. With individual ActionListener classes, it's easier to add the same listener to multiple components and no need to worry about source.
    4. Kind of the same thing: With individual classes, the event and its consequences are so tightly coupled.
    End preaching....basically, my style boils down to what I call the tool set vs Swiss army knife rule. Java seems designed around the concept of a large number of specific purpose classes vs a smaller number of multi purpose classes and I think its a design methodology that makes sense, because I believe strongly in functional isolation in my code.

  • How do I print only the events of a particular calendar, and not all the days in between listed?

    I am working on a MacBook Pro.  I have multiple calendars in my calendar.  I am able to figure out how to print a list of events for a particular calendar, but the list includes listing all the dates in between as well.  For example, I'd like to print a list of presentations I have coming up over the next 5 months.  That yields a 9 page document.  Although there may be only one presentation on a particular page, it also lists all the calendar dates, even if it doesn't have an event.  Does this make sense?
    Does anyone know how to deal with this?
    Thanks!

    Hi JN and Barry,
    Barry wrote:
    The second case may not be included in the available D&T formats in Numbers 3
    For my region, the Date & Time data formats include month.
    The Date Pop-Up
    This may not be the case for all regions.
    Remember that the month is only the display, and the Full Date & Time is still there. If I change the format to reveal what is behind the curtain:
    Regards,
    Ian.

  • How to create event alert for particular column get updated

    Hi every one.... plz help me
    How to create oracle event alert when particular column is update. plz help me.... Acutually i need email alert when ever list price for an item column in pricing table get updated+... plz. Its urgent.

    Oracle Event alert is based on update of specific table and not on specific column in table.
    However you can create a trgigger on table which is based on updat of column. And in this trigger you can send a mail using plsql.
    HTH

  • Dynamic Creation of list box on excel sheet and handling events

    hi all ,
    i m working on excel to sap integration application and for that i need to create dynmicaly list boxes in excel and also needs to handler events of each boxes..
    please suggest me somehting asap/
    thanks in advance,
    jigs
    helpful ans will be rewarded.

    hi all ,
    i m working on excel to sap integration application and for that i need to create dynmicaly list boxes in excel and also needs to handler events of each boxes..
    please suggest me somehting asap/
    thanks in advance,
    jigs
    helpful ans will be rewarded.

  • Handling events in ALV grid

    hi,
    Hi,
    I am displaying some fields from VBAP in ALV gid and have give drop down check box to storage location making it editable  so  if the user changes Storage location  of
    some entries and clicks SAVE button, when we click save button i need to capture all the rows that were been changed and update VA02 using these records through bapi.
    but iam not able to capture this SAVE event but iam able to capture Enter and cursor event.
    i have written following code for this
    LOCAL CLASSES: Definition
    class lcl_event_receiver: local class to handle event CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS:
          handle_data_changed
             FOR EVENT data_changed OF cl_gui_alv_grid
                 IMPORTING er_data_changed.
      PRIVATE SECTION.
    ENDCLASS.                    "lcl_event_receiver DEFINITION
    LOCAL CLASSES: Implementation
    class lcl_event_receiver (Implementation)
    CLASS lcl_event_receiver IMPLEMENTATION.
        METHOD handle_data_changed.
        DATA: l_error_in_data TYPE c.
        PERFORM handle_data_changed USING er_data_changed l_error_in_data.
    *§7.Display application log if an error has occured.
        IF l_error_in_data EQ 'X'.
          CALL METHOD er_data_changed->display_protocol.
        ENDIF.
      ENDMETHOD.                    "handle_data_changed
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
    *&      Form  handle_data_changed
         Identify columns which were changed and check input
         -->P_ER_DATA_CHANGED  text
    FORM handle_data_changed  USING  p_er_data_changed
                              TYPE REF TO cl_alv_changed_data_protocol
                              p_error_in_data TYPE c.
      DATA : lw_mod_cell TYPE lvc_s_modi ,
             l_value TYPE lvc_value ,
             l_lgort TYPE lgort_d.
      SORT p_er_data_changed->mt_mod_cells BY row_id .
      LOOP AT p_er_data_changed->mt_mod_cells INTO lw_mod_cell
                              WHERE fieldname = 'LGORT'.
        CALL METHOD p_er_data_changed->get_cell_value
          EXPORTING
            i_row_id    = lw_mod_cell-row_id
            i_fieldname = 'LGORT'
          IMPORTING
            e_value     = l_value.
        SELECT SINGLE lgort FROM t001l INTO l_lgort WHERE werks = p_werks
                                                    AND   lgort = l_value.
        IF sy-subrc NE 0.
    In case of error, create a protocol entry in the *application log.
          CALL METHOD p_er_data_changed->add_protocol_entry
            EXPORTING
              i_msgid     = '0K'
              i_msgno     = '000'
              i_msgty     = 'E'
              i_msgv1     = text-003
              i_msgv2     = l_value
              i_msgv3     = text-004
              i_fieldname = lw_mod_cell-fieldname
              i_row_id    = lw_mod_cell-row_id.
          p_error_in_data  = 'X'.
          EXIT.
        ELSE.
    *§5b.If the value is valid change values of
       cells.
          CALL METHOD p_er_data_changed->modify_cell
            EXPORTING
              i_row_id    = lw_mod_cell-row_id
              i_fieldname = lw_mod_cell-fieldname
              i_value     = l_value.
          READ TABLE t_list1 INTO w_list1 INDEX lw_mod_cell-row_id.
          IF sy-subrc EQ 0.
    *comparing old value with the changed value
            IF w_list1-lgort <> l_value.
              MOVE:      w_list1-werks  TO w_list3-werks,
                         w_list1-matnr  TO w_list3-matnr,
                         w_list1-arktx  TO w_list3-arktx,
                         w_list1-vbeln  TO w_list3-vbeln,
                         w_list1-posnr  TO w_list3-posnr,
                         w_list1-pstyv  TO w_list3-pstyv,
                         w_list1-vstel  TO w_list3-vstel,
                         w_list1-auart  TO w_list3-auart,
                         w_list1-kwmeng TO w_list3-kwmeng,
                         w_list1-vrkme  TO w_list3-vrkme,
                         w_list1-mbdat  TO w_list3-mbdat,
                         l_value        TO w_list3-lgort.
              APPEND w_list3 TO t_list3.
    *t_list3 will contain all the records that are changed
              CLEAR w_list3.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF go_custom_container IS INITIAL.
    create a custom container control for our ALV Control
        CREATE OBJECT go_custom_container
          EXPORTING
            container_name              = g_cont_on_main
                EXCEPTIONS
                    cntl_error = 1
                    cntl_system_error = 2
                    create_error = 3
                    lifetime_error = 4
                    lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc NE 0.
    Display error message.
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              titel = sy-repid
              txt2  = sy-subrc
              txt1  = 'The control could not be created'.
        ENDIF.
    create an instance of alv control
        CREATE OBJECT go_grid
          EXPORTING
            i_parent          = go_custom_container.
    *If display or change radio button is cheked
        IF ( p_chng = 'X' OR p_disp = 'X' ) .
    Set a titlebar for the grid control
          g_layout-grid_title = 'Sales Orders'.
          g_layout-excp_fname = 'TRAFFIC_LIGHT'.
    Define a drop down table.
          PERFORM set_drdn_table.
          CALL METHOD go_grid->set_table_for_first_display
            EXPORTING
              is_layout                     = g_layout
            CHANGING
              it_outtab                     = t_list1
              it_fieldcatalog               = t_fieldcat1
            EXCEPTIONS
              invalid_parameter_combination = 1
              program_error                 = 2
              too_many_lines                = 3
              OTHERS                        = 4.
          IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
    register ENTER and CURSOR to raise event DATA_CHANGED.
      (Per default the user may check data by using the check icon).
        CALL METHOD go_grid->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_enter.
        CALL METHOD go_grid->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified.
        CREATE OBJECT g_event_receiver.
        SET HANDLER g_event_receiver->handle_double_click  FOR go_grid.
        SET HANDLER g_event_receiver->handle_hotspot_click FOR  go_grid .
        SET HANDLER g_event_receiver->handle_data_changed  FOR  go_grid .
      ENDIF.
      CALL METHOD cl_gui_control=>set_focus
        EXPORTING
          control = go_grid.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE user_command_0100 INPUT.
      ok_code = sy-ucomm.
      CASE ok_code.
        WHEN 'EXIT'.
          PERFORM exit_program.
        WHEN 'SAVE'.
          PERFORM update_sales_order using t_list3[].
    endcase.
    Thanks in Advance,
    Siri

    Hi Sirisha,
              You can get the event code for Enter because you have regitered in the event reciever .
    But for the SAVE you will have to set in the PF-status of the screen and not the ALV-grid save .
    Please award if helpful.

  • I movie 11: how do i find an event for a particular clip in my project

    I movie 11: how do i find an event for a particular clip in my project

    Thanks so much for your response.  I tried that though and it did not work... any other suggestions?

  • Handling events in combo box

    Hello,
    I'm very much confused about the handling events of JComboBox with ActionListener and ItemListener. Both are seemed similar to me. If anyone can explain me the differences, it would be helpful for me. Thanks everybody.

    ActionEvents are fired each time any item is selected, ItemEvents are only fired, if the selection changes.

  • Handling Events in CMSDK webapplication

    Hi frns,
    I am handling events(create Directory,delete directory,
    move Folder,upload document etc.)and forward it(that a folder had been created,a file had been deleted etc.)to all the users who are currently logged on webapplication.
    To do that I have to create a custom server(extending IfsServer and implementing IfsEventHandler)and deploy it
    in the node using CMSDK manager,now my queries are:
    a)Shall I override the initialize()method of the Server
    ?If yes,then what will be the signature of initialize()?
    b)What about all others method of server lifecycle?
    c)What are the other steps(like display the msg.regarding the events to all the logged on users)to be taken?
    Plz send me the answers as early as possible.
    Regards,
    Prasenjit

    cebailey wrote:
    Here's a version with Panel > OwningVI > Key Down selected in the nodes that register events. It seems to do what I want. It acts on keystrokes that occur when the cursor isn't even over the parent's window, which is good in my situation. I made these choices by experimenting - is this a good approach, if I want to act on all the keystrokes that occur when the parent VI has focus?
    As you noted, this will have the event structure respond to keypresses whenever the parent VI is active. You can simplify the subVI by simply wiring the "VI Refnum" terminal directly to the Register for Events node. Getting the Panel, and then the Owning VI simply gets you back to where you started.
    That's a valid way of doing it, and I'm assuming that this is intended to be a test case. As you noted you have a large project, so I don't know what your overall architecture is, or how you intend to use this technique, so I can't really say whether it's a "good" approach. It's an approach.
    Say, I should have said this before, but you have to be pretty good to answer the question somebody should be asking, especially in brief forum postings.
    Thanks for the compliment. It's just a matter of seeing a lot of code and a lot of questions. I'm only a teenage pup compared to the real veterans on this board.

  • Handling events in subvis - think this should work but it doesn't.

    In part of a large project I need to handle key down events, but elsewhere I need to handle them differently and want to be able to dynamically register and unregister them in each location. I also want to be able to put one of the event handlers in a subvi. To quote the Help system, "Dynamically Registering Events: With dynamic registration, you can handle events in a subVI rather than only in the VI where the events are generated."
    ViThatHandlesEvents.vi handles key down events. It uses dynamic event registration to demonstrate that it works (though in this simple example it isn't necessary).
    ViContainingSubviThatHandlesEvents registers key down events and passes this to KeyDnEventHndlrSubVI. I thought it would work but it doesn't.
    Attachments:
    KeyDnEventHndlrSubVI.vi ‏14 KB
    ViThatHandlesEvent.vi ‏22 KB
    ViContainingSubviThatHandlesEvent.vi ‏18 KB

    cebailey wrote:
    Here's a version with Panel > OwningVI > Key Down selected in the nodes that register events. It seems to do what I want. It acts on keystrokes that occur when the cursor isn't even over the parent's window, which is good in my situation. I made these choices by experimenting - is this a good approach, if I want to act on all the keystrokes that occur when the parent VI has focus?
    As you noted, this will have the event structure respond to keypresses whenever the parent VI is active. You can simplify the subVI by simply wiring the "VI Refnum" terminal directly to the Register for Events node. Getting the Panel, and then the Owning VI simply gets you back to where you started.
    That's a valid way of doing it, and I'm assuming that this is intended to be a test case. As you noted you have a large project, so I don't know what your overall architecture is, or how you intend to use this technique, so I can't really say whether it's a "good" approach. It's an approach.
    Say, I should have said this before, but you have to be pretty good to answer the question somebody should be asking, especially in brief forum postings.
    Thanks for the compliment. It's just a matter of seeing a lot of code and a lot of questions. I'm only a teenage pup compared to the real veterans on this board.

  • Handling Events in OOPS ALV

    Hi All,
          I am using ALV OOPS for handling events.I have a scenario like in my ALV, i will change/insert/delete the records, i need to update the DB table when i press the save button.
    I need to throw an error if the user enters an invalid data like (material number which is not present in Mara table) How can i handle this using Events in OOPS?
    Can anyone send any sample code if you any ??
    Thanks in Advance...

    Hi
    Check the following link.
    EVENTS IN ALV OOPS
    hope you got your solution
    Regards
    Sachin

  • Handling events in BSP application using WML tag Extensions

    Hello Everyone  ,
                            We are developing a BSP applications for Mobile handheld using WML tag library. I am looking for some code samples to know how we can handle evevents inside the BSP using the WML tag library.
    Can any one of  you plesae help us by placing a code snippet for handling onInputprocessing() methods (BSP Using WML Tag extensions).
    I mean to ask how we can handle events inside the BSP applications that uses the WML tag library.
    I know about how to handle BSP events using HTMLB and XHTMLB tags frameworks.
    Thanks for your help in advance.
    Thanks,
    Greetson

    Is this WML tag library something that is supplied by SAP u2013 as a BSP Extension Element?  Or are you just using WML tags directly in your layout?  I can tell you in general that if you want to generate HTMLB events from regular HTML code you can generate the JavaScript calls using the htmlbEvent tag of the BSP extension library.  However your tags have to be running within an HTMLB Content tag for this to work.
    If you want to work totally without HTMLB then you need to use the simple HTTP Post but format the input name as OnInputProcessing(<function code>) like this:
    <input type="submit" name="OnInputProcessing(ok)" value="OK">
    This will cause the OnInputProcessing event handler to trigger without needing any HTMLB tags (this is how it was done in WebAS 6.10 before we BSP Extensions).

  • Handling Events in FXML-includes

    Hi!
    I am using FXML to define the GUI of my application. As the GUI is pretty complex with many regions and items in it, I have created a separate FXML file for each main region to reduce the overall complexity of maintaining the design.
    My parent FXML file, called "Frame.xml", includes those "sub-regional" FXML-definitions using "<fx:include source="RegionXYZ.fxml" />".
    What I am now stucked with is, how to handle events in this approach...
    Questions:
    a) Can I add a separate controller in each of the "sub-regional" FXML-files, like "fx:controller="FXMLRegionXYZController"?
    b) Or must I, or even should I, use only a single controller inside the main FXML? Will this single controller be able to recognize and handle actions/events in the included FXML-definitions as well?
    c) What is the best approach in general for this?
    Thanks,
    Jörn

    Hi!
    I am using FXML to define the GUI of my application. As the GUI is pretty complex with many regions and items in it, I have created a separate FXML file for each main region to reduce the overall complexity of maintaining the design.
    My parent FXML file, called "Frame.xml", includes those "sub-regional" FXML-definitions using "<fx:include source="RegionXYZ.fxml" />".
    What I am now stucked with is, how to handle events in this approach...
    Questions:
    a) Can I add a separate controller in each of the "sub-regional" FXML-files, like "fx:controller="FXMLRegionXYZController"?
    - Yes, you can
    b) Or must I, or even should I, use only a single controller inside the main FXML? Will this single controller be able to recognize and handle actions/events in the included FXML-definitions as well?
    - if you could control everything from a single controller but you option (A) is much better
    c) What is the best approach in general for this?
    - Option (a)
    Thanks,
    Jörn

  • Javascript error in event handler event type = timeline

    Hi,
    I have a small EdgeAnimate projekt with version 1.5.0 and the local export works fine... I must include the package at a CMS and I update all paths to absolute paths and all files are loading...
    but I the animation dont play - I see at the javascript console the follow output
    javascript error in event handler event type = timeline   edge.1.5.0.min.js:143
    Springender Punkt: Rettungswagen - Der springende Punkt
    I dont found any solution... :-((

    Hi Scott,
    I have gone through your shared composition created in older verion of Edge.
    If you open the older composition html page in browser, there already have some of the error messages in the console as you mentioned above like
          Javascript error in event handler! Event Type = timeline.
    And as you said with the latest Edge, when you upgrade the old composition, some new error messages gets added to the existing ones.
    As in the latest Edge, the whole of runtime has been shake-up, some of the attributes has been removed and are added in different way.
    Example: To access timelines of a symbol:
         Old way:           sym.timelines['Default Timeline']
         New way:          sym.data[sym.name].timeline
    You need to make some modifications in index_edgeActions.js file like:
         1. Search & Replace "timelines['Default Timeline']" with "data[sym.name].timeline"
         2. And in the code taken from EdgeCommons.js, replace "getVariable("symbolSelector")" with "_variables["symbolSelector"]".
    Hope, these changes will remove the new JS issues you mentioned.
    hth,
    Vivekuma

Maybe you are looking for

  • Problem Ejecting iPod Photo since updating software

    Can anyone help with my problem ? Just updated iTunes to 5.0.0.35. All seemed ok until I needed to update software on iPod (colour screen, 60gb) to 1.2 so I can use the camera connector I bought when I go on holiday. Now I'm having serious problems.

  • Bash completion broken since upgrade

    Hi, since I did an upgrade the bash autocompletion behaves strange. Completing directories will end in a space instead of an slash. Eg you enter "/et[tab]" and it completes "/etc " instead of "/etc/". This makes navigating directory hierarchies a PIT

  • Flash FLV for DVD?

    I've a client who asked for a bid on a project, which piqued my curiosity.However, from my probing it seems they wanted the Quicktime movies turned into FLV files but wanted them for DVDs. They were not as yet concerned about output for the web. I wa

  • Alternative sound input

    So for christmas, i recieved a wonderful condenser microphone and a preamp. Wanting to make some recordings with garageband, I plugged it all into the 3.5mm jack that was not the headphone jack, assuming that it's the microphone/input... I do not thi

  • Reports 6i Pdf generation problems

    Hi, I am using reports 6i with graphics. when I see the report inside the previewer the vertical tick marks on the X-axis appear fine, but when I generate to PDF the same tick marks appear inverted which can only be seen with the help of a mirror. I