swing - Re-using JTextField in Java pop-ups -


i'm building large java application uses multiple pop-up windows. of these windows must able displayed @ same time (for instance, separate pop-ups google earth , webcam feed), of them can displayed 1 @ time (for instance, error messages). first kind of pop-ups, webcam kind, working fine. error message pop-ups act webcam type of pop-ups (that is, create new .class files , there can multiple error pop-ups). how fix this? should create new error class?

also, in 1 of webcam-type pop-ups, have jtextfields read username , password. log-in popup works fine, if use once, close it, , use again, doing gettext() on jtextfields returns empty string. think problem might related 1 above, not sure.

passwordaction.addactionlistener(new actionlistener() {             jframe pwpop=new jframe("log in");             jtextfield unamefield;             jtextfield pwfield;             public void actionperformed(actionevent arg0) {                 pwpop.setbounds(250,200,300,150);                 jpanel pwpoppanel=new jpanel(new flowlayout(flowlayout.left,10,10));                 pwpop.add(pwpoppanel);                 unamefield=new jtextfield();                 pwfield=new jtextfield();                 jbutton loginbutton=new jbutton("log in");                 jbutton cancelbutton=new jbutton("cancel");                 jlabel logintext=new jlabel("username:");                 jlabel passwordtext=new jlabel("password:");                 jpanel buttonpanel=new jpanel(new flowlayout(flowlayout.center,5,0));                 pwpoppanel.add(logintext);                 pwpoppanel.add(unamefield);                 pwpoppanel.add(passwordtext);                 pwpoppanel.add(pwfield);                 buttonpanel.add(loginbutton);                 buttonpanel.add(cancelbutton);                 pwpoppanel.add(buttonpanel);                 loginbutton.addactionlistener(new actionlistener() {                     jframe logerrorframe;                     public void actionperformed(actionevent arg0) {                         if (dologin(unamefield.gettext(), pwfield.gettext(), "")) {                             unamefield.settext(null);                             pwfield.settext(null);                             pwpop.setvisible(false);                         }                     }                 });                 pwpop.setvisible(true);             }         }); 

as andrew thompson showed me, joptionpane solution looking for. capable of creating type of popup may need.

joptionpane javadoc

simple dialog joptionpane


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -