Proper way to pass 'this' to an anonymous listener

I have added a button to copy some information to the clipboard. Instead of a class-level actionPerformed() method I am using an anonymous listener:
     JButton jb = new JButton("Copy QE");
     jb.setBackground(bgc);
     jb.setForeground(Color.lightGray);
     jb.setToolTipText("copy the information below to the clipboard");
     final HelpBox that = this;
     jb.addActionListener( new ActionListener() {
         public void actionPerformed(ActionEvent e) {
          StringSelection ss = new StringSelection(that.toString());
          Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
          cb.setContents(ss, SIHwheel.logBox);
     });It seems to be working fine. I am wondering, though, is the final declaration of that the proper way? Is there a better overall methodology?

A common approach is to encapsulate the logic into a method on the enclosing class. Then, the listener would just call the method:
private void someMethod() {
  // init the JButton...
  jb.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      updateClipboard();
private void updateClipboard()
  StringSelection ss = new StringSelection(this.toString());
  Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
  cb.setContents(ss, SIHwheel.logBox);
}

Similar Messages

  • I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this and how do I select which partition to start the PC?

    I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this? How do I select which partition to start the PC?

    I have Boot Camp running on a separate HD (not a partition on my Mac drive).  I would like to partition the PC HD to have a multi boot PC.  What is the proper way to do this? How do I select which partition to start the PC?

  • I have been filling up my internal memory on my laptop after years of video editing. I now want to export all this footage to an external hard drive. What is the proper way to do this.

    I have been filling up my internal memory on my laptop after years of video editing. I now want to export all this footage to an external hard drive. What is the proper way to do this.

    Are the videos being stored in iMovie or another application? Have you exported/shared the video? If the video is in iMovie what version of iMovie are you using? Give as much info as possible, and you may also want to post the question in the iLife section of this forum since more people with video skills will be reading the iLife/iMovie threads.

  • Proper way to pass a structure as FORM parameter

    Folks,
    I need to pass a table that is of type LISTZEILE to a subroutine.
    form mytest using myTable LIKE LISTZEILE.
    loop at myTable.
      write: / myTable.
    endloop.
    endform.
    Syntax checker flags this declaration as an error. Can someone please suggest me the right way to declare this?
    Just some background info. This subroutine is invoked from a custom RFC:
    FUNCTION Z_MYRFC.
    ""Local Interface:
    *"  IMPORTING
      blah
    *"  EXPORTING
      blah
    *"  TABLES
    *"      RETURNTABLE STRUCTURE  LISTZEILE
    perform MyTest using returntable.
    blah.
    endfunction.
    Thank you in advance for your help.
    Regards,
    Peter

    hi,
    try this..
    PERFORM mytest TABLES <Table name>.
    FORM mytest TABLES < table name >STRUCTURE listzeile.
      " wriite your code here
    ENDFORM.
    hope this helps
    Regards
    RItesh J

  • Proper Way To Pass Variables

    I know this is a basic question but it seems there are several different suggestions on how to do this. So using AS3 with Adobe Flash CS4, what is the correct way to pass a variable from a server side script "PHP" to my SWF?
    Thanks

    var urlLdr:URLLoader =  new URLLoader();
    var urlVar:URLVariables = new URLVariables();
    // add data to be sent
    urlVar.data1 = "whatever";
    urlReq.data=urlVar;
    urlReq.method="POST";
    // listen for data return
    urlLdr.addEventListener(Event.COMPLETE, phpCompleteF, false, 0, true);
    // call php
    urlLdr.load(new URLRequest("yourphp.php"));
    function phpCompleteF(e:Event) {
    // i'm not sure everything needs to be "typed" but, it's prudent to do so
    var vars:URLVariables=new URLVariables(URLLoader(e.currentTarget).data);
    // vars contains your return data

  • What's the proper way to update this table field?

    I've got a table with a field of TOTAL.  There's a linked table with a field of AMOUNT.  There's one main table record to multiple linked records.   I'd like to replace the TOTAL with the sum of Amount for each link.   I'm
    having a hard time setting up an update query to do that.  Any suggestions?
    ajw

    The proper way is almost certainly not to store the totals in a column in a table at all, but to compute them in an aggregating query, e.g. to return the sum of transaction amounts per customer:
    SELECT CustomerID, SUM(Amount) AS TotalAmount
    FROM Transactions
    GROUP BY CustomerID;
    Storing aggregated values is only necessary if these can legitimately be amended independently of the values from which they are computed.  This is not out of the question, but is rarely the case.
    Ken Sheridan, Stafford, England

  • Unchecked conversion warning - What is the proper way to fix this?

    I've been trying to figure this out for awhile now, and I have not seen an example that will set me on the right track. Given the following code:
            public TreeSet<String> sort = new TreeSet<String>(CI_NE_Comparator);
            public static Comparator CI_NE_Comparator = new CaseInsensitiveNeverEqualsComparator();
            public static class CaseInsensitiveNeverEqualsComparator implements Comparator
              public int compare(Object o1, Object o2)
                   String s1 = (String) o1;
                   String s2 = (String) o2;
                   int compare = s1.trim().toLowerCase().compareTo(s2.trim().toLowerCase());
                   if (compare == 0)
                        return 1; // ensure like values are never deemed equal
                   return compare;
         }I'm getting a warning declaring the class variable sort:
    Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator <? super String>
    So just what is the proper method to make the Comparator conform to generics?
    ** Btw - if anyone knows of a better way to do that comparator, I'm all ears!

    Why don't you want like values to be deemed equal?
    What would be wrong with using
    String.CASE_INSENSITIVE_ORDER?The code you see above is a stripped down example. We have the need to present data records in alphabetical order to a user, and sometimes these records have the same dscr, but that doesn't necessarily mean it's a unique record. Because of the backing query, I can't rely on the order in which the records were received.
    I can't modify the queries. Also, I can't modify the 30 or so different types of data records, all having the common field dscr, so that I can write a better implementation. But, I can write a better comparator.
    This is all legacy code that I've been working with, so I have to make sure things work as they did before.

  • What is the proper way to slice this?

    I'm newbie, have taken a DW class, but only info I have about FW is self-taught from the various tutorials
    by John Wylie, Matt Stow, etc.  on the adobe website.  Created my first webpage comp
    in FW (attached) and trying to bring it to DW, but having a lot of trouble trying to figure out how to properly
    slice the banner portion so that I don't lose the page gradient, and I am able to  use FW to generate the "up" and "down"
    state of the navigation buttons (hover will be coded in DW).
    Is there a proper, not too complex method of slicing this so that I can bring it to DW?  Or have a created an impossible
    design by putting navigation areas along the same y-co ordinate as the logo?
    This forum has been fabulous!  Thanks to all that have helped me!

    Thanks for answering, can you clarify a little further, Please?
    I was using the overall page gradient as the bckground image.
    1. Can I have 2 bg images
    on one page, the gradient and the banner area?  (The gradient starts in the upper left hand corner of the page)
    2. Do I Export as Images only? or as  CSS and images?
    3. When you say "right align and add to header, you are telling me to add it as a layer to the jpeg header file,
    then flatten/optimize the image to import into DW?
    4. For the buttons you say I can add a div inside the header to hold the navigation.  This is what
    I wanted to do, but Where to slice?  If I slice only the navigation buttons, (either all together or
    individually, how to I set up the div in DW so as not to have the buttons overlay?
    5. I don't understand what you mean by "turn off the large slice view"
    thanks

  • What's the proper way to do this cross-platform app?

    hey y'all
    I'm making a multimedia app  with LV2010 and I'm trying to make it cross platform (win and mac os x).
    The functionality I need requires the use of  system libraries, I have access to somewhat similar functions in both OS's
    (winmm.dll in windows, coreMidi.framework in mac OS X)
    Except for the  actual system calls  the VIs will be identical.
    I can make the VI work in either platform by using the  call library function node,  but  i don't want to  have two copies of everything.
    I've tried  doing  a  wrapper sub  VI that puts  the  call library function node  in a case statement  and detect the OS but this VI will not be  executable because of dependencies (won't find the  library referenced in one of the cases. depending on the OS executed)
    Is there any way  I can specify  which subVI's to load  on a project or something to  get this whole dependency issue sorted?
    Solved!
    Go to Solution.

    You want to wrap the platform-specific code in a Conditional Disable structure, with one condition for each supported platform.  The OS symbol is already defined; see the help for Creating Conditional Disable Structures, which lists the pre-defined symbols and values.

  • Best way to pass vars from html into flash?

    I've read a variety of pages that describe how to pass a variable into a flash movie (AS3, player = v9) from the html in which it is embedded.  This page describes AS3 but neglects to mention what to do with the object and embed tags in the noscript section. Furthermore, I'm not sure the javascript I see generated in my page looks like the example there (the js in my page doesn't check AC_FL_RunContenta against zero).  This page is quite long and appears to deal mostly with AS1 and AS2 approaches which I have used before and neglects entirely the newish javascript approach which appears to be used to embed flash these days (i.e., the javascript function AC_FL_RunContent).
    I was wondering if someone could spell out the proper way to pass in a variable from HTML so that flash can see it in such a way that works even if javascript is disabled, in all browsers, etc., etc.
    I've attached the HTML generated by the Flash IDE to this topic.  Any help would be much appreciated.

    You'll have to search for that concise and thorough list of steps or figure it out using the information you now have, which is sufficient to get it done.  It's not that hard--add the FlashVars in the embedding code in the three places and use the various examples you have links to to add the code in the Flash file to access and use the FlashVars.
    Your Flash will be embedded in a web page depending on the visitors settings... if they allow javascript then the javascript portion will be used.  If they don't, then either the object or embed sections will be used depending on their browser.
    As far as javascript changes go, don't sweat 'em until you have a problem... use whatever code your Flash-created html page creates to embed the file in the page.

  • Better way to do this

    When selecting into a variable, is there a better way to do this? I want to make sure I don't get an error if there are no rows found. I think it's inefficient to count the number of occurrences before selecting into the variable. Can I use %NOROWSFOUND or something similar? If so, can you please provide an example? Thanks, Margaret
    Tzi := null;
    SELECT count(BUSINESS_tz)
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    IF Tzi_cnt > 0
    THEN
    SELECT BUSINESS_tz
    INTO Tzi
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq

    the proper way to do this is to use an exception block;
    so
    begin
    Tzi := null;
    SELECT BUSINESS_tz
    INTO Tzi_cnt
    FROM BUSINESS O
    WHERE ID = Fac_id AND BUSINESS_type = 'Store' AND O.Business_seq = (SELECT Business_seq
    FROM Org_lookup
    WHERE Store_seq = 0);
    exception
    when no_data_found
    then
       null;   -- put any code to execute here or raise exception
    end;you can also use sql%rowcount to find out how many rows your sql statement affected:
    eg directly after your sql and before any rollback or commit
    declare
    v_rowcount number;
    begin
    insert into <table_name>
    select * from <other_table>;
    v_rowcount := sql%rowcount;
    end;

  • Proper way to use data throughout a class?

    I know global variables aren't a thing in c#, as that goes against the rules.
    So I have a couple of functions and subroutines (pardon my vocabulary if it isn't canon). I use a simple array to transfer data back and forth. Is this the proper way to do this? As in most efficient, readable, and expandable?
    class Program
    static void Main()
    bool[] MotorPosition = new bool[4];
    MotorPosition[0] = true;
    MotorPosition[1] = false;
    MotorPosition[2] = true;
    MotorPosition[3] = false;
    while (true)
    MotorPosition = UpdateMotorPosition(MotorPosition);
    DisplayMotorPosition(MotorPosition);
    System.Threading.Thread.Sleep(64);
    static bool[] UpdateMotorPosition(bool[] MotorPosition)
    bool[] NewMotorPosition = new bool[4];
    for (int x = 0; x < 4; x = x + 1)
    NewMotorPosition[x] = !MotorPosition[x];
    return NewMotorPosition;
    static void DisplayMotorPosition(bool[] MotorPosition)
    string CombinedDisplay = null;
    for (int x = 0; x < 4; x = x + 1)
    CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
    Console.WriteLine(CombinedDisplay);
    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Absolutely amazing! I learn something new every day. I wonder when programming will cease to amaze me.
    using your example jdweng, I was able to add a counter to your code and move the motor position to the test class; as well as add another motor by instancing the class again!
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication1
    class Program
    static int Main(string[] args)
    Test test = new Test();
    test.Initialize(); //Assigns initial value to MotorPosition
    Test test2 = new Test();
    test2.Initialize(); //Assigns initial value to MotorPosition
    while (true)
    if (test.MotorUpdateCount == 40) Console.ReadLine(); //pauses at 40 to make it easy to see output upto that point
    if (test.MotorUpdateCount > 1000) return -1; //ends program
    test.MotorPosition = test.UpdateMotorPosition(test.MotorPosition); //updates motor 1 position
    test.DisplayMotorPosition(test.MotorPosition); //displays motor 1 position
    if (test.MotorUpdateCount > 20) //at count 20, engages motor 2
    test2.MotorPosition = test2.UpdateMotorPosition(test2.MotorPosition); //updates motor 2 position
    test2.DisplayMotorPosition(test2.MotorPosition); //displays motor 2 position
    System.Threading.Thread.Sleep(128); //slows the loop down to reasonable speed
    public class Test
    public int MotorUpdateCount = 0;
    public bool[] MotorPosition = new bool[4];
    public void Initialize()
    MotorPosition[0] = true;
    MotorPosition[1] = false;
    MotorPosition[2] = true;
    MotorPosition[3] = false;
    public bool[] UpdateMotorPosition(bool[] MotorPosition)
    bool[] NewMotorPosition = new bool[4];
    for (int x = 0; x < 4; x = x + 1)
    NewMotorPosition[x] = !MotorPosition[x];
    MotorUpdateCount = MotorUpdateCount + 1;
    return NewMotorPosition;
    public void DisplayMotorPosition(bool[] MotorPosition)
    string CombinedDisplay = null;
    for (int x = 0; x < 4; x = x + 1)
    CombinedDisplay = CombinedDisplay + MotorPosition[x].ToString();
    Console.WriteLine(CombinedDisplay);
    Console.WriteLine(MotorUpdateCount.ToString());
    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

  • What is the Proper Way to place a Background Image inside a Div?

    I have been searching Google and the Adobe forums for awhile now, and while there are very valid solutions to similar problems I found that none of them fixed the problem that I am facing. I blame myself and getting lost in this sloppy coding of mine, so part of my plan was to start my style sheet over from scratch.
    My question, what is the proper way to add a background image into a div? I currently have the top div following the "header" css style, here is what I have typed into that sections:
    <style type="text/css">
    @import url("../twoColLiqLtHdr.css");
    .header {
        width: 1000px;
        height: 300px;
        background-image: url(Assets/HeaderTemplate.png);
        background-repeat: no-repeat;
        background-position: center;
    The problem here is that the background image isn't even appearing. I would greatly appreciate any help, could anyone inform me on the proper way to doing this so that I can implement images in divs in the future without turning my coding in a down right mess?
    Thank you in advance.

    I apologize, I'm unable to post a link to the page just yet. This is a snip of coding for a website still in the making for the company I work for.
    Would any of the coding below help?:
    </script>
    <style type="text/css">
    <!--
    body {
        background-color: #760101;
    a:link {
        color: #FFF;
    a:visited {
        color: #690;
    .twoColLiqLtHdr #header table tr td {
        color: #400000;
        text-align: right;
    -->
    </style>
    <link href="../twoColLiqLtHdr.css" rel="stylesheet" type="text/css" />
    </head>
    <header class="twoColLiqLtHdr">
    <scmenu class="twoColLiqLtHdr">
    <tab class="twoColLiqLtHdr">
    <body class="twoColLiqLtHdr">
    <div class="header" align="" id="header">Content Goes Here</div>
    <div class="scmenu" align="" id="scmenu">Content Goes Here</div>
    <div class="tabs" align="" id="tabs">Content Goes Here</div>
    <div class="body" align="" id="body">Content Goes Here</div>
    <div class="footer" align="" id="footer">Content Goes Here</div>
    <script type="text/javascript">var TFN='';var TFA='';var TFI='0';var TFL='0';var tf_RetServer="rt.trafficfacts.com";var tf_SiteId="11773g197b36be92cde14c11fc77dacc3a2a4f1660eb17h9";var tf_ScrServer=document.location.protocol+"//rt.trafficfacts.com/tf.php?k=11773g197b36be92c de14c11fc77dacc3a2a4f1660eb17h9;c=s;v=5";document.write(unescape('%3Cscript type="text/JavaScript" src="'+tf_ScrServer+'">%3C/script>'));</script>
    </body>
    </html>
    That above is parts I added into the source code.

  • What is the proper way to change a url link?

    I need to tell DW to change all url links (on all pages) going to an old url to a new url. What is the proper way to do this? thanks.

    Did you even read my reply properly?
    'Defining a site' in DW has everything to do leveraging most functionality with FUNDAMENTALS of DW usage.
    'Change links sitewide' is an option within DW that will change links across sites by replacing an old link with a new - for DW to do this for more than just ONE FILE in your site, DW has to know what other files make up your site. This is why 'Defining a site' is critical.
    If you do feel otherwise, please go ahead and wait for somebody else (an expert) to post his views on this. Let's see what they have to say.
    Either which way, I really think you should change your attitude while posting on this forum. That will not only help you, but all of us here.
    Good luck.

  • Proper way to get the latest published Major version of Document

    Hi,
    I have a Document Library which has "Create major and minor (draft) versions" enabled.
    Now, from my C# application I need to fetch the latest major version of a document from that library.
    What is the proper way to do this?
    As of right now, I do the following:
    return sourceFolder.Files["documentName.docx"]; // sourceFolder is a SPFolder object
    Now, I don't trust that this will always give me the latest published major version of the document. Or am I wrong? If I'm wrong, how should I do this?
    Thanks!

    Problem
    When you store critical documents in the SharePoint libraries, sometimes it becomes necessary to track all the changes and to maintain version history for them.
    Solution
    There might be a time when you would need to restore files back to an older version if any inadvertent change happens. You can also track changes for auditing purposes.
    So how does SharePoint allow creating different versions of documents? How does version history work? What are the different types of versions we can maintain for our library or list and how can we revert back to an older version?
    SharePoint allows you to enable (by default it's disabled) versioning on lists and libraries. Once enabled, SharePoint will maintain multiple versions of the document or list which gets incremented on each change iteration. There are three different versioning
    settings:
    No versioning - This is the default setting in which the current version overwrites the older version. There are no previous versions stored. This setting is not recommended especially if your document library contains critical or important
    documents.
    Create major versions - Also called simple versioning, in this setting the document versions will be numbered with whole numbers, called major versions, i.e. 1, 2, 3, 4 etc.
    Create major and minor (or draft) versions - In this setting document versions will be numbered with whole numbers (1, 2, 3, 4 etc.) as well as numbers with decimals (.1, .2, .3, .4 etc.). The whole number is called the major version
    (indicates final copy) and the numbers with a decimal are called minor versions (indicates work is still in progress). You use this setting if your document goes through several iterations/drafts/reviews (minor versions) and you want only the final copy (major
    version) to be published to a broader audience.
    Please note for a list or list items, the only option available for versioning is creating major versions, no minor versions are created.
    Once versioning is enabled SharePoint automatically and transparently creates the next version of the document whenever a user updates a document in the library. These are some of the different scenarios when SharePoint will create a new version for your
    document or list item:
    When a new document or list item is created or uploaded into SharePoint, version 1 is created if the option
    Create major versions option is enabled or version 0.1 is created when
    Create major and minor (or draft) versions is enabled (not applicable for list items) and when you publish it then next higher major version is created.
    When you upload a document with the same name as an already existing document in the library and check the
    Add as a new version to existing files check box, the existing file becomes an older version and the new uploaded document will have next higher version number.
    When any properties (metadata fields) of the document or list item is changed.
    When you Check-in a document that was previously Checked-out.
    When you open a document in the associated application, edit and save it for the first time. On subsequent changes no new versions will be created as long as you don't close the application and re-open it.
    When you restore the old version of the document.
    Please note, although the demonstration in this tip has been shown in SharePoint 2010, the versioning feature has been part of previous SharePoint versions as well.
    Reference URL with Example :
    http://www.mssharepointtips.com/tip.asp?id=1047
    Thanks
    Jaison A

Maybe you are looking for

  • Nokia C3 move messages in different folder.

    Hi Friends, I am using Nokia C3 from last 2 month and my current software is v4.65. Now I like know how to move my inbox messages in different folder. I can only archive my messages but can't move to different folder. Please give me solution. Thank u

  • My MacBook Pro's internal SuperDrive has stopped recognizing CDs/DVDs after Yosemite install

    After upgrading to Yosemite, my MacBook Pro's (early 2011) internal SuperDrive has stopped recognizing CDs/DVDs after Yosemite install. It takes them in and will eject them with the keyboard button, but they will not mount. Disk Utility shows the Sup

  • Performance Analysis for Office

    Hello Everyone, doese anybody know about the details of the processing of data sources in Analysis? if there are several data sources on one query - is the query excecute once or as many times as I have data sources? is the processing done parallel o

  • Powerbook G3 Bronze

    I have 2 powerbook g3's that I use as "backup" computers, both have been stored for some time. I took them out today and neither will start, no noise, nothing. I realize the batteries are dead, but I plugged them in and got the same nothing. Anyone g

  • Webdynpro java browse a file

    Hi All,     I need to do a scenario where I need to browse a XML file from the desktop and display the data in a table . Can anyone give me code and procedure to do this. Thanks in advance Regards