Write a program to design simple calculator with the use of Grid Layout
Program Code
1. Write java Program to Demonstrate Grid of 5* 5
import java.awt.*;
/**
*
* @author TotalProgramming
*/
public class programcode1 {
programcode1()
{
Frame frame = new Frame();
frame.setLayout(new GridLayout(5,5));
for(int i = 1 ; i <= 25 ; i++)
{
frame.add(new Button(" "+i));
}
frame.setSize(500, 500);
frame.setVisible(true);
}
public static void main(String args[])
{
programcode1 pc1 = new programcode1();
}
}
OUTPUT :
Write java Program to Demonstrate Grid of 5* 5 |
2. Write a program to display The Number on Button from 0 to 9.
import java.awt.*;
/**
*
* @author totalProgramming
*/
public class programcode2 {
programcode2()
{
Frame frame = new Frame();
frame.setLayout(new GridLayout(3,3));
for(int i = 0 ; i <= 9 ; i++)
{
frame.add(new Button(" "+i));
}
frame.setSize(500, 500);
frame.setVisible(true);
}
public static void main(String args[])
{
programcode2 pc2 = new programcode2();
}
}
OUTPUT :
Write a program to display The Number on Button from 0 to 9. |
Exercise :-
1. Write a program to generate following output.
Write a program to design simple calculator with the use of Grid Layout. |
OUTPUT :
import java.awt.*;
import javax.swing.JButton;
/**
*
* @author totalprogramming
*/
public class exercise1 {
exercise1()
{
Frame frame = new Frame();
frame.setLayout(new GridLayout(2,3));
for(int i = 1 ; i <= 5 ; i++)
{
frame.add(new JButton("Button "+i));
}
frame.setSize(500, 500);
frame.setVisible(true);
}
public static void main(String args[])
{
exercise1 ex1 = new exercise1();
}
}
2. Write a program to generate following output using Border Layout
Write a program to generate following output using Border Layout |
import java.awt.*;
/**
*
* @author totalprogramming
*/
public class exercise2 {
exercise2()
{
Frame frame = new Frame();
frame.setLayout(new BorderLayout());
frame.add(new Button("EAST"),BorderLayout.EAST);
frame.add(new Button("WEST"),BorderLayout.WEST);
frame.add(new Button("NORTH"),BorderLayout.NORTH);
frame.add(new Button("SOUTH"),BorderLayout.SOUTH);
frame.add(new Button("CENTER"),BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setVisible(true);
}
public static void main(String args[]) {
exercise2 ex2 = new exercise2();
}
}