简体   繁体   中英

how to apply one jTable double click mouse event to different jFrames in same package

I have a jTable in a jFrame named "StudentSearching Form". What i wanted to do is if the user not remember the Student_Id , go to Student Searching form and search by name , then u get the Student_Id which belongs to filtered name and set it into a jTextField in the Frame called "StudentRegistration form" .I have done those stuff pretty good so far. But the problem I over came is according to my code I only can set Student_Id to the Frame called "StudentRegistration form". I have few different Frames like "StudentAttendance Form","Student Payment Form","StudentExams Form" that should get Student_Id by searching same "StudentSearching Form" above mentioned.

So please help me on this..... Thank you.

Here is my code :

private void jTable1MousePressed(java.awt.event.MouseEvent evt) {                                     
int rw =jTable1.getSelectedRow();
String k = jTable1.getValueAt(rw, 0).toString();

if(evt.getClickCount()==2){

SMStudentRegistrationForm sms= new SMStudentRegistrationForm();


this.dispose();
sms.setVisible(true);
sms.jTextField1.setText(k);


}


}

there is a link(jButton) to go to "StudentSearching Form" in every above mentioned Frame and get Student_ID on required Frame. Can Only get Student_Id on SMStudentRegistrationForm Frame . If(StudentExams Form jButton pressed){ I Should be able to enter the Student_Id to "StudentExams Form" jTextField } This will help to solve the problem I suppose. But Dont know how to do it , using java codes. Im using netbeans IDE ..

Define own listener eg ChangeSelectedStudentListener with just one method

void studentIdChanged(int newId);

Let all your dependent forms implement the listener. On change they should update their internal state (change text field values, retrieve some id dependent data from DB etc).

In your search form define addChangeSelectedStudentListener() method which stores all the aded listeners in a list. All your dependent forms should call the addChangeSelectedStudentListener(this) to let their listeners be registered. On double click on the table iterate through the listeners list and for each item call studentIdChanged(clickedStudentId)

Thus all your forms are notified about student change and could update their states.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM