Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

How redirect event between two public class?

Thread view: 
Jacek Janiszewski - 26 Jan 2004 08:51 GMT
Hi,

How can I send information about event from one object of one class to
another (belongs to another class)?
Main class (1) is extension of JFrame and describes my main application
window. Second class (2) inherited from JPanel creates JTree and places it
in main frame (1). I mean , how to get event about, for example, chosing any
element of JTree and send it to class of main window (1), which makes
further things.
Object of class 2 is create in constructor of main class (1).
Both class are public (and in others files) !

Maybe some examples?

--Jack
jj3_NOSPAM_@gazeta.pl
ak - 26 Jan 2004 09:03 GMT
> How can I send information about event from one object of one class to
> another (belongs to another class)?
add event listener.

____________

http://reader.imagero.com the best java image reader.
Jacek Janiszewski - 26 Jan 2004 10:12 GMT
> > How can I send information about event from one object of one class to
> > another (belongs to another class)?
[quoted text clipped - 3 lines]
>
> http://reader.imagero.com the best java image reader.

Some example?

It looks like....

(1)Main class

//first file
public class MainFrame extends JFrame
{
   ...
 public MainFrame()
   {
       ...
       TreePanel treePanel = new TreePanel();
       ...
   }
   ...
   public readEvent()
   {
           //here I want listen for an event
   }
   ...
}

// (2) second file
public class TreePanel extends JPanel
{
   ...
   prublic sendEvent()
   {
       //here I want to send event to first class
       ....
   }
   ...
}
ak - 26 Jan 2004 11:23 GMT
----- Original Message -----
From: "Jacek Janiszewski" <jj3@gazeta.pl>
Newsgroups: comp.lang.java.gui
Sent: Monday, January 26, 2004 11:12 AM
Subject: Re: How redirect event between two public class?

> > > How can I send information about event from one object of one class to
> > > another (belongs to another class)?
[quoted text clipped - 5 lines]
>
> Some example?

//simple example with ActionListener, you can use other listeners (or write
your own)
public class MainFrame extends JFrame implements ActionListener {
   //implements ActionListener
   public void actionPerformed(ActionEvent e) {
       //do something with event
   }

   public static void main(String [] args) {
       MainFrame mf = new MainFrame();
       TreePanel tp = new TreePanel();
       tp.setActionListener(mf);

   }
}

//only one ActionListener for simplicity - you can use Vector or
EventListenerList
public class TreePanel extends JPanel {
ActionListener listener;

   public void setActionListener(ActionListener listener) {
       this listener = listener;
   }

   public void sendEvent(ActionEvent ae) {
       listener.actionPerformed(ae);
   }
}

____________

http://reader.imagero.com the best java image reader.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.