🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12601

Re: Menubar and JInternalFrame

#12601
From: Nadia Akrour
Date: Fri, 11 Dec 1998 00:00
172 lines
5884 bytes
We may be missing something obvious because it didn't work for us.....
We tried it with the swing1.1beta2 MetalWorks example.
Could you please take a look at the code and say me if you see something wrong. I
have no more idea on what to do....
Thanks in advance.

------------------------------------------------------------------------
// class object with the frame in argument of the constructor
public class OD {

    JSMenuBar m_MenuBar;
    JMenu m_menuEd;
    JMenuItem m_menuEdRaz;
    MetalworksDocumentFrame2 m_jif = null;

    public OD(MetalworksDocumentFrame2 jif) {
      m_jif = jif;
    // create the menubar
      m_MenuBar = new JMenuBar();
      m_menuEd = addMenu("Edition");
      m_menuEdRaz = addMenuItem(m_menuEd,"Raz");
      m_MenuBar.add(m_menuEd);
      m_jif.setJMenuBar(m_MenuBar);
    }

  // ------------
  public void finalize() throws Throwable {
    System.out.println("OD " + m_jif.getTitle() + " being GCed !");
    m_MenuBar = null;
    m_jif = null;
    super.finalize();
  }

  //------------------------
  private JMenu addMenu(String text) {
   JMenu me = new JMenu(text);
   me.setHorizontalTextPosition(JButton.RIGHT);
    return me;
  }

  //-------------------------------
  private JMenuItem addMenuItem(JMenu menu, String text) {
   JMenuItem mi;
    mi = menu.add(text);
   mi.setHorizontalTextPosition(JButton.RIGHT);
   mi.setBorderPainted(false);
    return mi;
  }
}

---------------------------------------------------------------------------------------

// class wich extends JInternalFrame
public class MetalworksDocumentFrame2 extends JInternalFrame implements
InternalFrameListener{

    JPanel top;
    static int openFrameCount = 0;
    static final int offset = 30;
    MetalworksFrame m_f;

    public MetalworksDocumentFrame2(MetalworksFrame f) {
     super("", true, true, true, true);
      m_f = f;
     openFrameCount++;
      setTitle("MetalworksDocumentFrame2 " + openFrameCount);

     top = new JPanel();
     top.setBorder(new EmptyBorder(30, 30, 30, 30));
     top.setLayout(new BorderLayout());
     getContentPane().add(top);
     pack();
     setLocation( offset * (openFrameCount % 20), offset * (openFrameCount% 20));
     addInternalFrameListener(this);
    }

  // ------------
  public void dispose() {
    System.out.println(getTitle() + " disposed !");
    m_f = null;
    super.dispose();
  }

  //----------------------------------------------
  /** InternalFrameListener interface */
  public void internalFrameOpened(InternalFrameEvent e) { }
  /** InternalFrameListener interface */
  public void internalFrameClosing(InternalFrameEvent e) { }
  /** InternalFrameListener interface */
  public void internalFrameClosed(InternalFrameEvent e) {  dispose(); }
  /** InternalFrameListener interface */
  public void internalFrameIconified(InternalFrameEvent e) { }
  /** InternalFrameListener interface */
  public void internalFrameDeiconified(InternalFrameEvent e) { }
  /** InternalFrameListener interface */
  public void internalFrameActivated(InternalFrameEvent e) { }
  /** InternalFrameListener interface */
  public void internalFrameDeactivated(InternalFrameEvent e) { }

  // ------------
  public void finalize() throws Throwable {
    System.out.println(getTitle() + " being GCed !");
    super.finalize();
  }
}

------------------------------------------------------------------------------------------------

// main frame
public class MetalworksFrame extends JFrame {
...
...
    // ------------------------------------
    // create 10 internal frames
    // ------------------------------------
    public void newDocument() {
        // add 10 internal frames
      for (int i = 0; i< 10; i++ ) {
        // create JInternalFrame
        MetalworksDocumentFrame2 doc = new MetalworksDocumentFrame2(this);
        // create object
        OD od = new OD(doc);
        // add JInternalFrame to the desktop pane
        desktop.add(doc, DOCLAYER);
        try {
            doc.setSelected(true);
        } catch (java.beans.PropertyVetoException e2) {}
      }
        // call the GC
      m_theApp.fullRtGC();
    }

    // -----------------------------------
    // close the internal frames
    // ------------------------------------
    public void openDocument() {
      try {
        // set the internal frames to closed
       JInternalFrame[] allframe = desktop.getAllFrames();
        for (int i = 0; i< allframe.length; i++ ) {
          JInternalFrame doc = allframe[i];
          doc.setClosed(true);
        }
       }
      catch (java.beans.PropertyVetoException e) { }
      m_theApp.fullRtGC();
    }
....
}


Steve Waters wrote:

> 1.  JinternalFrame
> 2. a refererence to the frame
> 3 setJmenu bar.
>
> it goes like this
> code............
>    create internal frame
>    create object(pass frame)
> more code
>
> * note when this class (above) is destroyed or made null you will no longer have
> a pointer to this object below, so make sure you destroy it too.
>
> public create object(jinternalfrrame value)
> blah
> blah
> set jmenu( value)
> blah
>
Technical Details
Message-ID: <36711773.C70A888F@spring.fr>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net> <366FB425.C5E8333E@spring.fr> <36703797.9F0BB1B4@bellsouth.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,7a1fee86da1b3c36
X-Google-Attributes: gid111d45,public
From: Nadia Akrour <akrour@spring.fr>
Subject: Re: Menubar and JInternalFrame
Date: 1998/12/11
Message-ID: <36711773.C70A888F@spring.fr>
X-Deja-AN: 421170575
Content-Transfer-Encoding: 7bit
References: <366E5D45.9342BA14@spring.fr> <366F6314.73E5CDEE@bellsouth.net> <366FB425.C5E8333E@spring.fr> <36703797.9F0BB1B4@bellsouth.net>
X-Accept-Language: fr-FR,en
Content-Type: text/plain; charset=us-ascii
Organization: SPRING TECHNOLOGIES
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing