1

現在、アプリケーションを作成していますが、JFrameとがありJDialogます。と呼ばJFrameれるJList

JList lstMainVenuesEvents = new JList();

そして、私は以下を使用してlstMainVenuesEventsの値を取得しようとしています。

lstMainVenuesEvents.getSelectedIndex();

私は自分の値を完全にうまく得ることができますJFrameが、どうすればそれを自分に渡すことができますJDialogか?クラスファイルの1つにsetterメソッドを作成し、その値をJDialogファイルから取得することを考えましたが、確かに簡単な方法はありますか?PHPのPOSTリクエストJFrameのようにからデータを渡すある種のメソッドを持つことは可能ですか?JDialog

重要なことを見逃してしまった場合は、お詫び申し上げます。

更新:これが私のJListとJDialogショーのコードです。

JList lstMainVenuesEvents = new JList();
    lstMainVenuesEvents
            .addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    // stop from firing twice
                    if (e.getValueIsAdjusting()) {
                        EventModify evtWindow = new EventModify();
                        evtWindow.setVisible(true);
                    }
                }
            });
4

1 に答える 1

2

私はそれが「正しい」とは確信できませんが、制御の反転のようなアプローチは通常、渡される値を減らします。

lstMainVenuesEvents.getSelectedIndex()の特定のアクション/イベントで値が使用されていると仮定すると、からJDialogを設定できます。ActionListenerJFrame

// some where in the JFrame
jDialog.setButtonPressed(new ActionListener() {
    public void actionPerformed(ActionEvent evt)
    {
        // lstMainVenuesEvents.getSelectedIndex() is accessible in this block
        // put code logic here where
    }
});
于 2013-01-29T02:36:23.520 に答える