0% found this document useful (0 votes)
3 views

Java Practical 17

The document contains three Java Swing applications that demonstrate the use of GridLayout. The first application creates a 5x5 grid of buttons numbered 1 to 25, the second creates a grid of buttons numbered 0 to 9, and the third showcases a 3x2 grid with five buttons. Each application sets up a JFrame with specific titles, sizes, and layouts before displaying the window.

Uploaded by

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

Java Practical 17

The document contains three Java Swing applications that demonstrate the use of GridLayout. The first application creates a 5x5 grid of buttons numbered 1 to 25, the second creates a grid of buttons numbered 0 to 9, and the third showcases a 3x2 grid with five buttons. Each application sets up a JFrame with specific titles, sizes, and layouts before displaying the window.

Uploaded by

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

Practical 17:Q 1

import javax.swing.*;
import java.awt.*;
public class GridFrame extends JFrame
{
public GridFrame()
{
setTitle("5x5 Grid Layout Example");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(5, 5));
for (int i = 1; i <= 25; i++)
{
add(new JButton(String.valueOf(i)));
}
setVisible(true);
}
public static void main(String[] args)
{
new GridFrame();
}
}

Q2.

import javax.swing.*;
import java.awt.*;
public class NumberButtonsFrame extends JFrame
{
public NumberButtonsFrame()
{
setTitle("Number Buttons (0-9)");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(2, 5));
for (int i = 0; i <= 9; i++)
{
add(new JButton(String.valueOf(i)));
}
setVisible(true);
}
public static void main(String[] args)
{
new NumberButtonsFrame();
}
}

Q3.
import javax.swing.*;
import java.awt.*;
public class GridLayoutDemo extends JFrame
{
public GridLayoutDemo()
{
setTitle("GridLayout Demo");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 2, 10, 10));
add(new JButton("Button 1"));
add(new JButton("Button 2"));
add(new JButton("Button 3"));
add(new JButton("Button 4"));
add(new JButton("Button 5"));
setVisible(true);
}
public static void main(String[] args)
{
new GridLayoutDemo();
}
}

You might also like