Hello from Ireland,

In NetBeans I created a class that extends JFrame called “SearchCustomerPage”. The class has a JButton called “Search” that has an ActionListener associated with it (so when I click “Search” a method is called).

I have another JFrame page (“NewBookingPage”) that creates bookings. To create a booking the user enters various details including a customer number. To enter a customer number the user must first search for a customer, the "SearchCustomerPage" comes in to play.
To bring up the "SearchCustomerPage" the user clicks the "addCustomer" button in the "NewBookingPage". This creates an instance of "SearchCustomerPage". So in the "NewBookingPage" code I create a "SearchCustomerPage" object.

Now my question:
Is it possible to get a signal (in "NewBookingPage") when the "Search" button is clicked ? (I want to execute some code in the "NewBookingPage" class when user clicks the "Search" button in the "SearchCustomerPage" object).

So class-a (NewBookingPage) gets a signal when class-b (SearchCustomerPage) button has been clicked.

I nearly sure I need to add a listener but just can’t figure it out. Maybe something like following:
SearchCustomerPage scp = new SearchCustomerPage();

scp.addComponentListener(); //to listen to the search button


Any help would be much appreciated.

Recommended Answers

All 2 Replies

as per my knowledge its not feasible...

class 'a' getting only after all the things executed in class 'b'..

while running class 'b' class 'a' can't notify anything...

Easy way is to have a public method in the booking form class, pass the current instance of that class to the constructor of the search form class, then simply call the method on the instance when required.
This creates a hard-coded dependency between the search and booking classes which may be a problem if you want to use the search in other contexts. In that case you need to implement a Listener structure for the search: addSearchListener(SearchListener someOtherForm) where SearchListener is a public interface that defines a callback method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.