How do i create a static function in a class and implement ActionListener?

i am trying to create a pop up dialog box in a seperate class.
and i want to make the Function static, so that i only need to access it with the class name.
But how do i have a ActionListener ?
everything in a static function is static rite?

import java.awt.*;
import java.awt.event.*;
public class StaticFunction
    Dialog dialog;
    private Panel getUIPanel()
        Button button = new Button("show dialog");
        button.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                if(dialog == null)
                    dialog = OutsideUtility.showDialog("hello world");
                else if(!dialog.isVisible())
                    dialog.setVisible(true);
                else if(dialog.isVisible())
                    dialog.dispose();
                    dialog = null;
        Panel panel = new Panel();
        panel.add(button);
        return panel;
    private WindowListener closer = new WindowAdapter()
        public void windowClosing(WindowEvent e)
            System.exit(0);
    public static void main(String[] args)
        StaticFunction sf = new StaticFunction();
        Frame f = new Frame();
        f.addWindowListener(sf.closer);
        f.add(sf.getUIPanel());
        f.setSize(200,100);
        f.setLocation(200,200);
        f.setVisible(true);
class OutsideUtility
    public static Dialog showDialog(String msg)
        Button button = new Button("top button");
        button.setActionCommand(msg);
        button.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                Button button = (Button)e.getSource();
                System.out.println(button.getActionCommand() +
                                   " from anonymous inner listener");
        button.addActionListener(new ButtonListener());
        Button anotherButton = new Button("bottom button");
        anotherButton.setActionCommand("another button");
        anotherButton.addActionListener(localListener);
        Panel north = new Panel();
        north.add(button);
        Panel south = new Panel();
        south.add(anotherButton);
        Dialog dialog = new Dialog(new Frame());
        dialog.addWindowListener(closer);
        dialog.add(north, "North");
        dialog.add(new Label(msg, Label.CENTER));
        dialog.add(south, "South");
        dialog.setSize(200,200);
        dialog.setLocation(425,200);
        dialog.setVisible(true);
        return dialog;
    private static WindowListener closer = new WindowAdapter()
        public void windowClosing(WindowEvent e)
            Dialog dialog = (Dialog)e.getSource();
            dialog.dispose();
    private static ActionListener localListener = new ActionListener()
        public void actionPerformed(ActionEvent e)
            Button button = (Button)e.getSource();
            System.out.println(button.getActionCommand() +
                               " from localListener");
    private static class ButtonListener implements ActionListener
        public void actionPerformed(ActionEvent e)
            Button button = (Button)e.getSource();
            String ac = button.getActionCommand();
            System.out.println(ac + " from ButtonListener");
}

