1
public class Job_GUI extends javax.swing.JFrame {

    private JobDTO jdto;

    public Job_GUI() {
        initComponents();
    }

      private void menuEditJobActionPerformed(java.awt.event.ActionEvent evt) {
            editJob.setVisible(true);
            //here I want to obtain the updated dto. 
        }

  } 


public class JobDTO extends BaseDTO {
//setters and getters

}


class ListDataUI { 

    private void initListeners() {
        summaryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        summaryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    final int selectedRowIndex = summaryTable.getSelectedRow();
                    if (selectedRowIndex != -1) {
                        BaseDTO dto = data.get(summaryTable.convertRowIndexToModel(selectedRowIndex));
                    } else {
                    }
                }
            }
        });

    }

}

我不知道如何获取BaseDTO对象dtomenuEditJobActionPerformed方法,所以我可以显示对象的所有值。我如何从valueChanged事件发生时传递它?I'm simply using a table, when a row is selected, the dto state changes, need to pass this new state to the class Job_GUI actionperformed method

4

1 回答 1

1

声明dto后立即class GUI {声明。

这样它将具有全局范围,因此您的所有功能都可以看到它。

类 GUI {
   BaseDTO dto;

  私人无效菜单EditJobActionPerformed(java.awt.event.ActionEvent evt){
        editJob.setVisible(true);
        //现在你可以访问“dto”
    }

  }

类 ListDataUI {

    私人无效initListeners(){
        summaryTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        summaryTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @覆盖
            公共无效值更改(ListSelectionEvent e){
                if (!e.getValueIsAdjusting()) {
                    final int selectedRowIndex = summaryTable.getSelectedRow();
                    if (selectedRowIndex != -1) {
                        /*BaseDTO */ dto = data.get(summaryTable.convertRowIndexToModel(selectedRowIndex));
                        //不声明一个新对象
                    } 别的 {
                    }
                }
            }
        });

    }

}
于 2013-02-05T23:14:36.690 回答