久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='SnhJ0'></tfoot>

    <legend id='SnhJ0'><style id='SnhJ0'><dir id='SnhJ0'><q id='SnhJ0'></q></dir></style></legend>
      <bdo id='SnhJ0'></bdo><ul id='SnhJ0'></ul>
    1. <i id='SnhJ0'><tr id='SnhJ0'><dt id='SnhJ0'><q id='SnhJ0'><span id='SnhJ0'><b id='SnhJ0'><form id='SnhJ0'><ins id='SnhJ0'></ins><ul id='SnhJ0'></ul><sub id='SnhJ0'></sub></form><legend id='SnhJ0'></legend><bdo id='SnhJ0'><pre id='SnhJ0'><center id='SnhJ0'></center></pre></bdo></b><th id='SnhJ0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SnhJ0'><tfoot id='SnhJ0'></tfoot><dl id='SnhJ0'><fieldset id='SnhJ0'></fieldset></dl></div>

      1. <small id='SnhJ0'></small><noframes id='SnhJ0'>

        訪問(wèn)java內(nèi)部類(lèi)中的變量

        access to variable within inner class in java(訪問(wèn)java內(nèi)部類(lèi)中的變量)

            <tbody id='lcFHb'></tbody>

              <small id='lcFHb'></small><noframes id='lcFHb'>

                <bdo id='lcFHb'></bdo><ul id='lcFHb'></ul>

                <legend id='lcFHb'><style id='lcFHb'><dir id='lcFHb'><q id='lcFHb'></q></dir></style></legend>
              • <i id='lcFHb'><tr id='lcFHb'><dt id='lcFHb'><q id='lcFHb'><span id='lcFHb'><b id='lcFHb'><form id='lcFHb'><ins id='lcFHb'></ins><ul id='lcFHb'></ul><sub id='lcFHb'></sub></form><legend id='lcFHb'></legend><bdo id='lcFHb'><pre id='lcFHb'><center id='lcFHb'></center></pre></bdo></b><th id='lcFHb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lcFHb'><tfoot id='lcFHb'></tfoot><dl id='lcFHb'><fieldset id='lcFHb'></fieldset></dl></div>
                <tfoot id='lcFHb'></tfoot>
                • 本文介紹了訪問(wèn)java內(nèi)部類(lèi)中的變量的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在嘗試創(chuàng)建一個(gè) JLabels 數(shù)組,單擊時(shí)它們都應(yīng)該不可見(jiàn).當(dāng)試圖通過(guò)需要訪問(wèn)用于聲明標(biāo)簽的循環(huán)的迭代變量的內(nèi)部類(lèi)來(lái)設(shè)置鼠標(biāo)偵聽(tīng)器時(shí),就會(huì)出現(xiàn)問(wèn)題.代碼不言自明:

                  I'm trying to create an array of JLabels, all of them should go invisible when clicked. The problem comes when trying to set up the mouse listener through an inner class that needs access to the iteration variable of the loop used to declare the labels. Code is self-explanatory:

                      for(int i=1; i<label.length; i++) {
                         label[i] = new JLabel("label " + i);
                         label[i].addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent me) {
                               label[i].setVisible(false);   // compilation error here
                            }
                         });
                         cpane.add(label[i]);
                      }
                  

                  我認(rèn)為我可以通過(guò)使用 this 或者 super 而不是調(diào)用 label[i] 來(lái)克服這個(gè)問(wèn)題內(nèi)部方法,但我一直無(wú)法弄清楚.

                  I thought that I could overcome this by the use of this or maybe super instead of the call of label[i] within the inner method but I haven't been able to figure it out.

                  編譯錯(cuò)誤是:局部變量i是從內(nèi)部類(lèi)中訪問(wèn)的;需要聲明為final`

                  The compilation error is: local variable i is accessed from within inner class; needs to be declared final`

                  我確定答案一定是我沒(méi)有想到的非常愚蠢的事情,或者我犯了一些小錯(cuò)誤.

                  I'm sure that the answer must be something really silly I haven't thought of or maybe I'm making some small mistake.

                  任何幫助將不勝感激

                  推薦答案

                  您的局部變量必須是 final 才能從內(nèi)部(和匿名)類(lèi)訪問(wèn).

                  Your local variable must be final to be accessed from the inner (and anonymous) class.

                  您可以將代碼更改為以下內(nèi)容:

                  You can change your code for something like this :

                  for (int i = 1; i < label.length; i++) {
                      final JLabel currentLabel =new JLabel("label " + i); 
                      currentLabel.addMouseListener(new MouseAdapter() {
                          public void mouseClicked(MouseEvent me) {
                              currentLabel.setVisible(false);   // No more compilation error here
                          }
                      });
                      label[i] = currentLabel;
                  }
                  

                  來(lái)自 JLS:

                  任何使用但未在內(nèi)部類(lèi)中聲明的局部變量、形參或異常參數(shù)都必須聲明為final.

                  Any local variable, formal parameter, or exception parameter used but not declared in an inner class must be declared final.

                  任何使用但未在內(nèi)部類(lèi)中聲明的局部變量必須明確分配 (§16) 在內(nèi)部類(lèi)的主體之前.

                  Any local variable used but not declared in an inner class must be definitely assigned (§16) before the body of the inner class.

                  <小時(shí)>

                  資源:

                  • JLS - 內(nèi)部類(lèi)和封閉實(shí)例

                  這篇關(guān)于訪問(wèn)java內(nèi)部類(lèi)中的變量的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)

                    <tfoot id='4jaq5'></tfoot>

                      <tbody id='4jaq5'></tbody>
                  • <legend id='4jaq5'><style id='4jaq5'><dir id='4jaq5'><q id='4jaq5'></q></dir></style></legend>

                          <small id='4jaq5'></small><noframes id='4jaq5'>

                          • <bdo id='4jaq5'></bdo><ul id='4jaq5'></ul>
                            <i id='4jaq5'><tr id='4jaq5'><dt id='4jaq5'><q id='4jaq5'><span id='4jaq5'><b id='4jaq5'><form id='4jaq5'><ins id='4jaq5'></ins><ul id='4jaq5'></ul><sub id='4jaq5'></sub></form><legend id='4jaq5'></legend><bdo id='4jaq5'><pre id='4jaq5'><center id='4jaq5'></center></pre></bdo></b><th id='4jaq5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4jaq5'><tfoot id='4jaq5'></tfoot><dl id='4jaq5'><fieldset id='4jaq5'></fieldset></dl></div>
                            主站蜘蛛池模板: 天堂在线网 | 久久久精品一区二区 | 精品久久久久久亚洲综合网 | 青春草91| 特黄特黄a级毛片免费专区 av网站免费在线观看 | 操操日| 精品欧美一区二区三区久久久 | 在线观看中文视频 | 久久福利电影 | 亚洲一区二区三区四区五区午夜 | 日韩av.com| 成人av一区 | 99reav| 国精日本亚洲欧州国产中文久久 | 免费三级av | 国产精品久久久久久影视 | 日韩国产精品一区二区三区 | 在线视频a| 久久精品久久久久久 | 精品久久久久久亚洲综合网 | 欧美一级黄色免费看 | 日韩二三区 | 久久九 | 日韩av电影在线观看 | 亚洲视频一区在线 | 另类视频区 | 欧美一区二区激情三区 | 亚洲欧美中文字幕在线观看 | 亚洲国产精品一区二区三区 | 亚洲国产精品99久久久久久久久 | 亚洲国产激情 | 最新伦理片 | 黑人性hd| 精品伦精品一区二区三区视频 | 日韩欧美三级在线 | 国产精品国产三级国产aⅴ无密码 | 久久久成人网 | 鲁大师一区影视 | 拍拍无遮挡人做人爱视频免费观看 | 中文字幕91 | 91中文字幕在线观看 |