How to implement a mode dialog in the Java applet?

zhaozj2021-02-08  375

The key to implementing the mode dialog box in the Java applet is to specify a correct parent window for the dialog when you create a dialog. Because Applet is a subclass of the Panel class, you can't use the parent window of the dialog, so first To get the window where the applet is located, the parent window of the Mode dialog. The sample code is as follows:

.....

Dialog D = New Dialog (getParentWindow (Comp), Title

/ / CoMP is any component on the applet

....

Public void getParentWindow (Component ComponApplet, String Title) {

Container c = componapplet.getParent ();

While (c! = null) {

IF (c instanceof frame)

Return (frame) C;

C = c.getParent ();

}

Return NULL;

}

转载请注明原文地址:https://www.9cbs.com/read-889.html

New Post(0)