create an applet to display the Fibonacci numbers
1)AppletExample.java:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class AppletExample extends Applet implements ActionListener{
TextField text;
TextArea area;
Label label1,label2;
Button button;
public void init(){
setLayout(null);
label1 = new Label("How many numbers do you want in Series: ");
label1.setBounds(20,20,250,20);
add(label1);
text=new TextField(20);
text.setBounds(300,20,100,20);
add(text);
label2 = new Label("Fibonacci Series: ");
label2.setBounds(20,50,250,20);
add(label2);
area=new TextArea(5,15);
area.setBounds(300,50,100,80);
add(area);
button = new Button("Find");
button.setBounds(300,140,100,20);
add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
StringBuffer buffer=new StringBuffer();
int num = Integer.parseInt(text.getText());
int f1=0,f2=0,f3=1;
for(int i=1;i<=num;i++){
buffer.append(f3);
buffer.append("\n");
f1=f2;
f2=f3;
f3=f1+f2;
}
area.setText(buffer.toString());
}
}
2)applet.html:
<HTML> <BODY> <APPLET ALIGN="CENTER" CODE="AppletExample.class" width = "700" height = "400"></APPLET> </BODY> </HTML>