Similar Messages

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • How do I create an unordered list with three items and link to id's

    How do I create an ordered list with three items and linl to id's on my page

    Thanks, I guess what I was really asking, Is there a n option in the insert menu or somewhere where Dreamweaver does it for you.
    I am not clear on what you are wanting DW to do for you?  Is it that you want it to insert a three item unordered list?  No - there's no such function.  You would need to click in Design view where you want the list to go, click on the bulleted list icon on the Property inspector, and then enter the three items separated by carriage returns.  Then you'd have to link each item specifically.
    To enter the named anchors to element ID values, CS5 has no way to do this.  You'd have to enter those links manually.

  • I just saved my iphoto original library to my external hard drive, now how do i create new space on my hard drive and create a new iphoto library

    i just saved my iphoto original library to my external hard drive, now how do i create new space on my hard drive and create a new iphoto library

    Trash the copy of the library you just moved. Then Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Create Library'
    But do you want to have two iPhoto Libraries? Why not just use the one on the External?

  • How do I create a new document in Photoshop CC and have it 300 dpi?

    How do I create a new document in Photoshop CC and have it 300 dpi? I am doing digital scrapbooking and need to have my layout in Photoshop 12 x 12 so it is a scrapbook page and 300 dpi and I hope this doesn't sound stupid but I don't even know what dpi means.
    Thank you

    File>New
    Set preset to print or US Paper
    (typing width and height values will change the preset to custom)
    Set width to 12 inches
    set height to 12 inches
    set ppi to 300 (should already be this if you used the print preset)
    Click OK

  • How do I create Outgoing Mail Policie,Outgoing content filters and individual content filters?

    IronPort C160.
    async OS 6.5.3
    Server 1 and server 2 are communicating through ironport.( and also scanning)
    Server 1 we have setup domain abc.lk and yy.abc.lk in same server, this reside on DMZ. same segment ironport is connected,
    Server 2: we have setup separate server int.abc.lk which is resided on internal lan.
    Server 1 and server 2 should have to communicate internally, but server2 should not communicate to outside the world (eg. [email protected])
    How do I create "Outgoing Mail Policies, Outgoing content filters and the individual content filters?
    Note: Now server 1 and server2 are communicating internal and also communicating external ([email protected]), I need server 2 not to communicate external ([email protected]) it should be block and also do not block server 2 communicating to server1
    I have attached diagram also.
    Thanks.
    sumathi.

    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-parent:"";
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-para-margin:0cm;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:"Times New Roman";
    mso-ansi-language:#0400;
    mso-fareast-language:#0400;
    mso-bidi-language:#0400;}
    Hello Sumathi,
    (Thanks for adding a diagram, that helps understanding your situation)
    I think the simplest solution is to create a filter that allows server 2 (based on it's IP) to communicate with the internal domains, and drop the messages when they are targeted to any other domain
    so:
    filter source IP = servers
    condition: message to: is NOT abc.lk or yy.abc.lk
    action: drop message
    hope this helps!
    Steven

  • How do I create a digital book that fits tablets and computer monitor sizes?

    How do I create a digital book that fits tablets and computer monitor sizes?
    Example: An 8.5 X 11, 2 column Word document with pictures, approximately 100 pages.
    Must I also publish the book in a 5X8 format or does Acrobat have something that will do that for me?

    Starting at the end:
    - When the movie or tv show does transfer onto your iphone/ipod touch you will be able to see it in the expanded view of your device in the "DEVICES" section.
    - If the files are not on your device, then:
         -- confirm you have SD or HD-SD video. HD-only content will not play and probably will not even sync. iTunes seems to reliably have SD versions with their HD distributions so this should not be an issue
         -- confirm you are synch-ing the content to the ipod device by browsing the DEVICE view's Movie or TV Show tabs to confirm the movie or episode is 'checked'
    - If the files are on the iPod and you cannot find them, check your Settings: General for Restrictions.  If you restrict, for example the movies to "G" rating. PG and higher movies will sync but you will not be able to find them on the iPod!

  • How do I create 2 Recovery partitions: one for Lion and one for Mountain Lion?

    Well that is basically the question:
    How do I create 2 recovery partitions: one for Lion and one for Mountain Lion?
    Reason is that I would like to keep the option to return to Lion, or even better, have a seperate partition for eacht?

    can I access my programs from the other partition, so I can save space ...
    No, as far as I know, each one is completely separate - especially if you're dealing with two different versions of OS's.
    is it possible to safely make an extra partion on a running drive (it is my main computer ...) The disk is large enough ...
    how large would this have to be
    I've personally never done it on a running drive - have read it's possible, but don't want to suggest it since I've never done it and wouldn't be sure about the steps. This is how I got to two partitions on my iMac:
    Originally, I had just one partition with Snow Leopard. I used CCC to clone that to an external drive. Booted into that drive and used DU to partition and erase the internal. I then cloned the new clone back. Also cloned the same thing to the other partition which I then upgraded to Lion. So I had two OS's - SL and Lion. I've now decided to clone my SL to an external drive for occasional use and installed ML on that partition - so now I have Lion and ML.
    There are two ways to get a "fresh" install: either download the OS again and install it on a partition of your choice or, as I've done as well, copy the installer to a safe place so you don't need to download it again. It does include whatever apps/software is included in the OS.  I've designated two smaller partitions on externals as my "fresh" installs of both Lion and ML for emergency or reinstall purposes (this is my way of dealing with not having install DVDs) - I took the time to install it there and then slowly add fresh installs of my important apps (either via download or install CD) - don't bother with the little/less used stuff, a current copy of that can be downloaded if and when I need it. I don't really update those two - that can also be done if/when I need it since that'll always change.
    So, yesterday, I decided I wanted to start fresh with ML - booted into my fresh install of Lion (on external), wiped the SL partition on my internal and installed Lion. Decided to download a fresh copy of the ML installer and installed that. Then ran Software Update. After that, repaired permissions. Then I methodically opened every third party app and checked for updates - installed those where necessary. After all that, I simply copied (drag 'n drop) my entire Documents folder (which contains all my important data,, photos, etc) over from another backup.
    This took a while, but mostly because of the long download times; the installs weren't all that bad. I should be running a really clean system now, especially since nothing was ported over except my Documents folder.

  • How do I create new folders in mail on IPad and IPhone for saving emails?

    How do I create new folders in mail on IPad and IPhone for saving emails?

    You can't do it on the iPad you would need to do it on your computer and the folder will be seen by your account on the iPad and iPhone only if they are IMAP and Exchange accounts. POP accounts are not supported for folders. 

  • How can I create packages procedure & function in user-define Library

    hi.
    i am already created packages procedure & function in database and use so on.
    now i would like to create these in library file.
    please anyone give me example of any procedure or function to store in library.
    thanks
    Ali

    <FONT FACE="Arial" size=2 color="2D0000">> please send me one simple example for create library
    then create any function in library.
    2nd is any package can be create in library or not??
    Thanks S.K
    AliHave you checked the link?
    A simple example is provided.
    I think What I understood from your post is that, you want to put function/ Proc and want to call that as Library ..
    Which is not  possible.
    For exampel an external routine is a third-generation language procedure stored in a
    dynamic link library (DLL), registered with PL/SQL, and called by the DBA to perform
    special-purpose processing.
    In Unix a dynamic link library is known as a shared object (so).
    At run time, PL/SQL loads the library dynamically, then calls the routine as if it were a
    PL/SQL subprogram. To safeguard our database, the routine runs in a separate address
    space, but it participates fully in the current transaction. Furthermore, the routine can
    make a call back to the database to perform SQL operations.
    To identify a DLL we have to use CREATE LIBRARY command.
    The CREATE LIBRARY command is used to create a schema object, library, which
    represents an operating-system shared library, from which SQL and PL/SQL can call
    external third-generation-language (3GL) functions and procedures.
    Learn something more on External Procedures
    -SK
    </FONT>

  • How can I create a conversion function?

    Hi!
    I want to know hot to create a conversion function.
    I want to display at program screen the format 000.000.000-39 but register 00000000000(char 11).
    Thanks

    Yes you can.  I will point you to an example.  You can do the same.
    1. Display domain PS_POSNR in SE11.
    2. Click on the Definition tab.
    3. Look at the field called Convers routine. It says ABPSP
    4. Double-click on this field.  This shows two function modules, one called *..INPUT and the other called *..OUTPUT.
    You will have to create a function group with those two function modules and assign the conversion routine in the domain,

  • How can I share a static field between 2 class loaders?

    Hi,
    I've been googling for 2 days and it now seems I'm not understanding something because nobody seems to have my problem. Please, somebody tell me if I'm crazy.
    The system's architecture:
    I've got a web application running in a SunOne server. The app uses Struts for the MVC part and Spring to deal with business services and DAOs.
    Beside the web app, beyond the application context, but in the same physical server, there are some processes, kind of batch processes that update tables and that kind of stuff, that run once a day. Theese processes are plain Java classes, with a main method, that are executed from ".sh" scripts with the "java" command.
    What do I need to do?
    "Simple". I need one of those Java processes to use one of the web app's service. This service has some DAOs injected by Spring. And the service itself is a bean defined in the Spring configuration file.
    The solution is made-up of 2 parts:
    1. I created a class, in the web app, with a static method that returns any bean defined in the Spring configuration file, or in other words, any bean in the application context. In my case, this method returns the service I need.
    public class SpringApplicationContext implements ApplicationContextAware {
         private static ApplicationContext appContext;
         public void setApplicationContext(ApplicationContext context) throws BeansException {
              appContext = context;
         public static Object getBean(String nombreBean) {
              return appContext.getBean(nombreBean);
    }The ApplicationContext is injected to the class by Spring through the setApplicationContext method. This is set in the Spring configuration file.
    Well, this works fine if I call the getBean method from any class in the web app. But that's not what I need. I need to get a bean from outside the web app. From the "Java batch process".
    2. Why doesn't it work from outside the web app? Because when I call getBean from the process outside the web app, a different class loader is executed to load the SpringApplicationContext class. Thus, the static field appContext is null. Am I right?
    So, the question I need you to please answer me, the question I didn't find in Google:
    How can I share the static field between the 2 class loaders?
    If I can't, how can I load the SpringApplicationContext class, from the "Java batch process", with the same class loader my web app was started?
    Or, do I need to load the SpringApplicationContext class again? Can't I use, from the process, the class already loaded by my web app?
    I' sorry about my so extensive post...
    Thank you very much!

    zibilico wrote:
    But maybe, if the web service stuff gets to complicated or it doesn't fulfill my needs, I'll set up a separate Spring context, that gets loaded everytime I run the "Java batch process". It'll have it's own Spring configuration files (these will be a fragment of the web app's config files), where I'll define only the beans I need to use, say the service and the 2 DAOs, and also the DB connection. Additionally, I'll set the classpath to use the beans classes of the web app. Thus, if the service and DAOs were modified in the app server, the process would load the modified classes in the following execution.You'll almost certainly have to do that even if you do use RMI, Web services etc. to connect.
    What I suggest is that you split your web project into two source trees, the stuff that relates strictly to the web front end and the code which will be shared with the batch. The latter can then be treated as a library used by both the batch and web projects. That can include splitting Spring configuration files into common and specific, the common beans file can be retrieved from the classpath with an include. I regularly split web projects this way anyway, it helps impose decoupling between View/Controller and Model layers.
    On the other hand, you might consider running these batch processes inside the web server on background threads.

  • How do I create my own custom persona to use and share?

    I would like to create my own persona and then be able to share with Firefox users. I am clueless as to how to get started. I am sure the information is somewhere in the Mozilla Help database, but have yet to locate it. I just want to create a simple persona with some photos and graphics I have on my computer. I don't really know anything about code. Thanks for your help!

    Google Search: '''firefox create a persona'''
    * '''Personas for Firefox''' | How to Create Personas<br>https://www.getpersonas.com/en-US/demo_create
    * '''Personas for Firefox''' | Frequent Questions<br>http://www.getpersonas.com/en-US/faq
    * '''Personas for Firefox''' | Getting Started<br>http://www.getpersonas.com/en-US/getting_started
    '''I think you'd have a lot more fun with Styles though''', personas tend to hide things on toolbars, styles can be more helpful (or just as bad)
    * '''Stylish''' :: Add-ons for Firefox<br>https://addons.mozilla.org/en-US/firefox/addon/stylish/
    * '''Restyle the web with Stylish!''' - userstyles.org<br>http://userstyles.org/
    * '''Scrollbar Context Menu''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/54
    * '''Scrollbar Menu''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/52
    * '''Link Warning''' - Themes and Skins for Mozilla - userstyles.org<br>http://userstyles.org/styles/1301
    * '''Tabs, Enlarge list-all-tabs button''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/18553
    * '''Tabs Bar Minimal Size''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/9043
    * '''Tab Color Underscoring active/read/unread (Fx3.6)''' - Themes and Skins for Browser - userstyles.org<br>http://userstyles.org/styles/24728

  • How can I Create a Client Configuration File for RemoteApp and Desktop Connection with Server 2012?

    I have a working RDS RemoteApp site and looking to test out the feature in Windows 7 Control Panel\All Control Panel Items\RemoteApp and Desktop Connections
    I came across this link: Create a Client Configuration File for RemoteApp and Desktop Connection and I believe this is what I need to do first, but these instructions are for
    Server 2008, and I'm running 2012.
    Any suggestions or tips on how I can begin testing this with Server 2012?

    Hi,
    You can manually enter the path to the 2012 feed and it will connect and download the RemoteApps and Desktop connections.
    If you need a sample .wcx file I have posted one here a couple of times.  If you want I will look for it and post a link.
    -TP
    I tried adding my URL's below, these are sample links that work for me right now for when I log into the web page, but neither of these work.  And I'm not sure what I would need to do with or how to create a .wcx file.
    When I type in my URL of: https://connect.mydomain.org/RDWeb, I get redirected to: 
    https://connect.mydomain.org/RDWeb/Pages/en-US/login.aspx?ReturnUrl=/RDWeb/Pages/en-US/Default.aspx

  • How do I create a report of what is run and when on Crystal Server

    In crystal server, how do I create a report that will tell me the name of all of my reports and the time it is scheduled to run?
    I get the feeling it is in the Query Builder,  but I have no idea what the names of all of these tables are.
    Anyone ever done this or know of another way to do this?

    Please download https://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/404170c1-59ae-2b10-b19f-c86764e759a5#rating and read the section titled "Auditing Reports".

Maybe you are looking for