Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 3)
Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 3)
Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 3)
CLASS: TYCO-A
ROLL NO: 43
SUBJECT: AJP (EXPERIMENT: 3)
Practical No. 3: Write a program to design simple calculator with the use
of Grid Layout.
I. Practical Significance:
A layout manager automatically arranges your controls within a window. While it is possible to lay
out Java controls by hand, too, you generally won’t. It is very tedious to manually lay out a large
number of components
Layout Types
X. Program Code: Teacher must assign a separate program statement to group of 3-4 students.
1. Write java Program to Demonstrate Grid of 5* 5
Program:-
import java.awt.*;
class GridLayoutExample
{
GridLayoutExample()
{
Frame f = new Frame("Manish Kumhar 43");
Button b1 =new Button(" 1");
Button b2 =new Button(" 2");
Button b3 =new Button(" 3");
Button b4 =new Button(" 4");
Button b5 =new Button(" 5");
Button b6 =new Button(" 6");
Button b7 =new Button(" 7");
Button b8 =new Button(" 8");
Button b9 =new Button(" 9");
Button b10 =new Button(" 10");
Button b11 =new Button(" 11");
Button b12 =new Button(" 12");
Button b13 =new Button(" 13");
Button b14 =new Button(" 14");
Button b15 =new Button(" 15");
Button b16 =new Button(" 16");
Button b17 =new Button(" 17");
Button b18 =new Button(" 18");
Button b19 =new Button(" 19");
Button b20 =new Button(" 20");
Button b21 =new Button(" 21");
Button b22 =new Button(" 22");
Button b23 =new Button(" 23");
Button b24 =new Button(" 24");
Button b25 =new Button(" 25");
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(b6);
f.add(b7);
f.add(b8);
f.add(b9);
f.add(b10);
f.add(b11);
f.add(b12);
f.add(b13);
f.add(b14);
f.add(b15);
f.add(b16);
f.add(b17);
f.add(b18);
f.add(b19);
f.add(b20);
f.add(b21);
f.add(b22);
f.add(b23);
f.add(b24);
f.add(b25);
f.setSize(300,300);
f.setVisible(true);
f.setLayout(new GridLayout(5,5));
}
public static void main(String args[])
{
GridLayoutExample g = new GridLayoutExample();
}
}
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
XIII. Exercise
1. Write a program to generate following output
Figure 3
Program:-
import java.awt.*;
class GridLayoutExample
{
GridLayoutExample()
{
Frame f = new Frame("Manish Kumhar 43");
Button b1 =new Button("Button 1");
Button b2 =new Button("Button 2");
Button b3 =new Button("Button 3");
Button b4 =new Button("Button 4");
Button b5 =new Button("Button 5");
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.setSize(400,200);
f.setVisible(true);
f.setLayout(new GridLayout(3,2,10,10));
}
public static void main(String args[])
{
GridLayoutExample g = new GridLayoutExample();
}
}
Output:-
Program:-
import java.awt.*;
public class BorderDemo
{
Frame f = new Frame("Manish Kumhar 43");
public BorderDemo()
{
Button b1 = new Button("North");
Button b2= new Button("Center");
Button b3= new Button("East");
Button b4= new Button("South");
Button b5= new Button("West");
f.add(b1, BorderLayout.NORTH);
f.add(b2, BorderLayout.CENTER);
f.add(b3, BorderLayout.EAST);
f.add(b4, BorderLayout.SOUTH);
f.add(b5, BorderLayout.WEST);
f.setSize(280,150);
f.setVisible(true);
f.setLayout(new BorderLayout());
}
public static void main(String[] args)
{
BorderDemo bd = new BorderDemo();
}
}
Output:-
XIV. References/ Suggestions for Further Reading
1. https://www.javatpoint.com
2. https://www.tutorialspoint.com/java
3. The complete reference Java 2 by Herbert Schildt
1. …………………………………..
2. …………………………………..
3. …………………………………..
Dated signature of
Marks Obtained
Teacher
Process Product
Total(50)
Related(35) Related(15)