A
Allan Bruce
Hi there,
I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?
Thanks
Allan
/*
* FibonacciTest.java
*
* Created on 10 November 2003, 11:16
*/
/**
*
* @author abruce
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FibonacciTest extends JApplet implements ActionListener
{
JLabel numberLabel, resultLabel, timeLabel;
JTextField numberField, resultField, timeField;
public void init() // set up the GUI
{
// obtain content pane and set its layout to FlowLayout
Container container = getContentPane();
container.setLayout(new FlowLayout());
// create numberLabel and attach it to content pane
numberLabel = new JLabel("Enter an integer and press Enter");
container.add(numberField);
// create numberField and attach it to content pane
numberField = new JTextField(10);
container.add(numberField);
// register this applet as numberFields ActioNListener
numberField.addActionListener(this);
// create resultLabel and attach it to conmetnt pane
resultLabel = new JLabel("Fibbonaci value is");
container.add(resultLabel);
// create timeLabel and attach it to content pane
timeLabel = new JLabel("Time taken was: ");
container.add(timeLabel);
// create numberField, make it uneditable and attach to content pane
resultField = new JTextField(15);
resultField.setEditable(false);
container.add(resultField);
} // end init
public void actionPerformed(ActionEvent e)
{
long number, fibonacciValue;
// obtain users input and convert to long
number = Long.parseLong(numberField.getText());
showStatus("Calculating");
// calculate fibonacci value for number from user input
fibonacciValue = fibonacci(number);
showStatus("Done");
resultField.setText(Long.toString(fibonacciValue));
} // end actionPerformed
// recursive fibonacci
public long fibonacci(long n)
{
// base case
if (n==0 || n==1)
return n;
else
return fibonacci(n-1) + fibonacci(n-1);
} // end fibonacci
} // end FibonacciTest
--
Allan Bruce
Dept. of Computing Science
University of Aberdeen
Aberdeen AB24 3UE
Scotland, UK
I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?
Thanks
Allan
/*
* FibonacciTest.java
*
* Created on 10 November 2003, 11:16
*/
/**
*
* @author abruce
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FibonacciTest extends JApplet implements ActionListener
{
JLabel numberLabel, resultLabel, timeLabel;
JTextField numberField, resultField, timeField;
public void init() // set up the GUI
{
// obtain content pane and set its layout to FlowLayout
Container container = getContentPane();
container.setLayout(new FlowLayout());
// create numberLabel and attach it to content pane
numberLabel = new JLabel("Enter an integer and press Enter");
container.add(numberField);
// create numberField and attach it to content pane
numberField = new JTextField(10);
container.add(numberField);
// register this applet as numberFields ActioNListener
numberField.addActionListener(this);
// create resultLabel and attach it to conmetnt pane
resultLabel = new JLabel("Fibbonaci value is");
container.add(resultLabel);
// create timeLabel and attach it to content pane
timeLabel = new JLabel("Time taken was: ");
container.add(timeLabel);
// create numberField, make it uneditable and attach to content pane
resultField = new JTextField(15);
resultField.setEditable(false);
container.add(resultField);
} // end init
public void actionPerformed(ActionEvent e)
{
long number, fibonacciValue;
// obtain users input and convert to long
number = Long.parseLong(numberField.getText());
showStatus("Calculating");
// calculate fibonacci value for number from user input
fibonacciValue = fibonacci(number);
showStatus("Done");
resultField.setText(Long.toString(fibonacciValue));
} // end actionPerformed
// recursive fibonacci
public long fibonacci(long n)
{
// base case
if (n==0 || n==1)
return n;
else
return fibonacci(n-1) + fibonacci(n-1);
} // end fibonacci
} // end FibonacciTest
--
Allan Bruce
Dept. of Computing Science
University of Aberdeen
Aberdeen AB24 3UE
Scotland, UK