🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: (Continued...)How do I call the method in another(between different) JInternalFrame??

#9998
From: Greg Hamer
Date: Wed, 08 Dec 1999 00:00
167 lines
5419 bytes
In the first problem, you need a reference to the the JinternalFrame
object that you want to call isOk on. In your first case, there was a
reference in the jbInit method, but it was local to that method and
unavailable anywhere else in the program. You could have the internal
frame pass itself in to parentprint as a parameter, depending on what
you are trying to do. Or maybe you want to loop through all the child
internal frames. From mainFrame,
((JDesktopPane)getContentPane()).getAllFrames() would give you an array
of all the InternalFrames. Your second problem is that the
JInternalFrame.getParent() does not quite return the JFrame, it returns
the JDesktopPane of the JFrame. The DesktopPane exists as the
contentPane of the RootPane which is the only child of the JFrame, so
getParent().getParent().getParent() should be able to be cast to
mainFrame.

ERic wrote:

> Sorry that I can't write my problem clear enough. My problem is:How
> can I call the method between different JInternalFrame?? (Can I do
> this?)
> even they are within the same package???  ( I can do this in
> JDialog...)
>
> As I know, if the classess are in the same package, I can "reuse" the
> method which defined at any class... but I can't do this......Why???
> :  (
>
> Thanks for your help!!!!
>
> Following are three little java for showing my problem....
>
>
>
>
> <<Application1.java>>
> package Test5;
>
> import javax.swing.UIManager;
>
> public class Application1 {
>   boolean packFrame = false;
>
>   public Application1() {
>     mainFrame frame = new mainFrame();
>     if (packFrame)
>       frame.pack();
>     else
>       frame.validate();
>     frame.setVisible(true);
>   }
>
>
>   public static void main(String[] args) {
>     try  {
>       UIManager.getLookAndFeelDefaults();
>     }
>     catch(Exception e) {
>     }
>     new Application1();
>   }
> }
>
>
> <<mainFrame.java>>
> package Test5;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class mainFrame extends JFrame {
>   JDesktopPane desk = new JDesktopPane();
>   BorderLayout borderLayout1 = new BorderLayout();
>
>   public mainFrame() {
>     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
>     try  {
>       jbInit();
>     }
>     catch(Exception e) {
>       e.printStackTrace();
>     }
>   }
>
>   private void jbInit() throws Exception  {
>     this.setContentPane(desk);
>     this.getContentPane().setLayout(borderLayout1);
>     this.setSize(new Dimension(400, 300));
>     JInternalFrame jif = new InternalFrame();
>     desk.add(jif);
>     desk.revalidate();
>     parentprint();
>   }
>
>   public void childprint(){
>     System.out.println("We call this method from an
> InternalFrame...");
>   }
>
>   public void parentprint(){
>     if (jif.isok())                                         //Here the
> first problem is... I want call a method defined at other
> JInternalFrame,How can I do this?
>                                                                //if
> ((InternalFrame).isok())  <---I can't declare like this, because the
> isok() can't be declare as a static method....
>       System.out.println("Result is True, after we call method defined
> in child, we print this");
>   }
> }
>
>
> <<InternalFrame.java>>
> package  Test5;
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class InternalFrame extends JInternalFrame {
>   boolean ok = false;
>   BorderLayout borderLayout1 = new BorderLayout();
>   JButton jButton1 = new JButton();
>
>   public InternalFrame() {
>     super();
>     try {
>       jbInit();
>     }
>     catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
>
>   public void jbInit() throws Exception {
>     jButton1.setText("OK");
>     jButton1.addActionListener(new java.awt.event.ActionListener() {
>
>       public void actionPerformed(ActionEvent e) {
>         jButton1_actionPerformed(e);
>       }
>     });
>     this.setClosable(true);
>     this.setIconifiable(true);
>     this.setMaximizable(true);
>     this.setResizable(true);
>     this.getContentPane().setLayout(borderLayout1);
>     this.getContentPane().add(jButton1, BorderLayout.CENTER);
>   }
>
>   public boolean isok(){
>     return ok;
>   }
>
>   void jButton1_actionPerformed(ActionEvent e) {
>     ok = true;
>     ((mainFrame)getParent()).childprint();                //Here the
> second problem is; this can pass the debug, but error at run time;
>     this.dispose();
> //also I don't know the method getParent(); I sow this at some sample
> code;
>
> }
> //The problem is, how do I call a method defined at the parent like
> this???
>
> }
Technical Details
Message-ID: <384F0E3B.1C6CAC1B@borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <384B8796.F03CE374@usa.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,8d30d9dc90139ef5,start
X-Google-Attributes: gid111d45,public
From: Greg Hamer <ghamer@borland.com>
Subject: Re: (Continued...)How do I call the method in another(between different)  JInternalFrame??
Date: 1999/12/08
Message-ID: <384F0E3B.1C6CAC1B@borland.com>
X-Deja-AN: 558387312
Content-Transfer-Encoding: 7bit
References: <384B8796.F03CE374@usa.net>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing