Posts

Showing posts with the label Layout manager in Java

Write a Java program to illustrate basic calculator using grid layout manager.

 //calculator.html /*<html > <applet code="calculator" width =1000 height =1000></applet> </html>*/   //calculator.java import java.awt.*; import java.awt.event.*; public class calculator implements ActionListener {     int c,n;     String s1,s2,s3,s4,s5;     Frame f;     Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,add,sub,mul,div,mod,eq,clear;     Panel p;     TextField tf;     GridLayout g;     public calculator1()     {         f = new Frame("My calculator");         p = new Panel();         f.setLayout(new FlowLayout()); g = new GridLayout(4,4,10,20);         p.setLayout(g); //creating components   tf = new TextField(20);           b0=new Button("0");   b1=new Button("1");   b2=new Button("2");   b3=new Button("3"); ...

Layout management - Layout manager types - BorderLayout ,GridLayout ,FlowLayout and Cardlayout.

Layout Manager in Java The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes of layout managers. A layout manager is an object that controls the  size and the position of the components in a container. The layout manager is  set by the setLayout() method. If no call to setLayout( ) is made, then the default layout  manager is used. Syntax : void setLayout(LayoutManager layoutObj) Here, layoutObj is a reference to the desired layout manager. If you wish to disable the layout manager and position components manually, pass null for layoutObj. Types of Layout managers : There are following classes that represents the layout managers: 1. java.awt.BorderLayout 2. java.awt.FlowLayout 3. java.awt.GridLayout 4. java.awt.CardLayout 1. BorderLayout : The BorderLayout is used to arrange the components in five regions: north, south, east, west and center. Each region (area) may co...