Best way to access variables from actionCommand

Say I have a method which reads some data from a file, then stores it in a string. I have a button in this method with an ActionListener defined as follows:
                btnOk.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                       otherMethod();
                });Now I need to pass the value of my string to this other method. What's the best way of doing this? Currently I have it declared at the top of the class but it seems a bit messy. I know I could declare the string final, but I need to set it conditionally depending on another variable, so I'd need to declare it before I initialize it's value. If it's declared final this won't work. Is the method I'm using now the usual way of doing this?

Echilon wrote:
Say I have a method which reads some data from a file, then stores it in a string. I have a button in this method with an ActionListener defined as follows:It's not great practice for a GUI event listener to call something that does file I/O. It'll lead to a sluggish interface, since I/O is slow.
A better solution is to invoke code that will cause the I/O to happen in a different thread. I think that Swing actually has built-in support for that, but I don't use Swing much so I don't know.
Now I need to pass the value of my string to this other method. What's the best way of doing this? Currently I have it declared at the top of the class but it seems a bit messy. I know I could declare the string final, but I need to set it conditionally depending on another variable, so I'd need to declare it before I initialize it's value.That doesn't necessarily mean that you can't declare it final. Final just means that once you assign it, you can't change it. You can still set its initial value conditionally.
I agree that it's messy to use fields for no other purpose than to pass values between methods.

