How to use Action interface?

Hello,
I haven't been programming in JAVA for very long, just over a month. I understand that intefaces are just method signatures and variables that can be used by a class wich implements them and redefines the methods and/or variables. I know that much.. I think.
My Question:
I want to use the Action interface for multiple buttons, I just don't know exactly how. dubwai, is the one who suggested the concept to me. Does anyone have any implementation or code wich utilizes the Action interface?
Thanks very much,
Bruce

What you need to do is write a class that extends AbstractAction. I did one for a FileAction class. I have included the code for this below as a reference:
     class FileAction extends AbstractAction
          // Handles file actions
          FileAction(String name)
               //Constructor
               super(name);
               String iconFileName = "images/" + name + ".gif";
               if(new File(iconFileName).exists())
                    putValue(SMALL_ICON, new ImageIcon(iconFileName));
          FileAction(String name, String tooltip)
               //Constructor
               this(name);                                             // Call the other constructor
               if(tooltip != null)                                   // If there is tooltip text...
                    putValue(SHORT_DESCRIPTION, tooltip);     // store it.
          public void actionPerformed(ActionEvent e)
               String name = (String)getValue(NAME);
               if(name.equals(saveAction.getValue(NAME)))
                    // code to handle file Save operation
                    saveOperation();
               else if(name.equals(saveAsAction.getValue(NAME)))
                    // code to handle file Save As operation
                    File file = showDialog(
                         "Save Sketch As",
                         "Save",
                         "Save the Sketch",
                         's',
                         modelFile == null ? new File(files.getCurrentDirectory(), filename) : modelFile);
                    if (file != null)
                         if (file.exists() && ! file.equals(modelFile))
                              if (JOptionPane.NO_OPTION ==      //Overwrite warning
                                   JOptionPane.showConfirmDialog(
                                   SketchFrame.this,
                                   file.getName() + " exists. Overwrite?",
                                   "Confirm Save As",
                                   JOptionPane.YES_NO_OPTION,
                                   JOptionPane.WARNING_MESSAGE))
                              return;     // no file selected
                         saveSketch(file);
                    return;
               else if(name.equals(openAction.getValue(NAME)))
                    // code to handle file Open operation
                    checkForSave();
                    File file = showDialog("Open Sketch File",     // dialog window title
                         "Open",                                             // button lable
                         "Read a sketch from a file",               // button tooltip text
                         'o',                                             // shortcut character
                         null);                                             // no file selected
                    if (file != null)                                   // if a file was selected
                         openSketch(file);                              // then read it
               else if(name.equals(newAction.getValue(NAME)))
                    // code to handle file New operation
                    checkForSave();
                    theApp.insertModel(new SketchModel());          // insert new empty sketch
                    modelFile = null;                                   // no file for it
                    filename = DEFAULT_FILENAME;                    // default name
                    setTitle(frameTitle
                         + files.getCurrentDirectory()
                         + "\\"
                         + filename);
                    sketchChanged = false;                              // not changed yet
               else if(name.equals(exitAction.getValue(NAME)))
                    // code to handle file Exit operation
                    checkForSave();
                    System.exit(0);
               else if(name.equals(printAction.getValue(NAME)))
                    // code to handle file Print operation
                    PrinterJob printJob = PrinterJob.getPrinterJob();     // get a printing object
                    printJob.setPageable(theApp.getView());     // the view is the page source
                    if(printJob.printDialog())     // display print dialog
                         try
                              printJob.print();     // then print
                         catch(PrinterException pe)
                              System.out.println(pe);
                              JOptionPane.showMessageDialog(SketchFrame.this,
                                   "Error printing a sketch.",
                                   "Printer Error",
                                   JOptionPane.ERROR_MESSAGE);
     }The good thing about Actions is that you can put them in a menu or on a toolbar using the same code.
Garry.

