inner class question

i am using jdk1.2.2, codes like:
public class TMenu extends JFrame{
  public JMenu aboutMenu = new JMenu("About");
    ...
//following is inner class
class ItemHandler implements ActionListener{
 
  public void actionPerformed(ActionEvent e)
  {
   //aboutMenu
//    if (aboutMenu.isSelect()) TDialog.displayAboutDialog();
    JMenu menu = new JMenu();
    menu = aboutMenu;
...
It shows abotMenu is a undefined variable at inner class when compiled.
iryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

iryAuthor Commented:
Edited text of question.
0
vivexpCommented:
Hi,

Visit the site for detailed info
http://www.javaworld.com/javaworld/javatips/jw-javatip75.html
Try out...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JodCommented:
There is no isSelect() method in JMenu but there is an isSelected(). With this in mind, this compiles just fine...

import javax.swing.*;
import java.awt.event.*;

public class test1 extends JFrame{
  public JMenu aboutMenu = new JMenu("About");

//  ...

  //following is inner class
  class ItemHandler implements ActionListener{
    public void actionPerformed(ActionEvent e)
    {
      //aboutMenu
      if (aboutMenu.isSelected()) System.out.println("Done...");
    }
  }
}


If you want to be doubly safe then use...


import javax.swing.*;
import java.awt.event.*;

public class test1 extends JFrame{
  public JMenu aboutMenu = new JMenu("About");

//  ...

  //following is inner class
  class ItemHandler implements ActionListener{
    public void actionPerformed(ActionEvent e)
    {
      //aboutMenu
      if (test1.this.aboutMenu.isSelected()) System.out.println("Done...");
    }
  }
}


When you use test1.this you get the outer class object so test1.this.aboutMenu always gets you the reference to the aboutMenu object in the outer class.

Do you need to know more about inner classes?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.