如何访问匿名内部类中容器类的私有类成员? [英] How can I access private class members of container class within the anonymouse inner class?

查看:148
本文介绍了如何访问匿名内部类中容器类的私有类成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从AbstractActionClass中访问包含函数initTimer()的类的所有成员字段?
谢谢

How can I access all the member field of the class which contains the function initTimer() from within the AbstractActionClass?
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);
    }

推荐答案

尝试

ClassName.this.foo

,其中foo是类成员.有关更多信息,请参见 JLS§15.8.4合格这个.

where foo is a class member. For more information, see JLS §15.8.4 Qualified this.

这篇关于如何访问匿名内部类中容器类的私有类成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