Similar Messages

  • How to use ITextmodel interface in VC++

    hai,
    i want to know how to use ITextModel interface in VC++, that is how to give the story to ITextModel interface, if any one knows please tell him ASAP
    regards,
    ram

    Hi,
    I am not sure what you mean by "give the story to ITextModel", but if what you're looking is to insert some text into a text model, check out SnpManipulateTextModel::InsertText in the SDK, it does exactly that.
    Thanks!
    lee

  • How to use temporary interface in another interface as derived table in 10g

    Hi ,
    Can somebody please tell me how to use temporary interface in another interface as derived table in 10g.
    I have an option in odi 11g to this task.But i am working on odi 10g for my project.So that please help me to do this task.
    I can able to create temporary interface in 10g ,but i dont know how to use that temporary interface in another inerface as derived table.
    Thanks in Advance
    Thanks,
    Srikanth A

    A temp interface CANNOT be used as a derived table in ODI 10g.
    All you can do is to drag and drop the temp interface as the source in the mapping.
    PS. Please remember to assign correct/helpful points to the people who help you in the forum.

  • How to use IKinectPressingUpdatedEventArgs Interface??

    I don't Know how to use IKinectPressingUpdatedEventArgs Interface(c++)
    I need to delta data
    how to get data??

    What specifically are you trying to do? Depending on the scenario, this might not be something you need. Are you using Win32 or store based apis? What is your UI framework? Have you created a thread and waiting for the interaction events to fire?
    Carmine Sirignano - MSFT

  • How to use Action/Input maps

    It seems to me that the move to sharing actions menus, buttons, and other components is a logical one, given that it is desirable to have all references to the action reflect its enabled state.
    The question that arises is: which ActionMap object to use as the central store? Do you create your own and pass it on somewhere?
    And, if you try to do anything with homegrown InputMaps then the components stop seeing the events. I wish there was a definitive YOU MUST DO IT THIS WAY tutorial.
    Why is there no factory API that can create UI components pre-attached to actions and with accelerators or mnemonics already set? Then we would not need to write half the code we do now. My solution:
    public class ComponentFactory {
       ActionMap myMap;
       public ComponentFactory(ActionMap map) {
          myMap = map;
       public JButton createButton(String actioncommand) {
           Action a = myMap.get(actioncommand)
           if(a==null)
              return null;
           return new JButton(a);
       public JMenuItem createMenuItem(String actioncommand) {
        // etc...
       public void setAction(Action a) {
           myMap.put(a.getValue(ACTION_COMMAND_KEY),a);
       public void setEnabled(String actioncommand, boolean state) {
           Action a = myMap.get(actioncommand);
           if(a!=null)
               a.setEnabled(state);
    }Is there any concensus as to the best way to handle ActionMaps/InputMaps?

    Hugh,
    >
    The tutorial is a touch short on this subject, whilst
    it is good on how to create and use actions with
    toolbars and the like, the section on InputMaps and
    ActionMaps is far too brief to get the wider picture.
    The API docs on the same is about one paragraph's
    worth.okay, I just checked the tutorial - it's a bit short on the inputMap/actionMap indeed.
    >
    You are mixing up two different issues:
    a) customize a button with an action
    b) bind a keyStroke to an action for an arbitrary
    jComponent
    a) has nothing to do with b)If b) has nothing to do with a) why have MNEMONIC_KEY
    and ACCELERATOR_KEY on the action?Hmm... where do you see a contradiction to my statement? Those keys are part of a) as they are used for customization of the AbstractButtons: the button's mnenmonic/accelerator properties are set to the corresponding values of the action. This propertyChange triggers an update of the keyBinding to the button's "pressed"/"doClick" actions as registered in the actionMap. They are never used (at least not internally by Swing) for b)
    Historically the action is older than the inputMap/actionMap: basically it's an ActionListener (which is more or less a command pattern) plus some (view) state. This "plus" was designed right in the beginning of Swing for a) to enable state sharing between different "buttons" but not really integrated until version 1.4. parallel to that the need for a general mechanism of binding between keyStrokes and "commands" became obvious and inputMap/actionMap were introduced in 1.3. The only action state that's needed for this mechanism to work is the enabled property. All values are ignored - so currently they somehow appear to be overloaded in the context of the inputMap/actionMap. Personally I think they are very powerful because of this extra flexibility.
    >
    There is still not a single diagram; and I maintain
    that it is less than useful to beginners who are not
    familiar with the terminology used. Well, IMO diagrams are not everything - I still think it much easier to understand than the dnd spec or the focus spec f.i.
    >
    you are free to use whatever object you want as akey
    - write a utility method to use the name, if feellike
    doeing so. There is nothing in the framework that
    would single out the name as "the" key to use, The keybindings document specifically states:
    "New actions can be added to a component equally
    easily."
    "The conventional key for an action is it's
    name." If there is a conventional way then it
    should be encouraged with an appropriate API. I get your point. And I definitely agree on following a convention if there is one. Except when the convention is quite immature (to formulate mildly) - and not even followed by Swing internally: most of the default actions registered in the actionMap don't even have a name, the binding is done by string literals ... duplicated in at least two places: the XXLookAndFeel and the ui-delegates.
    Greetings
    Jeanette

  • How to create object for a interface (or) how to use ITextModel Interface

    Hi,
    I am new to vc++ and indesign, i am using windows xp as OS and Indesign CS3 as version, now i want to know how to create an object for the ITextModel Interface (or) how to use the ITextModel interface, for getting the selected text and to manipulate the content, for this i tried myself to the best for more than a week,
    but i not get any solution or any idea to do it, so i post this scrap, if any one knows kindly help me immediately, if u want any more details kindly reply me i am ready to give..
    Regards,
    ram

    Hi, Ram,
    as Jongware already has explained in a previous thread, this is the scripting forum, the SDK forum is next door.
    Besides, your question has already been answered over there in SDK forum - with a reference to an existing example, including documented source. There is also plenty more documentation (780 pages alone in the programming guide) and other working examples.
    The brief response was a perfect match to the vague, general scope of the question. If you want more details, be more specific yourself. Do not just touch such major topics as selection, text, object architecture in one sentence to expect a silver bullet. Instead, stick to one detail, find and read the relevant examples and documentation (did I mention the programming guide?) yourself e.g. using keyword search. Quote your code where you're stuck.
    Being new to both VC++ and InDesign is an explanation but no excuse. IMO, same goes for "using windows xp as OS". All together are bad starting conditions if you intend to write a plugin. Even a seasoned C++ programmer with some years of experience in publishing quirks will easily require months, so don't become impatient after just a week.
    If you need quick results and have a programming background such as a recent Java101, reconsider scripting (this forum). It can bring you amazingly far and you'll learn InDesign through a simplified object model. Same principles apply - there is plenty documentation and a good choice of examples.
    Regards,
    Dirk

  • How to use local interface in my easy code ?

    hi everybody
    I work on an ejb project. My code is like that to test remote interface (and it works) :
    public class TestStudent {
       Properties properties;
       public TestStudent() {
          properties = new Properties();
          properties.put("java.naming.factory.initial",
          "org.jnp.interfaces.NamingContextFactory");
          properties.put("java.naming.factory.url.pkgs",
          "org.jboss.naming:org.jnp.interfaces");
          properties.put("java.naming.provider.url", "jnp://localhost:1099");
          properties.put("jnp.disableDiscovery", "true");
       public static void main(String[] args) {
          TestStudent beanStudent = new TestStudent();
          beanStudent.createBean();
       public void createBean() throws EJBException {
          try {
             InitialContext context = new InitialContext(properties);
             Object object = context.lookup(StudentHome.JNDI_NAME);
             StudentHome studentHome = (StudentHome) PortableRemoteObject.narrow(object,StudentHome.class);
             Student student = studentHome.create();
             student.setName("pirlouit");
             System.out.println(student.getId());
             System.out.println(student.getName());
          } catch (NamingException e) {
             throw new EJBException(e);
          } catch (RemoteException e) {
             throw new EJBException(e);
          } catch (CreateException e) {
             throw new EJBException(e);
    }Then I do quite the same thing to test local interface like in the following code but it doen't work :
    public class TestStudent {
       Properties properties;
       public TestStudent() {
          properties = new Properties();
          properties.put("java.naming.factory.initial",
          "org.jnp.interfaces.NamingContextFactory");
          properties.put("java.naming.factory.url.pkgs",
          "org.jboss.naming:org.jnp.interfaces");
          properties.put("java.naming.provider.url", "jnp://localhost:1099");
          properties.put("jnp.disableDiscovery", "true");
       public static void main(String[] args) {
          TestStudent beanStudent = new TestStudent();
          beanStudent.createBean();
       public void createBean() throws EJBException {
          try {
             InitialContext context = new InitialContext(properties);
             Object object = context.lookup(StudentLocalHome.JNDI_NAME);
             StudentLocalHome studentLocalHome = (StudentLocalHome)object;
             System.out.println("studentLocalHome is null ? "+studentHome.equals(null));
             StudentLocal student = studentLocalHome.create();
             student.setName("pirlouit");
             System.out.println(student.getId());
             System.out.println(student.getName());
          } catch (NamingException e) {
             throw new EJBException(e);
          } /*catch (RemoteException e) {
             throw new EJBException(e);
          }*/ catch (CreateException e) {
             throw new EJBException(e);
    }The print of "student local home is null ?" give me 'true' which is not the answer I want ... so here is the problem. How can I get my entity bean using local interface ?
    For the moment 've got the exception (which appears on instruction "StudentLocal student = studentLocalHome.create();") :
    Exception in thread "main" java.lang.NullPointerException
         at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:118)
         at $Proxy0.create(Unknown Source)Please help !! Thank you very much !

    Write a JSP to test Local Interface. You cannot call Local Interface from a remote JVM.
    Jay
    http://www.javarss.com - Java News from around the world.
    Visit JavaRSS.com and add above signature to your messages. Thanks!

  • How to use multiple Interfaces for the same BS?

    Hi @ ,
    Is it possible to have a scenarion where i am using multiple interfaces in the same BS based upon some conditional field in the message.
    I amnot able to get the solution I know with condition editor I can have multiple receivers but in my scenarion based upon message fiels i have to decide which BAPI to be used and wht mapping and then post it to the same System
    Any help will be highly rewarded
    Regards

    Hi-
    Yes it is possible you can use multimapping for mapping the interfaces.
    To know more about multimapping see
    http://help.sap.com/saphelp_nw04/helpdata/en/21/6faf35c2d74295a3cb97f6f3ccf43c/content.htm
    Some more helpful links
    /people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible

  • How to use kannada interface in oracle 9i?

    hi friends,
    i dont know how to interface in oracle using kannada language.
    pls informe how to do it in using oracle forms 6i.

    Where does one download that interface? (This is the 'Problems with downloads' forum!!)

  • How to use Action with an Accelerator without assigning Action to a Button

    I have an Action
    I have set an Accelerator key to it.
    If I assign the Action to a MenuItem or other Button in my GUI all is well
    However I want the Accelerator to fire the Action when it isn't assigned to the button
    How do I do this, because it doesn't work?

    Use Key Bindings to invoke the Action directly:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html

  • How to use FPGA Interface VIs without FPGA Module

    According to this, http://zone.ni.com/reference/en-XX/help/371599D-01/lvfpgahosthelp/interface_no_module/, I can use the FPGA interface vis to connect to an FPGA (on a 7833R) without installing the FPGA Module. How do I get access to those VIs? Do I have to install the module (but there is no need to activate it?) or is there something else to install that only includes the interface functionality?
    Thanks,
    Chris

    Hey Chris,
    Out of the LV Help i found:
    The FPGA Interface is available with FPGA target driver software. You can use the FPGA Interface functions in a host VI if you have an FPGA target and the appropriate driver software. You do not need the LabVIEW FPGA Module to use the FPGA Interface functions. You need the FPGA Module if you want to develop FPGA VIs.
    I think installing the NI RIO driver adds the palette.
    Christian

  • How to use USB interface with LabVIEW Embedded for ARM

    Hi everybody.
    I am developing an application based on the "LabVIEW Embedded for
    ARM". Now I am doing various tests using
    the evaluation board 2300 (with NXP LPC2378), but soon I will
    dedicate to program the micro used in my project (NXP
    LPC2148).
    During the tests, I have seen that "default" LabVIEW interface allows the use
    of CAN, I2C and SPI interfaces of the micro. I want to know how can I also use the
    USB interface that is on the micros -both LPC2148 and LPC2378- (pin USB_D + / D-, USB_UP_LED,
    USB_CONNECT, VBUS).
    Thanks in advance for your suggestions

    @chueco85
    If you've created an application in LabVIEW for ARM and you build it.
    you can go to tools >> ARM Module >> Show Keil uVision
    then go to he build options.
    the hex file will be created when you do a build.
    with flash magic :http://www.flashmagictool.com/
    you can program your device.
    Wouter.
    "LabVIEW for ARM guru and bug destroyer"

  • HOW TO USE Class Interface CL_GUI_FRONTEND_SERVICES

    Dear All,
    I am working to get output of SMARTFORMS through report into PDF file.Following code i am using inside LOOP.
    *CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
       WINDOW_TITLE         =
       DEFAULT_EXTENSION    = 'PDF'
       DEFAULT_FILE_NAME    = 'PAYSLIP.pdf'
       WITH_ENCODING        =
       FILE_FILTER          =
       INITIAL_DIRECTORY    =
       PROMPT_ON_OVERWRITE  = 'X'
    CHANGING
       FILENAME             = W_FILE_NAME
       PATH                 = W_FILE_PATH
       FULLPATH             = W_FULL_PATH
       USER_ACTION          =
       FILE_ENCODING        =
    EXCEPTIONS
       CNTL_ERROR           = 1
       ERROR_NO_GUI         = 2
       NOT_SUPPORTED_BY_GUI = 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.
    *CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE                    = W_BIN_FILESIZE
       FILENAME                       = W_FILE_NAME
      FILETYPE                        = 'BIN'
    TABLES
       DATA_TAB                        = T_PDF_TAB.
    *IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    I am getting proper output through the above coding.
    But problem is,if there will be a multiple PDF output it always ask the path to save each PDF file as i am using "FILE_SAVE_DIALOG"
    I want all PDF files to save at once by giving default path of PC.
    How can i do this, is there any other method i can use please
    let me know...
    Regards,
    Ankur

    Hi,
    I have used following code..
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
       bin_filesize              =
        filename                  =
       filetype                  = 'ASC'
       append                    = SPACE
       write_field_separator     = SPACE
       header                    = '00'
       trunc_trailing_blanks     = SPACE
       write_lf                  = 'X'
       col_select                = SPACE
       col_select_mask           = SPACE
       dat_mode                  = SPACE
       confirm_overwrite         = SPACE
       no_auth_check             = SPACE
       codepage                  = SPACE
       ignore_cerr               = ABAP_TRUE
       replacement               = '#'
       write_bom                 = SPACE
       trunc_trailing_blanks_eol = 'X'
       wk1_n_format              = SPACE
       wk1_n_size                = SPACE
       wk1_t_format              = SPACE
       wk1_t_size                = SPACE
    IMPORTING
       filelength                =
      changing
        data_tab                  = T_PDF_TAB
    but the error it is giving that "T_PDF_TAB is not a compatible type".

  • How to use Actions ? (.atn files)

    I've downloaded a lot of actions recently, and I'm having trouble simply clicking the "Play" arrow.  On some, I open an image, then click Play for the action...then a bunch of stuff happens really fast, and the end result is exactly what i wanted.
    For other actions, however, the Play button is grayed out.  So I then have to navigate down within the action and click play on the first item within the action.    Another problem is that some actions prompt me to enter OK every step of the way.  Some actions take like 25 steps, so i have to clock OK each time, but in my first example above, other actions do all 25 steps at once without prompting me.   Is there something I am doing wrong?  thanks!

    Click once on the name of the action you want to run to highlight it, then press the play button.
    Avoid clicking in the boxes to the left, which are the "Enable" and "Prompt" functions.
    If  you have changed those boxes, your best bet is to remove and reinstall the set by clicking once on the set name to highlight it then using the trash can, then loading the .atn file again.
    Hope this helps!
    -Noel

  • How to use action links or master-detail event in dashboard prompts?

    Hi,
    I am new to OBIEE 11g. I have created three reports 1.Daily Data Report, 2.Weekly Data Report 3. Monthly Data Report.
    I have created one dashboard prompt in which I have specified choices as Daily, Weekly and Hourly.
    My requirement is that when I select the choice as 'Daily' I should get Daily Data report below Dashboard prompt.
    When I select the choice as 'Weekly' I should get Weekly Data report below Dashboard prompt
    and when I select the choice as 'Monthly' I should get Monthly Data report below Dashboard prompt.
    How this can be achieved in OBIEE 11g?

    Hi,
    What you do is just put this 3 different reports in 3 different dashboard sections and in section condition assign a condition based on presentation variable so that when u select weekly in the prompt only the weekly section condition should be true and other 2 section conditions should be false, in that case only the true section condition will display and false conditions will hidden.
    Try implement this u will definetly can achieve the result.
    Note: Create Variable prompt for this as best practice
    Revert for any queries.
    Mark if helpful/correct.
    Thanks
    Edited by: 934322 on Mar 19, 2013 7:49 AM

Maybe you are looking for

  • Help needed in creating pdf file

    Hi all, I keep coming back to this question again. I chose iText over jasper reports to generate PDF files for some good reasons. in my application I 1. accept file uploaded by the user 2. process the data inside files and separate them into good dat

  • Why does my apple tv keep lagging

    My apple TV keeps lagging/freezing then it catches up with it self when im watching a film from my mac or on itunes and if i bought a film from apple it does the same thing.  Ive had this apple TV for over a year and never had a problem, then all of

  • Application Builder problem on one server but not another

    I am having an Application Builder problem. When I get into App Express and go inside the builder and try to edit a listed application, I get an "http 404 the page cannot be found. The page might have had its name changed or is temporarily unavailabl

  • Send ALV report as email attachment but in background scheduling mode

    Hi All,        I have ALV report which runs fine in  the foreground. But i need to display it in the spool that is by scheduling in the background. can i send an excel attachement as e-mail in the background scheduling?  my report contains 10 columns

  • MSEXchange not rejecting bad email addresses

    I have written a specialized email application In ACCES 2010 for my department. At first I couldn't send email outside our domain so the server folks turned on relay and gave me a static IP address. However, now the mail server does not reject bad em