Container Classes Window The window is the container








- Slides: 8

Container Classes Window - The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window Frame - The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc. Dialog - Dialog is considered as a window without having a menu bar. - This sub class of window will help in taking inputs from the user and also gives alerts to the user. - An object of the Dialog class cannot exist without an associated object of the Frame class. Panel - The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.


Frame Example import java. awt. *; class First extends Frame { First() { Button b=new Button("click me"); b. set. Bounds(30, 100, 80, 30); // setting button position add(b); //adding button into frame set. Size(300, 300); //frame size 300 width and 300 height set. Layout(null); //no layout manager set. Visible(true); //now frame will be visible, by default not visible } public static void main(String args[]) { First f=new First(); } }


import java. awt. *; Dialog Example public class Dialog. Example { Dialog d; Dialog. Example() { Frame f= new Frame(); d = new Dialog(f , "Dialog Example", true); d. set. Layout( new Flow. Layout() ); Button b = new Button ("OK"); d. add(b); d. set. Size(300, 300); d. set. Visible(true); } } public static void main(String args[]) { new Dialog. Example(); }


Panel Example import java. awt. *; public class Panel. Example { Panel. Example() { Frame f= new Frame("Panel Example"); Panel panel=new Panel(); panel. set. Bounds(40, 80, 200); panel. set. Background(Color. gray); Button b 1=new Button("Button 1"); Button b 2=new Button("Button 2"); } panel. add(b 1); panel. add(b 2); f. add(panel); f. set. Size(400, 400); f. set. Layout(null); f. set. Visible(true); } public static void main(String args[]) { new Panel. Example(); }
