2

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

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);
    }
4

2 回答 2

4

尝试,

ClassName.this.foo

foo班级成员在哪里。有关更多信息,请参阅JLS §15.8.4 限定此

于 2011-09-27T19:54:19.757 回答
2

假设你的外部类被调用OuterClass,那么OuterClass.this.whatever

于 2011-09-27T19:53:21.827 回答