gpt4 book ai didi

java - 如何将鼠标点击结果发送到另一个jFrame'?

转载 作者:太空宇宙 更新时间:2023-11-04 06:50:03 25 4
gpt4 key购买 nike

我正在使用 netbeans IDE

我在“如何将 mouseClick 结果发送到另一个 jFrame”中遇到问题?

我设置TF_appID作为公众 SearchForNewAppointment jFrame

没有错误,但是当我单击表格时什么也没有出现?

        SearchForNewAppointment show = new SearchForNewAppointment();
int row = appointment_table.getSelectedRow();
String table_click = (appointment_table.getModel().getValueAt(row, 0).toString());

String sql = "select * from appointment where app_id = '"+table_click+"' ";

pst = conn.prepareStatement(sql);
rs = pst.executeQuery();

if(rs.next()){
String add1 = rs.getString("app_id");
show.TF_appID.setText(add1);
}

最佳答案

为什么不使用事件中心?

public interface EventHub {
void subscribe(String eventName, EventHandler handler);
void publish(String eventName, Object context);
}

public interface EventHandler {
void onEvent(Object context);
}

EventHub 是一个单例,它被注入(inject)到两个框架中。

public class Frame1 extends JFrame {
public Frame1(final EventHub hub) {
Button button = new Button("click-me");
button.addAddActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// for this simple event, the context is null. In the future,
// more complex events might need some contextual info
hub.publish("myCustomEvent", null);
}
});
super.add(button);
}
}

public class Frame2 extends JFrame {
public Frame2(EventHub hub) {
hub.subscribe("myCustomEvent", new EventHandler() {
public void onEvent(Object context) {
System.out.println("Button was clicked");
}
});
}
}

这意味着发布与订阅是解耦的。这也意味着单个事件可以有多个监听器。

关于java - 如何将鼠标点击结果发送到另一个jFrame'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23429832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com