Let Us Know About Layout managers In Java
Layout Managers are used to arrange controls in the window.
1. FlowLayout: This manager arranges controls from left to right and top to bottom way. Its default alignment is center. By default, Applet window contains flow layout manager.
setLayout() method is used to attach layout manager to Applet window and FlowLayout() constructor takes alignment value.
2. BorderLayout: This layout manager divides applet into five areas. Those are
add() method takes control, control displaying area.
Example: add(new Button("one"), BorderLayout.EAST);
getInsets() method returns Insets object to provide gap among applet edge and components displaying area. Insets() constructor takes values for providing gap. These values are belong to north, west, south, and east.
GridLayout manager divides window into number of rows and columns. Each cell contains equal width and height.
Panel: It is rectangular transparent window. It does not contain title bar, menubar and so on. It is dependant window. By default applet contains panel. Panel class is used to create panel. CardLayout manager arranges cards like playing cards arrangement. It puts all cards one on another and shows cards one by one. Its next() method puts down the currently displaying card and shows next card.
Its show() method shows the referenced panel from the panels list.
Example: cardLO.show(osCards, "W");
Here add method adds winPan to OsCards Panel with the reference name W.
Example: osCards.add(winPan, "W");
Frame class creates frame window. It is a window which may contains title bar, menu bar and so on. Menubar class creates menu bar control. setMenubar() method attaches menu bar control to window. Menu class is used to create menu. Its constructor takes caption of menu. MenuItem class creates options in the menu. CheckboxMenuItem class creates checkbox type of menu item. At run time, if it is selected tick mark is appeared and disappeared when it is deselected. WindowAdapter is replacement class for WindowListener interface. It contains windowClosing() method. This method contains WindowEvent type of argument. This method is operated when registered window close button is pressed. setVisible() method takes Boolean value. True for showing window and false for hiding window. getActionCommand() method returns caption of pressed menu item. getParameter() method takes width or height string and returns width or height value of applet.setSize() method takes width, height values and sets that size to window.
Dialog box takes user input and do some process.
Dialog boxes are two types.
1. Model dialog box
2. Modeless dialog box.
1. Model Dialog box:
When this dialog box is displaying on the screen, user cannot operate parent window of this dialog box.
Example: open, save dialog boxes.
2. Modeless dialog box:
When this dialog box is displaying on the screen, user can operates parent window of this dialog box.
Example: find, replace dialog boxes.
Dialog class creates dialog box control. Its constructor takes parent window address, title, true for modal dialogbox/ false for modeless dialog box. dispose() method destroys dialog box.
FileDialog class creates open or save dialog box. Its constructor takes parent instance address, title, FileDialog.LOAD for open dialog box/ FileDialog.SAVE for save dialog box.