/*
* Created on 2005-7-22
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FibonacciTest extends JApplet implements ActionListener {
public void init()
{
Container c = getContentPane();
c.setLayout( new FlowLayout());
numLabel = new JLabel ( " Enter integer and press Enter" );
c.add(numLabel);
num = new JTextField ( 10 );
num.addActionListener( this );
c.add( num );
resultLabel = new JLabel ( "Fibonacci Value is" );
c.add(resultLabel);
result = new JTextField ( 15 );
result.setEditable( false );
c.add ( result );
}
public void actionPerformed ( ActionEvent e )
{
long number, fibonacciValue;
number = Long.parseLong(num.getText());
showStatus( "Calculating...");
fibonacciValue = fibonacci( number );
showStatus( "done.");
result.setText( Long.toString(fibonacciValue));
}
public long fibonacci (long n)
{
if( n == 0 || n == 1 )
return n;
else
return fibonacci( n - 1 ) + fibonacci( n - 2 );