Java swing dialog box and parent window value passing instance

Source: Internet
Author: User
I used the Parent and Child Window to pass the value and searched the internet for a bunch of nonsense. I felt very uncomfortable. I studied it for a long time. It turned out to be very simple. The thread is also used in this example. You don't need to be more clear. Let's just move on to the code. note how to pass the value in the ///// Dialog Box package des; import java. AWT. color;
Import java. AWT. Dialog;
Import java. AWT. Font;
Import java. AWT. frame;
Import java. AWT. graphicsconfiguration;
Import java. AWT. window;
Import java. AWT. event. mouseadapter;
Import java. AWT. event. mouseevent;
Import java. AWT. event. windowadapter;
Import java. AWT. event. javaswevent; import javax. Swing. jbutton;
Import javax. Swing. jdialog;
Import javax. Swing. jlabel;
Import javax. Swing. jscrollpane;
Import javax. Swing. jtextarea;
Import javax. Swing. swingutilities;
Import javax. Swing. uimanager; import org. Dyno. Visual. Swing. layouts. constraints;
Import org. Dyno. Visual. Swing. layouts. grouplayout;
Import org. Dyno. Visual. Swing. layouts. Leading; // vs4e -- Do not remove this line!
Public class test extends jdialog {Private Static final long serialversionuid = 1l;
Private jbutton jbutton0;
Private jlabel jlabel0;
Private jtextarea jtextarea0;
Private jscrollpane jscrollpane0;
Freamtest parent;
Private Static final string preferred_look_and_feel = "javax. Swing. plaf. Metal. metallookandfeel ";
Public test (){
Initcomponents ();
} Public test (freamtest parent ){
Super (parent );
This. Parent = parent;
Initcomponents ();
} Public test (freamtest parent, Boolean modal ){
Super (parent, modal );
This. Parent = parent;
Initcomponents ();
} Public test (freamtest parent, String title ){
Super (parent, title );
This. Parent = parent;
Initcomponents ();
} Public test (freamtest parent, String title, Boolean modal ){
Super (parent, title, modal );
This. Parent = parent;
Initcomponents ();
} Public test (freamtest parent, String title, Boolean modal,
Graphicsconfiguration Arg ){
Super (parent, title, modal, ARG );
This. Parent = parent;
Initcomponents ();
} Public test (dialog parent ){
Super (parent );
Initcomponents ();
} Public test (dialog parent, Boolean modal ){
Super (parent, modal );
Initcomponents ();
} Public test (dialog parent, String title ){
Super (parent, title );
Initcomponents ();
} Public test (dialog parent, String title, Boolean modal ){
Super (parent, title, modal );
Initcomponents ();
} Public test (dialog parent, String title, Boolean modal,
Graphicsconfiguration Arg ){
Super (parent, title, modal, ARG );
Initcomponents ();
} Public test (window parent ){
Super (parent );
Initcomponents ();
} Public test (window parent, modalitytype ){
Super (parent, modalitytype );
Initcomponents ();
} Public test (window parent, String title ){
Super (parent, title );
Initcomponents ();
} Public test (window parent, String title, modalitytype ){
Super (parent, title, modalitytype );
Initcomponents ();
} Public test (window parent, String title, modalitytype,
Graphicsconfiguration Arg ){
Super (parent, title, modalitytype, ARG );
Initcomponents ();
} Private void initcomponents (){
Setfont (new font ("dialog", Font. Plain, 12 ));
Setbackground (color. White );
Setforeground (color. Black );
Setlayout (New grouplayout ());
Add (getjbutton0 (), new constraints (new leading (297, 10, 10), new leading (45, 10, 10 )));
Add (getjlabel0 (), new constraints (new leading (149, 10, 10), new leading (21, 12, 12 )));
Add (getjscrollpane0 (), new constraints (new leading (89,100, 12, 12), new leading (64, 80, 10, 10 )));
Addwindowlistener (New windowadapter (){
 
Public void windowclosed (invalid wevent event ){
Windowwindowclosed (event );
}
 
Public void windowclosing (invalid wevent event ){
Windowwindowclosing (event );
}
});
Setsize (462,240 );
} Private jscrollpane getjscrollpane0 (){
If (jscrollpane0 = NULL ){
Jscrollpane0 = new jscrollpane ();
Jscrollpane0.setviewportview (getjtextarea0 ());
}
Return jscrollpane0;
} Private jtextarea getjtextarea0 (){
If (jtextarea0 = NULL ){
Jtextarea0 = new jtextarea ();
Jtextarea0.settext ("jtextarea0 ");
}
Return jtextarea0;
} Private jlabel getjlabel0 (){
If (jlabel0 = NULL ){
Jlabel0 = new jlabel ();
Jlabel0.settext ("dialog ");
}
Return jlabel0;
} Private jbutton getjbutton0 (){
If (jbutton0 = NULL ){
Jbutton0 = new jbutton ();
Jbutton0.settext ("jbutton0 ");
Jbutton0.addmouselistener (New mouseadapter (){
 
Public void mouseclicked (mouseevent event ){
Jbutton0mouseclicked (event );
}
});
}
Return jbutton0;
} Private Static void installlnf (){
Try {
String lnfclassname = preferred_look_and_feel;
If (lnfclassname = NULL)
Lnfclassname = uimanager. getcrossplatformlookandfeelclassname ();
Uimanager. setlookandfeel (lnfclassname );
} Catch (exception e ){
System. Err. println ("cannot install" + preferred_look_and_feel
+ "On this platform:" + E. getmessage ());
}
}/**
* Main Entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
Public static void main (string [] ARGs ){
Installlnf ();
Swingutilities. invokelater (New runnable (){
@ Override
Public void run (){
Test dialog = new test ();
Dialog. setdefacloseoperation (test. dispose_on_close );
Dialog. settitle ("test ");
Dialog. setlocationrelativeto (null );
Dialog. getcontentpane (). setpreferredsize (dialog. getsize ());
Dialog. Pack ();
Dialog. setvisible (true );
}
});
}
// Close
Private void windowwindowclosed (invalid wevent event ){

} Private void jbutton0mouseclicked (mouseevent event ){


String TT = jtextarea0.gettext ();
This. Parent. getjtextfield0 (). settext (TT );
System. Out. println ("6666666666 ");


} Private void windowwindowclosing (invalid wevent event ){

String TT = jtextarea0.gettext ();
This. Parent. getjtextfield0 (). settext ("hhhaayyy ");

System. Out. println ("yyyyyy ");
// Jtextfield0.
} // Parent window package des; import java. AWT. event. mouseadapter;
Import java. AWT. event. mouseevent; import javax. Swing. jbutton;
Import javax. Swing. jdialog;
Import javax. Swing. jframe;
Import javax. Swing. jtextfield;
Import javax. Swing. swingutilities;
Import javax. Swing. uimanager; import org. Dyno. Visual. Swing. layouts. constraints;
Import org. Dyno. Visual. Swing. layouts. grouplayout;
Import org. Dyno. Visual. Swing. layouts. Leading; // vs4e -- Do not remove this line!
Public class freamtest extends jframe {Private Static final long serialversionuid = 1l;
Private jbutton jbutton0;
Private jtextfield jtextfield0;
String vv;
Private Static final string preferred_look_and_feel = "javax. Swing. plaf. Metal. metallookandfeel ";
 
 
Public jtextfield getjtextfield0 (){
Return jtextfield0;
} Public void setjtextfield0 (jtextfield jtextfield0 ){
This. jtextfield0 = jtextfield0;
} Public String getvv (){
Return vv;
} Public void setvv (string vv ){
This. VV = vv;
} Public freamtest (){
Initcomponents ();
} Private void initcomponents (){
Setlayout (New grouplayout ());
Add (getjbutton0 (), new constraints (new leading (129, 10, 10), new leading (40, 10, 10 )));
Add (getjtextfield0 (), new constraints (new leading (31,254, 12, 12), new leading (86, 47, 10, 10 )));
Addmouselistener (New mouseadapter (){
 
Public void mouseclicked (mouseevent event ){
Mousemouseclicked (event );
}
});
Setsize (320,240 );
} Private jtextfield getjtextfield0 (){
If (jtextfield0 = NULL ){
Jtextfield0 = new jtextfield ();
Jtextfield0.settext ("jtextfield0 ");
}
Return jtextfield0;
} Private jbutton getjbutton0 (){
If (jbutton0 = NULL ){
Jbutton0 = new jbutton ();
Jbutton0.settext ("tttttt ");
Jbutton0.addmouselistener (New mouseadapter (){
 
Public void mouseclicked (mouseevent event ){
Jbutton0mouseclicked (event );
}
});
}
Return jbutton0;
} Private Static void installlnf (){
Try {
String lnfclassname = preferred_look_and_feel;
If (lnfclassname = NULL)
Lnfclassname = uimanager. getcrossplatformlookandfeelclassname ();
Uimanager. setlookandfeel (lnfclassname );
} Catch (exception e ){
System. Err. println ("cannot install" + preferred_look_and_feel
+ "On this platform:" + E. getmessage ());
}
}/**
* Main Entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
Public static void main (string [] ARGs ){
Installlnf ();
Swingutilities. invokelater (New runnable (){
@ Override
Public void run (){
Freamtest frame = new freamtest ();
Frame. setdefaclocloseoperation (freamtest. exit_on_close );
Frame. settitle ("freamtest ");
Frame. getcontentpane (). setpreferredsize (frame. getsize ());
Frame. Pack ();
Frame. setlocationrelativeto (null );
Frame. setvisible (true );
}
});
} Private void mousemouseclicked (mouseevent event ){

} Private void jbutton0mouseclicked (mouseevent event ){

// Jdialog TT = new test (this, "dialogtest", true );
// TT. Show ();
// System. Out. println ("sdgf ");
Threadteat RRR = new threadteat (this );
Thread Th1 = new thread (RRR );
Th1.start ();
}}
/// Thread package des; public class threadteat implements runnable {
 
Freamtest ff;
Threadteat (){}
 
Threadteat (freamtest ff ){
This. FF = ff;
}
Public static void main (string [] ARGs ){
Threadteat RRR = new threadteat ();
Thread Th1 = new thread (RRR );
Th1.start ();
} @ Override
Public void run (){
// Todo auto-generated method stub
Int C = 0;
While (true ){

If (C = 5 ){
Test TT = new test (ff );
TT. Show ();
}


Try {
Thread. Sleep (1000 );
C ++;
System. Out. println ("C is ---" + C );
} Catch (interruptedexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}

}}
It's simple and clear. I really don't understand how such a simple thing cannot be found on the Internet. It's useless nonsense, there are not many useful items on the Internet, and junk export is all!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.