简体   繁体   English

如何将一个jTable双击鼠标事件应用于同一包中的不同jFrame

[英]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". 我在名为“ StudentSearching Form”的jFrame中有一个jTable。 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. 我想做的是,如果用户忘记了Student_Id,请转到Student Search表单并按名称搜索,然后您获得属于过滤名称的Student_Id,并将其设置到名为“ StudentRegistration form”的框架中的jTextField中。到目前为止,这些东西做得还不错。 But the problem I over came is according to my code I only can set Student_Id to the Frame called "StudentRegistration form". 但是我遇到的问题是根据我的代码,我只能将Student_Id设置为称为“ StudentRegistration表单”的框架。 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. 我有几个不同的框架,例如“学生出勤表”,“学生付款表”,“学生考试表”,应该通过搜索上述相同的“ StudentSearching表单”来获取Student_Id。

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. 在上述每个框架中都有一个链接(jButton)转到“ StudentSearching Form”,并在所需框架上获取Student_ID。 Can Only get Student_Id on SMStudentRegistrationForm Frame . 只能在SMStudentRegistrationForm Frame上获取Student_Id。 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. 如果(按下了“ StudentExams表单jButton”){我应该能够将Student_Id输入到“ StudentExams表单” jTextField}这将有助于解决我想的问题。 But Dont know how to do it , using java codes. 但是不知道如何使用Java代码来做到这一点。 Im using netbeans IDE .. 我正在使用netbeans IDE ..

Define own listener eg ChangeSelectedStudentListener with just one method 仅使用一种方法定义自己的侦听器,例如ChangeSelectedStudentListener

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). 更改后,他们应该更新其内部状态(更改文本字段值,从DB中检索一些与ID相关的数据等)。

In your search form define addChangeSelectedStudentListener() method which stores all the aded listeners in a list. 在搜索表单中,定义addChangeSelectedStudentListener()方法,该方法将所有辅助侦听器存储在列表中。 All your dependent forms should call the addChangeSelectedStudentListener(this) to let their listeners be registered. 您所有的依赖窗体都应调用addChangeSelectedStudentListener(this)以注册其侦听器。 On double click on the table iterate through the listeners list and for each item call studentIdChanged(clickedStudentId) 双击表,遍历侦听器列表,并为每个项目调用studentIdChanged(clickedStudentId)

Thus all your forms are notified about student change and could update their states. 因此,您的所有表格都会收到有关学生变更的通知,并且可以更新其状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JTable的单元格上禁用鼠标单击事件? - How to disable mouse click event on cells of JTable? java右键双击鼠标事件的行为与Mac OS X上的左键双击鼠标事件相同 - java right double click mouse event behaves same as left double click mouse event on Mac OS X 在JTable1上的鼠标单击事件上需要更新JTable2以及JEditorPane,所有这些都在同一jframe中 - Need to update JTable2 along with the JEditorPane on mouse click event on JTable1, all are in the same jframe 单击(鼠标事件)行时如何在jTable单元格中设置Image? - how set Image in jTable cell when click(Mouse Event) the row? JTable如何触发事件选择行或双击行 - JTable how to fire event selecting a row or double click on a row 如何禁用 JTable 鼠标单击? - How to disable JTable mouse click? 使用jtable的表生成运行时和鼠标单击事件 - table generation runtime and mouse click event with jtable 如何使用JTable鼠标单击事件将图像形式的JTable显示到JLabel或从数据库显示到JLabel? - How to display Image form JTable into JLabel or from database to JLabel using JTable mouse click event? 在java中双击鼠标事件 - Mouse event with double click in java 在两个不同的JFrame中打开的相同菜单仅在最后一个上起作用 - Same menu opened in two different JFrames works only on the last one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM