Can't use inherited method with JButton

I am trying to use the getActionListeners() method on a JButton. The method is inherited from the AbstractButton class. However, when I try to compile with this line...
ActionListener CurrentListeners[] = OKButton.getActionListeners();I get the following error:
Method getActionListeners() not found in class javax.swing.JButton.
I am also using the removeActionListener() method, which is inherited from the same object, and the compiler has no problem with that!

Okay, then does anyone know how I can change the
ActionListener for a JButton? I want to use the
removeActionListener(ActionListener l) method and then
addActionListener(...). However, since I can't get
the current ActionListener, I have nothing to pass
into the remove method.It's my belief that's this is why this method was added to AbstractButton in JDK 1.4. It makes life so much easier. Why don't you download the JDK 1.4 and install it into your IDE?
Otherwise, you should subclass JButton as someone else suggested and provide an accessor method for the listener.

Similar Messages

  • Why not to use static methods - with example

    Hi Everyone,
    I'd like to continue the below thread about "why not to use static methods"
    Why not to use static methods
    with a concrete example.
    In my small application I need to be able to send keystrokes. (java.awt.Robot class is used for this)
    I created the following class for these "operations" with static methods:
    public class KeyboardInput {
         private static Robot r;
         static {
              try {
                   r = new Robot();
              } catch (AWTException e) {
                   throw new RuntimeException(e + "Robot couldn't be initialized.");
         public static void wait(int millis){
              r.delay(millis);
         public static void copy() {
              r.keyPress(KeyEvent.VK_CONTROL);
              r.keyPress(KeyEvent.VK_C);
              r.keyRelease(KeyEvent.VK_C);
              r.keyRelease(KeyEvent.VK_CONTROL);
         public static void altTab() {
              r.keyPress(KeyEvent.VK_ALT);
              r.keyPress(KeyEvent.VK_TAB);
              r.keyRelease(KeyEvent.VK_TAB);
              r.keyRelease(KeyEvent.VK_ALT);
                   // more methods like  paste(), tab(), shiftTab(), rightArrow()
    }Do you thinks it is a good solution? How could it be improved? I've seen something about Singleton vs. static methods somewhere. Would it be better to use Singleton?
    Thanks for any comments in advance,
    lemonboston

    maheshguruswamy wrote:
    lemonboston wrote:
    maheshguruswamy wrote:
    I think a singleton might be a better approach for you. Just kill the public constructor and provide a getInstance method to provide lazy initialization.Thanks maheshguruswamy for advising on the steps to create a singleton from this class.
    Could you maybe advise also about why do you say that it would be better to use singleton? What's behind it? Thanks!In short, it seems to me that a single instance of your class will be able to coordinate actions across your entire application. So a singleton should be enough.But that doesn't answer why he should prefer a singleton instead over a bunch of static methods. Functionally the two are almost identical. In both cases there's only one "thing" on which to call methods--either a single instance of the class, or the class itself.
    To answer the question, the main reason to use a Singleton over a classful of static methods is the same reason the drives a lot of non-static vs. static decisions: Polymorphism.
    If you use a Singleton (and and interface), you can do something like this:
    KeyboardInput kbi = get_some_instance_of_some_class_that_implements_KeyboardInput_somehow_maybe_from_a_factory();And then whatever is calling KBI's public methods only has to know that it has an implementor of that interface, without caring which concrete class it is, and you can substitute whatever implementation is appropriate in a given context. If you don't need to do that, then the static method approach is probably sufficient.
    There are other reasons that may suggest a Singleton--serialization, persistence, use as a JavaBean pop to mind--but they're less common and less compelling in my experience.
    And finally, if this thing maintains any state between method calls, although you can handle that with static member variables, it's more in keeping with the OO paradigm to make them non-static fields of an instance of that class.

  • (261718088) Q: Can you use xm:multiple with Objects other than String?

    Q: Can you use xm:multiple with Objects other than Strings?
    <br>
    A: You bet. Attached find a text file with some code from the example I showed
    today, a version of the multipleSayHiTo() method that has a parameter of an Array
    of Person objects rather than a parameter of an Array of Strings. The code within
    the text file comes from the Greeting.jws file (the Greeting Web Service).
    [multiple.txt]

    So you are saying that the recovery discs I made do include the copy of windows that was originally installed?
    Absolutely! They will restore the hard disk to its original out-of-the-box contents. Follow the instructions in the section Restoring from recovery DVDs/media, which begins on p. 73 of the User's Guide.
       Satellite A660 Series User’s Guide
    maybe i can make a deal with wd to have them swap this drive out for the BEKT instead...
    That would be a good idea in any case.
    As I said, the 10-fc12-045d error would not be due to the drive's being AFT, but more likely the discs are not being read properly. New discs can be obtained from Toshiba. Scroll down to Get Recovery Media here
    -Jerry

  • How do i run an external monitor with my macbook and change settings so that when i close the lid the signal to the monitor is not lost and i can continue using the mac with a mouse and a wireless keyboard?

    How do i run an external monitor with my macbook and change settings so that when i close the lid the signal to the monitor is not lost and i can continue using the mac with a mouse and a wireless keyboard?

    No, nothing will prevent the computer from going to sleep when you close its display except third-party hacks that are designed to do exactly that. I strongly advise against using any of those, as they may interfere with successful entry into clamshell mode (and they carry other downside risks as well). Just wait until the computer is asleep (with its sleep light pulsing), then press any key on the keyboard. It sounds as though your setup is working as it's designed to do.

  • How can I use an iPad with two itunes accounts?

    How can I use an iPad with two itunes accounts?
    Hi there
    My partner has a works iPad, which has her works Apps on (ones that are specifically made by her company and are NOT available in the App store).
    What I want to be able to do is to ALSO have my itunes account on there so that I can put all the apps I have purchased previously from my iPhone on it.
    This is so I can put on VLC player (thats already in my itunes account) so I can add videos to the iPad.
    How do I do this please?
    I tried it before by connecting it to my mac, but it wiped everything off the iPad completely and also deleted the data settings for using 3G.
    So I want to avoid this happening again the future as it had to be sent back to her head office to be sorted again.
    Any advise please?
    Thanks

    You can't. The iPad is desgined to be a 'one user' device and only really works with one apple ID at a time.
    The only way would be if she, at work and with her work apple id, downloaded your apps (repurchasing them of course).
    It's not meant to be a multiple user/multiple ID device.

  • How can i use text expander with the new Mavericks,

    how can i use text expander with the new Mavericks,

    I regret upgrading to mavericks for the same reason
    ftamez wrote:
    how can i use text expander with the new Mavericks,
    Now I have been searching - and you have to buy an app and it will cost you $34.99 (what a rip off)

  • HT202213 can i use home sharing with my wife who has a different apple id

    Can I use home sharing with my wife who has a different apple id so we dont buy the same songs twice

    Wow, great question mhaney73.  There's got to be a way.  I have that problem as well, double songs all over the place. 

  • HT4363 Can I use home sharing with FaceTime?

    Can I use home sharing with FaceTime

    Winston,
    Thanks for the promt reply. But my problem was that I did not know how to use the air play. I looked around and figured it out.
    thanks,

  • Can I use my macbook with a mac mini

    can I use my macbook with a mac mini

    You mean can you network the two Macs?
    What OS X version are you running on both of your Macs?

  • How can i use "icloud backup" with ios 4.2.1?

    How can i use "icloud backup" with ios 4.2.1? I tried to update my ihpone 3G wih the newest IOs. Seems not to be possible.

    You cannot.
    It requires ios 5.
    Your iphone can only go to 4.2.1

  • I just downloaded ios7 now i can only use the phone with the speaker, how can i fix this?

    I just downloaded ios7 now i can only use the phone with speaker, how can i fix this?

    x

  • How can I use the NI PXI-6508 with Lab View 7? what are the first steps to get started??How can I use the channels with lab view 7????

    I have a 8 slot PXI system with 2 NI PXI 6508 and 1 DMM 4070 in it. I want to get started with programming the digital I/O cards (6508)! How can I use this cards with LabView 7?what is the best way to get started, or where can I get examples showing how to use the several channels?
    Thanks!
    Philipp

    Philipp,
    The best way to get started is to decide if you want to use traditional NI-DAQ or NI-DAQmx. Recently we released NI-DAQ 7.1 which provides NI-DAQmx support for the PXI-6508. In my opinion, NI-DAQmx is more efficient and much easier to use.
    To get started with examples, simply launch LabVIEW and go to Help>>Find Examples. Then expand Hardware Input and Output>>DAQmx and select the appropriate digital group for your application. This should help get you started.
    Please repost if you need addition assistance. Good luck with your application!

  • I had Leopard on may Mac. I upgraded to Mountain Lion using Snow Leopard. I can't use my video with Mountain Lion. Can I load Snow Leopard on an external hard drive so I can use it with my camera?

    I had Leopard on may Mac. I upgraded to Mountain Lion using Snow Leopard. I can't use my video with Mountain Lion. Can I load Snow Leopard on an external hard drive so I can use it with my camera?

    First, you cannot do this if you have a Boot Camp partition.
    Second: Create a new partition.
    1. Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    After the main menu appears select Disk Utility and click on the Continue button. Select the hard drive's main entry then click on the Partition tab in the DU main window.
    2. You should see the graphical sizing window showing the existing partitions. A portion may appear as a blue rectangle representing the used space on a partition.
    3. In the lower right corner of the sizing rectangle for each partition is a resizing gadget. Select it with the mouse and move the bottom of the rectangle upwards until you have reduced the existing partition enough to create the desired new volume's size. The space below the resized partition will appear gray. Click on the Apply button and wait until the process has completed.  (Note: You can only make a partition smaller in order to create new free space.)
    4. Click on the [+] button below the sizing window to add a new partition in the gray space you freed up. Give the new volume a name, if you wish, then click on the Apply button. Wait until the process has completed.
    You should now have a new volume on the drive.
    It would be wise to have a backup of your current system as resizing is not necessarily free of risk for data loss.  Your drive must have sufficient contiguous free space for this process to work.
    Third: Install Snow Leopard.
    Boot from your Snow Leopard DVD. Follow instructions for installation being sure that before you actually install Snow Leopard you have selected the new partition as your target destination.
    Booting From An OS X Installer Disc
      1. Insert OS X Installer Disc into the optical drive.
      2. Restart the computer.
      3. Immediately after the chime press and hold down the "C" key.
      4. Release the key when the spinning gear below the dark gray Apple logo
          appears.
      5. Wait for installer to finish loading.

  • Can I use my iPad with airport extreme to retrieve files from a USB connected hard drive?

    Can I use my iPad with airport extreme to retrieve files from a USB connected hard drive?

    Yes, I believe so. Please check out the NetPortal app. I don't have an iPad, but I use it on my iPod Touch to access files on my Time Capsule. It is available from the iTunes App Store.

  • I just purchased a 3TB Time Capsule.  I live in Italy and have 220V power.  The Time Capsule is rated for that, but the cord says 125V.  Can I use this cord with an adapter, or do I need to buy a new cord at an Italian store?

    I just purchased a 3TB Time Capsule.  I live in Italy and have 220V power.  The Time Capsule is rated for that, but the cord says 125V.  Can I use this cord with an adapter, or do I need to buy a new cord at an Italian store?

    Due to the kind of plug used the US power cord is rated at the 125v value.. and legally we cannot advise you to use on higher voltages.. although I have never had issues in Australia.. 240v.
    But adapters from your Euro power plug to US are generally ugly .. unsightly things.. and often sit high above the socket and are none too stable.. I agree with Bob.. just go out and buy a standard figure 8 power cord.. check with Apple in Italy for a white one.. if you are going to have it on show.. black are far more common. Or even check ebay for a standard power Apple power cord as a number of items they sell use the figure8 socket. 

Maybe you are looking for

  • Cannot open. Message on screen XUL error: platform version '1.9.2.17' is not compatible

    Cannot connect to the internet. Error message XUL as follows-- Platform version '1.9.2.17' is not compatible with minversion >=1.9.2.18 maxversion <=1.9.2.18 Pressing "OK" does not close the box or lead to any help.

  • HP PSC 2355 Has anyone found a solution that worked ?

    Re: HP PSC 2355 all in one Has anyone found a solution that worked? This printer used to work fine with Tiger – after a lot of headaches setting it up. Seemingly, after downloading a latest 10.4 up-grade, I lost all functions with this 3 in 1 printer

  • Cancellation of hours worked

    Hello all, I am new to the SAP world and could use some advise. We are using CRM field service and are using service confirmations to log our enginners time spent on the job. We also use the service confirmation for invoicing the hours worked. What w

  • Currency Format Mask

    I want to make some number field have thier own currency format mask. I wrote in controller like followed. OAMessageTextInputBean salary = (OAMessageTextInputBean)webBean.findChildRecursive("Salary"); if (salary != null) { salary .setAttributeValue(O

  • Sound on itues/quick time stopped working

    While podcasts and audio files still play, after 5 months of working fine the audio on my iTunes videos do not work. The files begin to play without any sound and then just repeat the first bit of sound over and over. This seem to happen a day or so