Name: Manish Kumhar Class: Tyco-A Roll No: 43 Subject: Ajp (Experiment: 3)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

NAME: MANISH KUMHAR

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

II. Relevant Program Outcomes (POs)


 Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to
solve the computer group related problems.
 Discipline knowledge: Apply Computer Programming knowledge to solve the computer group
related problems.
 Experiments and practice: Plan to perform experiments and practices to use the results to solve
the computer group related problems.
 Engineering tools: Apply relevant Computer programming / technologies and tools with an
understanding of the limitations.
 Individual and Team work: Function effectively as a leader and team member in
diverse/multidisciplinary teams.
 Communication: Communicate effectively in oral and written form.

III. Competency and Practical skills


To develop standalone applications
The practical is expected to develop the following skills:
1. Able to apply different layouts to Applet, Frame and Panel
2. Able to demonstrate the use of different types of Layout Manager

IV. Relevant Course Outcome(s)


Develop programs using GUI Framework (AWT and Swing).

V. Practical Outcome (PrOs)


Write a program to design simple calculator with the use of GridLayout .

VI. Relevant Affective domain related Outcome(s)


1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VII. Minimum Theoretical Background


Layout Manager is a facility that determines how components should be arranged when they are
added to the container. Layout Manager is an interface that is implemented by all the classes of
layout managers. There are following classes that represent the layout managers.

Layout Types

FlowLayout GridLayout BorderLayout CardLayout GridbagLayout


Understand the default layout for different containers such as Applet, Frame, Panel.
Grid Layout is used to make a bunch of components equal in size and displays them in the requested
number of rows and columns. One component is displayed in each rectangle.
The list of Constructor for GridLayout are:
1. GridLayout(): creates a grid layout with one column per component in a row.
2. GridLayout(int rows, int columns): creates a grid layout with the given rows and columns but no
gaps between the components.
3. GridLayout(int rows, int columns, int hgap, int vgap): creates a grid layout with the given rows
and columns along with given horizontal and vertical gaps if we give setLayout(null) the default
layout is disabled.then we have to use setBounds method to layout the components.

VIII. Resources required (Additional)– Nil

IX. Resources used (Additional)

Sr. Name of Broad


Quantity Remarks (If any)
No. Resource Specification
1

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();
}
}

2. Write a program to display The Number on Button from 0 to 9.


Program:-
import java.awt.*;
class GridLayoutExample
{
GridLayoutExample()
{
Frame f = new Frame("Manish Kumhar 43");
Button b0 =new Button(" 0");
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");
f.add(b0);
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.setSize(300,300);
f.setVisible(true);
f.setLayout(new GridLayout(4,3));
}
public static void main(String args[])
{
GridLayoutExample g = new GridLayoutExample();
}
}
XI. Result (Output of Code):

...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................

Output 1:- Output 2:-

XII. Practical Related Questions


Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. Give name of default Layout for Different container.
2. List the names of BorderLayout regions.
3. Write the default horizontal and vertical gap in FlowLayout.
4. Write the use of Insets in border layout.
(Space for answer)

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:-

2. Write a program to generate following output using Border Layout


Figure 4

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

XV. Assessment Scheme

Performance Indicators Weightage


Process related (35 Marks) 70%
1. Logic formation 30%
2. Debugging ability 30%
3. Follow ethical practices 10%
Product related (15 Marks) 30%
4. Expected output 10%
5. Timely Submission 10%
6. Answer to sample questions 10%
Total (50 Marks) 100%

List of Students /Team Members

1. …………………………………..
2. …………………………………..
3. …………………………………..

Dated signature of
Marks Obtained
Teacher

Process Product
Total(50)
Related(35) Related(15)

You might also like