tags:

views:

41

answers:

2

Hi all,

I have a class that extends JFrame to make orders. in the middle I have a button that opens a new window that is used to find an article.

What I need is: When I click btnNewArticle, after searching new article, and confirm in new window, I will get as return article code.

Click btnNewArticle --> (open new window to find an article) --> confirm selection -->as return I get Article Code.

Is it possible?

Thanks

+1  A: 
aioobe
to be honest i am lost.in OrdersFrame i have:protected void newArticle_actionPerformed(ActionEvent e) { new NewArticle(); } and in NewArticle: protected void saveArticle_actionPerformed(ActionEvent e) { //code to do this.dispose(); } i realy dont know what to do to get ArticleCode on return.and from Java Dialogs example i dont understand muchHELP
gerpaick
Give the OrdersFrame a reference to the "parent" dialog, that is, the GUI that spawns the OrdersFrame. In `code to do this.dispose()` you do something like `parent.setChosenArticleCode(codeFromDialog)`.
aioobe
can you check whats wrong with my code? i sent http://CodeTidy.com/217/ (what is Orders..) and on line 260 there is a NuovaRiga method. http://CodeTidy.com/218/ (NuovaRiga) and on line 199 there is Save() action....
gerpaick
A: 

For me this principle has worked:

public class ArticleSearchDialog extends JDialog {

    public static ArticleId execute(Frame parent) {
        ArticleSearchDialog dialog = new ArticleSearchDialog(parent, true);
        dialog.setVisible(true);
        return dialog.getSelectedArticle();
    }

    private ArticleId getSelectedArticle() {
        return selectedArticle;
    }

    private void jbCancelActionPerformed(ActionEvent evt) {
        selectedArticle = null;
        setVisible(false);
        dispose();
    }

    private void jbOkActionPerformed(ActionEvent evt) {
        selectedArticle = ...; //TODO 
        setVisible(false);
        dispose();
    }        

    // All the rest of the dialog code.
}

Then the call gets really easy:

ArticleId articleId = ArticleSearchDialog.execute(this);
if (articleId != null) {
    //TODO
}
DR