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

public class  sumA extends JApplet implements ActionListener
{ 
  JLabel label1;
  JTextField namebox;
  JPanel inputPanel;
  JTextArea t;
  int n;

 
  public void init()
  {    
	label1=new JLabel("enter maximum number for the summation ");
	t=new JTextArea(" ");
	t.setFont(new Font("Serif",Font.BOLD,24));
	namebox=new JTextField("100");	
    setLayout(new BorderLayout());
    inputPanel=new JPanel();
    inputPanel.add(label1);
    inputPanel.add(namebox);
    add(inputPanel,BorderLayout.NORTH);
    add(t,BorderLayout.CENTER);
    namebox.addActionListener(this);
  }
  
  public double sum(int n)
  {double tt=0;
   for(int i=0;i<=n;i++) {tt+=i;}
   return tt;	  
  }

public void actionPerformed( ActionEvent e)
{
	 if(e.getSource()==namebox)
        {   n=Integer.parseInt(namebox.getText());
	        t.setText("sum of numbers from 1 to"+n+" is "+sum(n)); }
}

    public static void main(String s[])
    {
        JFrame f = new JFrame("summation of numbers between 1 to n Applet Graphic");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JApplet applet = new sumA();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.setSize(800,500);
        f.setVisible(true); 
    }  
}
