【问题标题】:Handling button event in main class处理主类中的按钮事件
【发布时间】:2016-07-05 03:29:22
【问题描述】:

我是 Java 和编程新手。我想通过在表中选择一行并将int 发送到创建它的主类,或者处理在主类中执行的按钮操作,在JDialog 类中生成一个int。主类在这里创建子类:

private void launchtable() {
    DlgBeds dcl = new DlgBeds();
    dcl.setLocationRelativeTo(this);
    dcl.setVisible(true);

    // I want in this place to put something like this:
    txtCode.setText(subclassgeneratedint );
}

但首先我需要从子类中获取该 int。我尝试在那里创建一个可以在 main 中使用的方法来返回 int,但它设置文本时选择了第一行(默认选择),它不能返回更多的行选择来不断变化txtCode;就像死在那里的方法一样。 主类中的按钮也可以有一个action performed,但我猜该参数需要是子类中的一个。

protected void actionPerformed[button in the subclass](ActionEvent e) {
    //actions
}

我真的迷路了,我知道我需要学习更多才能解决这种情况,但我需要尽快找到答案。

【问题讨论】:

标签: java swing jtable jdialog


【解决方案1】:

ListSelectionListener 添加到您的表中。您可以获取所选行,如 here 所示,并使用 PropertyChangeListener 将其传递到主窗口,如 herehere 所示。

【讨论】:

    猜你喜欢
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-12
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多