简体   繁体   English

如何访问匿名内部类中容器类的私有类成员?

[英]How can I access private class members of container class within the anonymouse inner class?

How can I access all the member field of the class which contains the function initTimer() from within the AbstractActionClass? 如何从AbstractActionClass中访问包含函数initTimer()的类的所有成员字段?
Thanks 谢谢

private void initTimer()
    {
       Action updateClockAction = new AbstractAction() {
                public void actionPerformed(ActionEvent e){
                    JLabel secLabel = m_GameApplet.GetJpanelStartNetGame().GetJlabelSeconds();
                    secLabel.setFont(new java.awt.Font("Lucida Handwriting", 1, 36));
                    secLabel.setForeground(Color.red);
                    secLabel.setText(Integer.toString(m_TimerSeconds));
                    if(m_TimerSeconds >0)
                    {
                        m_TimerSeconds--;
                    }
                    else if (m_TimerSeconds == 0)
                    {
                        m_Timer.stop();
                        m_GameApplet.GetJpanelStartNetGame().GetJlabelSeconds().setText("0");
                        m_GameApplet.GetJpanelStartNetGame().GetJbuttonFinish().setVisible(false);
                        //Checking whether time ended for both players and no solution was recieved
                        if(!m_WasGameDecisived)
                        {
                            System.out.println("Tie - No one had a solution in the given time");
                            //askUserForAnotherRoundLeaveTableOrExitProgram();//////////////////////////////////////////////To implement
                        }
                    }
                }
            };
            m_Timer = new Timer(1000, updateClockAction);
    }

Try, 尝试,

ClassName.this.foo

where foo is a class member. 其中foo是类成员。 For more information, see JLS §15.8.4 Qualified this . 有关更多信息,请参见JLS§15.8.4对此进行了限定

假设您的外部类称为OuterClass ,然后称为OuterClass.this.whatever

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么外部 Java 类可以访问内部类私有成员? - Why can outer Java classes access inner class private members? 如何在Java中访问私有类成员? - How can I access private class members in Java? 外部类可以访问内部类的成员吗? - Can an outer class access the members of inner class? 如何从子类中访问父类中的内部类? - How can I access a inner class in a Parent class from within a Child class? 在更高版本的 Java 中,内部类如何访问封闭类的私有成员? - How do inner class access enclosing class' private members in higher versions of Java? 如何从Java中的静态内部类访问外部类的私有成员 - How to access private members of outer class from static inner class in Java 为什么我可以访问封闭类引用的私有成员 - Why can I access the private members of an enclosing class reference 可以在静态方法中实例化的匿名内部类是否可以访问包含类的实例成员? - Can Anonymous inner class instantiated within a static method has access to instance members of containing class? 内部类甚至可以访问外部类的私有成员。这是否侵犯了隐私? - Inner classes can access even the private members of the outer class.. doesn't it violates the privacy? 在Java嵌套类中,封闭类可以访问内部类的私有成员吗? - In Java nested classes, can the enclosing class access private members of inner classes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM