Java 如何将鼠标单击结果发送到另一个jFrame';?

Java 如何将鼠标单击结果发送到另一个jFrame';?,java,swing,netbeans,jframe,Java,Swing,Netbeans,Jframe,我正在使用netbeans IDE 我在“如何将mouseClick结果发送到另一个jFrame”中遇到了一个问题 我将TF_appID设置为在SearchForNewAppointment jFrame 没有错误,但是当我点击表格时,什么都没有出现 SearchForNewAppointment show = new SearchForNewAppointment(); int row = appointment_table.getSelectedRow();

我正在使用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);
        }

这取决于第二个Jframe(即TF_appID)中的组件是否在设置值时初始化。在填充动态值之前,请确保初始化第二个JFrame及其所需的组件

为什么不使用事件中心

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

public interface EventHandler {
    void onEvent(Object context);
}
EventHub是一个注入两个帧的单例

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");
            }
        });
    }
}
这意味着发布与订阅是解耦的。这也意味着一个事件可以有多个侦听器