Friday, 24 January 2014

Write a program to make Calculator in User Interface

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

public class calc extends Applet
{
    Button[] b = new Button[16];
    TextField t = new TextField(20);
    Panel p = new Panel();
    String[] lbl= {"1","2","3","+","4","5","6","-","7","8","9","*","CE","0","/","="};
    public void init()
    {
        setLayout(new BorderLayout());
        add(t, BorderLayout.NORTH);
        
        p.setLayout(new GridLayout(4,4));
        for(int i=0;i<=15;i++)
        {
            b[i] = new Button(lbl[i]);
            p.add(b[i]);  
        }
        add(p, BorderLayout.CENTER);
        
    } 
}


/*<applet code="calc" width="200" height="400"></applet>*/


OUTPUT



















0 comments:

Post a Comment

Followers