0% found this document useful (0 votes)
4 views5 pages

AJP PR 03(10)

Uploaded by

Ekrama Ansari
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)
4 views5 pages

AJP PR 03(10)

Uploaded by

Ekrama Ansari
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/ 5

DEPARTMENT OF COMPUTER ENGINEERING

Subject: Advance Java Subject Code: 22516


Semester: 5th Semester Course: Computer Engineering
Laboratory No: V119 Name of Subject Teacher: Prasad Koyande
Name of Student: Ekrama Ansari Roll no: 22203C0010

Experiment No: 3
Title of Experiment Write a program to design simple calculator with the use of Grid Layout.
PRACTICE SET:
1. Write java Program to Demonstrate Grid of 5* 5.

CODE:

import javax.swing.*;
import java.awt.*;

public class GridLayout5x5 {


public static void main(String[] args) {
// Create a new JFrame
JFrame frame = new JFrame("5x5 Grid Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(5, 5)); // Set GridLayout with 5 rows and 5 columns

// Create and add buttons to the grid


for (int i = 1; i <= 25; i++) {
JButton button = new JButton(String.valueOf(i)); // Create button with number
frame.add(button); // Add button to the frame
}

// Set frame properties


frame.setSize(400, 400); // Set the size of the frame
frame.setVisible(true); // Make the frame visible
}
}

OUTPUT:

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

CODE:

import javax.swing.*;
import java.awt.*;

public class GridLayout0to9 {


public static void main(String[] args) {
// Create a new JFrame
JFrame frame = new JFrame("0 to 9 Grid Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(2, 5)); // Set GridLayout with 2 rows and 5 columns

// Create and add buttons with numbers 0 to 9


for (int i = 0; i <= 9; i++) {
JButton button = new JButton(String.valueOf(i)); // Create button with number
frame.add(button); // Add button to the frame
}

// Set frame properties


frame.setSize(400, 200); // Set the size of the frame
frame.setVisible(true); // Make the frame visible
}
}

OUTPUT:

Page | 2
XI. EXERCISE:

1. Write a program to generate following output.

CODE:

import java.applet.Applet;
import java.awt.*;

/*
<applet code="GridLayoutApplet" width=300 height=300>
</applet>
*/

public class GridLayoutApplet extends Applet {

public void init() {


setLayout(new GridLayout(3, 2, 10, 10)); // 3 rows, 2 columns, 10px gaps

add(new Button("Button 1"));


add(new Button("Button 2"));
add(new Button("Button 3"));
add(new Button("Button 4"));
add(new Button("Button 5"));
}
}

OUTPUT:

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

CODE:

import java.awt.*;
import java.applet.*;
import java.util.*;

/*
<applet code="BorderLayoutProgram" width=300 height=300>
</applet>
*/

public class BorderLayoutProgram extends Applet {


public void init() {
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);
}
}

OUTPUT:

Page | 4
Grade and Process Related Product Related Dated Sign
Dated (35) (15)
Signature of
Teacher

Page | 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy