Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

handling events in swing

Posted on 2004-04-26
6
Medium Priority
?
366 Views
Last Modified: 2013-11-23
what is the best way to handle events across several frames in an application. eg. how do i pass back values from textfields, passwordfields or textarea in a jdialog back to the parent frame when user clicks a submit button. are there any tutorials for this kind of event handling across classes without using inner classes. are there any design patterns for this.
0
Comment
Question by:vijaywm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 225 total points
ID: 10922237
Well, it's not because you dispose/close the dialog that it isn't there anymore.
So, you can still call all it's getter functions.

MyDialog myDialog = new MyDialog();
...
// 1) Show it

// 2) Here it is closed by pressing <Submit> or whatever
// but that doesn't prevent you to:

String field1 = myDialog.getField1();
String field2 = myDialog.getField2();
...
0
 

Author Comment

by:vijaywm
ID: 10922304
great. thanks.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10922386
Is your Q completely answered?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Accepted Solution

by:
gnoon earned 150 total points
ID: 10925080
Create your own event and listener class to handle event it's easy concept and implementation.

There're 3 classes and 1 interface in the session.

1 - Event generator class (generate some events)
2 - Event class (contains data of an event)
3 - Listener interface (contains event methods and will executed when some events occur)
4 - Event listening class (contains a reference of event generator)

For example, you have

  SigninListener interface : (Listener interface)
        interface SigninListener {
            public void whenUserClickSignin(SigninEvent e);
        }

  SigninEvent class : (Event class)
        public class SigninEvent {
            String username;
            String password;
            public SigninEvent(String username,String password) {
                this.username = username;
                this.password = password;
            }
            /* and other get/set method */
        }

  SigninDialog class : (Event generator class)
        public class SigninDialog extends JDialog implements ActionListener {
            JTextField jt_User,jt_Passwd;
            JButton jb_Signin;
            SigninListener signinlistener;

            public SigninDialog() {
                /* build ui here */
                signinlistener = new SigninListener() {
                    public void whenUserClickSignin(SigninEvent e) {/* default implementation */}
                };
                jb_Signin.addActionListener(this);
            }

            public void addSigninListener(SigninListener l) {
                signinlistener = l;
            }

            public void actionPerformed(ActionEvent e) {
                /* whenever user click sign-in button, (s)he is generating sign-in event.
                 */
                SigninEvent se = new SigninEvent(jt_User.getText(), jt_Passwd.getText());
                signinlistener.whenUserClickSignin(se);
            }
        }

  MainFrame class : (Event listening class)
        public MainFrame extends JFrame implements SigninListener {
            SigninDialog jd_Signin;
            public MainFrame() {
                /* build ui here */
                jd_Signin.addSigninListner(this);
            }
            public void whenUserClickSignin(SigninEvent e) {
                jd_Signin.dispose();
                /* user authentication here */
            }
        }

I hope you'll see the concept from the classes above.
G noon
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10925973
>> great. thanks.

If you feel like your question is answered,
then please kindly close this question by accepting one or more of the comments that were useful to you.
If you feel like your question is not yet answered, keep asking more explanation.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10927210
Thanks for accepting.
That keeps us answering your future questions too.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question