0% found this document useful (0 votes)
74 views10 pages

Practical No.3

This document contains the details of a student's practical assignment on creating a simple calculator application using grid layout in Java. It includes the code for two programs - one that demonstrates a 5x5 grid layout with buttons, and another that displays the numbers 0-9 on buttons in a 3x3 grid. It also lists some questions and answers regarding default layouts, border layout regions, and includes code examples to generate specific outputs using grid layout and border layout.

Uploaded by

Siddhi Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views10 pages

Practical No.3

This document contains the details of a student's practical assignment on creating a simple calculator application using grid layout in Java. It includes the code for two programs - one that demonstrates a 5x5 grid layout with buttons, and another that displays the numbers 0-9 on buttons in a 3x3 grid. It also lists some questions and answers regarding default layouts, border layout regions, and includes code examples to generate specific outputs using grid layout and border layout.

Uploaded by

Siddhi Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Enrollment No : 1901160126

Name : Siddhi Dhanaji Sawant


Roll No. : 23
Branch : Information Technology
Semester : 5th
Practical No. 03
---------------------------------------------------------------------------

Aim : Write a program to design simple calculator with the use


of Grid Layout.

X. Program Code
1. Write java Program to Demonstrate Grid of 5* 5.
Code :

import java.awt.*;
import java.applet.*;
public class Pra3_1 extends Applet
{
int n=5;
public void init()
{
setLayout(new GridLayout(n,n));
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
add(new Button());
}
}
}
}
Output :
2. Write a program to display The Number on Button from 0 to
9.
Code:
import java.awt.*;
import java.awt.event.*;
public class Grid
{
Grid()
{

Frame f=new Frame();


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(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.setLayout(new GridLayout(3,3));
f.setSize(500,500);
f.setVisible(true);
}
public static void main(String[] args) {
new Grid();
}
}
Output:
XII. Practical Related Questions
1. Give name of default Layout for Different container.
Answer : For Panels, including Applets, the default layout
manager belongs to the class FlowLayout. For Windows, the
default layout manager is a BorderLayout.

2. List the names of BorderLayout regions.


Answer :
i.East
ii.West
iii.South
iv.North
v.Center

3. Write the default horizontal and vertical gap in


FlowLayout.
Answer : 5Unit

4. Write the use of Insets in border layout.


Answer : If you want to leave a small space between the
container that holds your components and the windows that
contains. To do this, override the getInsets() method that is
defined by the container.
Insert(int top, int left, int bottom, int right)
The values passed in top, left, bottom and right specify the
amount of space between the container and its enclosing
window.

XIII. Exercise
1. Write a program to generate following output.
Program Code :

import java.awt.*;
class GridLayoutExample1 extends Frame
{
GridLayoutExample1()
{
Button[] button =new Button[6];
setLayout(new GridLayout(3,2));
for(int i=1; i<=button.length;i++)
{
if(i==6)
{
break;
}
else
{
button[i]=new Button("Button "+(i));
add(button[i]);
}
}
}
}
class Pra3_3
{
public static void main(String args[])
{
GridLayoutExample1 frame = new GridLayoutExample1();
frame.setTitle("GridLayout in Java Example");
frame.setSize(400,150);
frame.setVisible(true);
}
}

2. Write a program to generate following output using Border


layout.
Program Code :

import java.awt.*;
class BorderLayoutExample extends Frame
{
BorderLayoutExample()
{
setLayout(new BorderLayout());
add(new Button("NORTH"),BorderLayout.NORTH);
add(new Button("SOUTH"),BorderLayout.SOUTH);
add(new Button("EAST"),BorderLayout.EAST);
add(new Button("WEST"),BorderLayout.WEST);
add(new Button("CENTER"),BorderLayout.CENTER);
}
}
class Pra3_4
{
public static void main(String args[])
{
BorderLayoutExample frame = new BorderLayoutExample();
frame.setTitle("BorderLayout in Java Example");
frame.setSize(400,150);
frame.setVisible(true);
}
}

You might also like