/*
 * Created on 17-oct-2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Hogar
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */


import java.awt.*;
import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;



public class appletSum extends Applet implements ActionListener{
	public Button set=new Button("Calcular");
	public TextField n=new TextField(8);
	public TextArea inst= new TextArea(1,30);
	public Label time=new Label(" ");
	public Panel sur=new Panel(new BorderLayout());	
	public Label intro=new Label("Factores de la solución a las sumatorias de potencias, con Gauss-Jordan de baja presición:");
	public Label nl=new Label("Ingrese la potencia de la sumatoria, (i^n):");
	public SumPow pow;
	
	public void init() {
		set.setActionCommand("boton");
   		set.addActionListener(this);
   
    
    	sur.add(time,BorderLayout.NORTH);
    	sur.add(inst,BorderLayout.SOUTH);
	
		this.setLayout(new BorderLayout());
	
		add(intro,BorderLayout.NORTH);
		add(nl,BorderLayout.WEST);
    	add(n,BorderLayout.CENTER);
    	add(set,BorderLayout.EAST);
    	add(sur,BorderLayout.SOUTH);
    	this.resize(1000,100);
	}

	public void actionPerformed(ActionEvent e) {
		if ("boton".equals(e.getActionCommand()))
		{		
	    String ene=(n.getText());	
		int enint=(int)(java.lang.Integer.parseInt(ene));
		pow=new SumPow(enint);	
		
		
		time.setText("Sumatoria de i^"+ enint +" ");
		double[] aux=pow.x;
		String res=" ";
		for(int i=1;i<=pow.n;i++){
			if(i==1){
				res=res.concat("("+aux[i-1]+")n^"+i+" ");	
			}else{
				res=res.concat("+ ("+aux[i-1]+")n^"+i+" ");		
			}
		
		}	
		inst.setText("= "+res+" ");
		
		}
			
		
	}
	
		
	public void paint(Graphics g) {
		g.drawString("Welcome to Java!!", 50, 60 );
	}
}
