Monday, 3 November 2014

Write a java program to create the following GUI. Using appropriate layout managers.





Name : Shreyal Mandot

Title : Assignment 6b1. Write a java program to create the following GUI. Using appropriate layout managers.




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

public class ass6b1 extends JFrame
{
 
    private JTextField t1;
    private JButton b[];
    private JPanel p1,p2;
   
    public ass6b1()
{
   
    setTitle("Simple Calculator");
   
    t1=new JTextField(30);
    p1=new JPanel();
    p2=new JPanel();

p1.setLayout(new FlowLayout(FlowLayout.CENTER));
p1.add(t1);
 
   b=new JButton[16];
   
p2.setLayout(new GridLayout(4,4,5,5));
String[] str={"1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"};
   
      for(int i=0;i<str.length;i++)
      {
     
        b[i]=new JButton(str[i]);
        p2.add(b[i]);
   
      }
   
      this.setLayout(new BorderLayout());
      this.add(p1,BorderLayout.NORTH);
      this.add(p2,BorderLayout.CENTER);
      this.setSize(300,300);
      setVisible(true);
   
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
}
 
public static void main(String[] args)
    {
 
new ass6b1();
 
    }

}

/*

Output-



*/


No comments:

Post a Comment