title: I cannot access object in java
body: <p>i am new at Java and have some problems about swing. I want an application which has some internal frame when user calls by menubar.</p>
  
  <pre><code>import java.awt.Color;
  
  import javax.swing.JDesktopPane;
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
  
  public class uygulama {
  
  public static void main(String[] args) {
  
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
  
              JFrame frame = new JFrame("uygulama adı");  
  
              JDesktopPane desktop = new JDesktopPane();
              frame.add(desktop);
  
              menubar  mb = new menubar(); //Jmenubar inst.
              frame.setJMenuBar(mb);
  
              frame.setBounds(300,100,500,300);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
              System.out.println(desktop.getTopLevelAncestor());
  
          }
      }); 
    }
  
  }
  </code></pre>
  
  <p>In the code above (the listener code block);  i cant access 'desktop' object. If i could, i would use 'desktop.add()'  to add an JInternalFrame.</p>
  
  <pre><code>import java.awt.Desktop;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JInternalFrame;
  import javax.swing.JMenu;
  import javax.swing.JMenuBar;
  import javax.swing.JMenuItem;
  import javax.swing.JOptionPane;
  import javax.swing.JPopupMenu;
  
  
  public class menubar extends JMenuBar {
  
      JMenu Dosya;
      JMenuItem DosyaItem;
  
      menubar () {
          Dosya = new JMenu("Dosya");
  
  
          DosyaItem = new JMenuItem("Dosya1");
          DosyaItem.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  //desktop. here is the problem
              System.out.println();
              }
          });
          Dosya.add(DosyaItem);
          add(Dosya);
  
  
      }
  
  }
  </code></pre>