Similar Messages

  • What is the best way of accessing application module without page binding?

    Hi All
    I am using Jdeveloper 11g R2 (11.1.2.3) & Weblogic 10.3.5.0
    What is the best way of accessing application module without page binding?
    In my application after user authenticated from LDAP
    I need to read some information from database and set my menues.
    Thanks
    Mohsen

    Hi,
    if you don't have a binding the I am not sure the binding context is created. Anyway, try
    BindingContext.getCurrent().findDataControl("name here as ID in DataBindings.cpx") and see if it returns a valid instance
    Frank

  • What is the best way to import pictures from Lightroom 5 into FCP X

    What is the  best way to transfer pictures from Lightroom 5 into Final Cut Pro X?

    There is no one best way.  If, for instance, you want to be able to zoom into the picture with a Ken Burns effect then you may want to save out a very high res version that will be larger than your video resolution. Just use Lightroom to export a jpg file wherever you want it. You could export it into the Events folder and then choose not to copy it when you import it within FCPx. You could import the picture into iPhoto and then access it directly from within FCPx. Those are two simple, "regular" ways to get it into FCPx but if you are not going to Ken Burns the image by zooming into it and such you will want to crop it in Lightroom to the same size you will be using ie if you are making 720HD video then crop the image to that size and proportion before you export it from Lightroom.

  • Hello! I have a MAC OS X version 10.6.8. What is the best way to access to lion?Thanks

    Hello,
    I have OS X version 10.6.8. What is the best way to access to lion?
    Thanks

    You obtain Lion by purchasing, then downloading and installing it over the internet from the Apple App Store.
    Hope this helps

  • Best way to access my mac G4 files when working on a windows pc laptop

    Hi - I'm looking for ideas on the best way to access files stored on my G4 mac, when working on a pc laptop elsewhere in the house.
    I'm not sure if this involves setting up a network, or whether I should be looking at ftp or even bluetooth.
    Just to explain what I'm after: I'm writing a book, primarily on my g4 (running panther) in my study. But I spend a large proportion of my day running after my rampaging toddler. I'd like to make better use of my time by being able to grab my partner's laptop and write while my toddler is occupied for twenty minutes.
    Messing around with a memory stick etc would just take too long as I'd have to remember to update the main file. It would get very messy!
    I hope someone can help!
    Thanks, Tina
    Message was edited by: tinaMac

    Between the networking question(s) to connect the two different platform
    computers, using Sharing and other settings in each, the next question is
    about the software used in the documents you are to be creating in one
    and sending to the other.
    Do you have a similar word processing software for the PC as in the Mac;
    or something compatible in creating and using .RTF documents, etc. Or,
    if you have a Windows version of AppleWorks, that would work. And the
    TextEdit in your OS X can handle rich text format word processing; and
    probably open basic text from a PC fairly easy. (And Word, etc, can.)
    Issues in sharing, are such that you have to be careful when changing the
    settings in your computers, that you don't accidentally share your computer
    contents with other persons and computers in the vicinity. By wire would be
    the most secure, since Ethernet can be used locally to share.
    Internet and wireless may be a possibility, too; or using a local shared external
    drives, if visible to both computers, depending on the network setup.
    Do you have a USB hard disk drive set up on your wireless network, and
    formatted in Fat32 so the Mac and PC can both see and use it? If so, you
    may be able to send documents to there from the PC and use them in the
    Mac. This may work, and depending on how the files were organized, not
    too hard to keep up with the draft copies generated from the PC for use in
    the Mac at a later time, and so on. This way, both computers would not
    need to be on, to send & receive a file...
    {For that matter, using a Google Account could be helpful;
    to just email the writing to yourself, at any computer.}
    Anyway, there are several possibilities, including those in the link to another
    discussion on that topic per the above post.
    Good luck & happy computing!

  • What are the best ways to share photos from iPhoto?

    What are the best ways to share photos from iPhoto?

    If you use Adobe Photoshop, or even Adobe Photoshop Elements, stay as far away from iPhoto as possible.
    iPhoto does not play nice with Adobe software or with software from any other third party developer.
    iPhoto will hide your image files in a library paradigm where you have no access to them other than through iPhoto.

  • How is the best way to remove something from a photo?

    How is the best way to remove something from a photo?

    This is difficult to answer without fully knowing what you are trying to do.
    That said, a few excellent and user friendly retouching tools include:  The Spot Heealing Brush Tool, Healing Brush Tool, Patch Tool, and the Cloning Stamp Tool.

  • How is the best way to read data from an iphone if you lost your itunes data after a crash?

    How is the best way to read data from an iphone if you lost your itunes data after a crash?

    How is the best way to read data from an iphone if you lost your itunes data after a crash?

  • Is there any way to access files from the Classic environment to my iMac running on Leopard (10.5.8)?

    Is there any way to access files from the Classic environment to my iMac running on Leopard (10.5.8)?

    Sorry, no.

  • Is there a way to access 11i from outside other than Self service?

    Is there a way to access 11i from outside other than Self service?
    I could connect any application from inside the firewall (basically router) and can not access screens from outside. Eventhough port forwarding 80 allows us upto initial screen, it does not go further.
    Any workaround/suggestions
    Jiltin

    Hi Jiltin,
    If you can migrate your forms server into Forms Listener Servlet.This will allow you to use forms outside firewall provided atleast one port(assuming yours 80) is open.
    Ref to the M.Link Note 201340.1 for how to setup forms listener servlet.
    Magesh

  • Whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    Check out > OS X Lion: How to use Migration Assistant to transfer files from another Mac

  • What could be the best way to Export data from 11.5.8 instance to 12.1.2?

    Hi All
    What could be the best way to Export data from 11.5.8 instance to 12.1.2?
    Release: 11.5.8
    OS: Oracle Solaris on SPARC (32-bit) verison 9
    DB: 9.2.0.1
    Thanks in advance

    What kind of data you are looking to move?
    Database export/import is only supported for full database export/import and the application release should be the same on the source/target nodes.
    You can move the setup using iSetup or FNDLOAD.
    Thanks,
    Hussein

  • What is the best way to import photos from aperture to my new Lightroom

    What is the best way to import photos from aperture to my new Lightroom ?

    See if this helps
    http://lightroomsolutions.com/articles/migrating-from-aperture-to-lightroom-where-do-i-beg in/

  • The best way to import photos from Picasa to iPhoto

    Hi,
    Many of my friends share their pictures online using picasa. Sometimes, I'd like to copy these pictures to keep a backup offline. As a software, I use iPhoto; not picasa. What is the best way to import pictures from picasa to iPhoto?
    I first tried to subscribe to the RSS feed using iPhoto and then copy the pictures from there to my library, but then the dates of the pictures are set wrong: instead of indicating when the picture was shot, it indicates some other date (I guess it indicates the date when the picture was uploaded to picasa).
    Then I decided to install the software picasa.app. From the webalbum of my friends, I could download the pictures directly to picasa.app. Then I exported them to the desktop, and from there imported them to iPhoto. The dates where set correctly, but I lost all the titles and comments of the pictures.
    Do you have any method to download the pictures while keeping both the dates and the titles correctly?
    Thanx!

    There is a direct option in Organizer which lets you import from iPhoto. This is under Import dropdown menu in left panel.
    If you are importing from iPhoto'09, your Tags, Albums Events, captions, star rating would also get imported apart from your media. This works differently for iPhoto'011 where you can get only the media to the Organizer,
    Just a couple of things to know:
    1. If in iPhoto preferences, you have chosen to create copies of your photos in iPhoto library and your library hence refers to the media store inside the library package, then on importing from iPhoto, Organizer would create copies of all those media under your pictures folder. That means, it would not corrupt your iPhoto package or modify it in any way.
    2. However, if in iPhoto, you are organizing by using references to original location on your Hard drive i.e. you are not creating copies of media in iPhoto library then on importing from iPhoto to Organizer, the Organizer would also use the same references and would not create copies of the media.
    Hope that helps!
    ~V

  • Best way to transfer files from old Macbook Pro to new one?

    I just got a new Macbook Pro from Apple...YEEEEAAAHHHH! 
    So....
    What's the best way to transfer files from old Macbook Pro to new one?  I know Migration assistant, but is there a recommended way?  I don't want to put do a system restore or transfer everything from the old laptop, but I do want to move important things like photos, music, documents and such over.  Any suggestions on best way to do this?
    Another question, perhaps subquestion.  If I have, say, an older version of iPhoto but a newer version of one on my new Macbook Pro, will it still transfer photos no problem?
    Just looking for hints from the experts so this puppy is set up in the best way possible.

    Just one comment on this:
    ‘If I have, say, an older version of iPhoto but a newer version of one on my new Macbook Pro, will it still transfer photos no problem?’
    the problems are ALWAYS in the reverse way, when you have the newest (or a newer) version of a given app, and wish to transfer its library to an older version.
    Otherwise, see the link to Pondini.
    I have been using Martin Jahn’s iBackup, with which I have become accustomed and works fine. It also makes daily backups. Its advantage over other apps is that you may add whatever you wish to save, beside its default settings (which you may delete or cancel, of course, even if not recommended); it also has a friendly interface and easily customizable. Of course, this is a personal view, you may try other methods as well, or other backup apps. All are good if you are satisfied and correspond to your needs.

Maybe you are looking for