Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Simple method program

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This program simply checks to see when each method is executed. However, when I run it in an AppletViewer my applet displays absolutely nothing. Could anyone provide any suggetions? I've provided both files below. Thank you for your help.
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LifeCycle extends Applet implements ActionListener
{
/*Declares the names of six methods that execute during
the full lifetime of the applet. Declares a button "pressButton."
Declares six integers that hold the number of occurences of each
of the six methods.*/
Font buttonFont = new Font("TimesRoman", Font.ITALIC,12);
Label messageInit = new Label("init ");
Label messageStart = new Label("start ");
Label messageDisplay = new Label("display ");
Label messageAction = new Label("action ");
Label messageStop = new Label("stop ");
Label messageDestroy = new Label("destroy");
Button pressButton = new Button("Press");
int countInit, countStart, countDisplay,
countAction, countStop, countDestroy;

/*The Init() method adds one to countInit, places
all components within the applet and calls
the display() method.*/

public void Init()
{
++countInit;
add(messageInit);
add(messageStart);
add(messageDisplay);
add(messageAction);
add(messageStop);
add(messageDestroy);
add(pressButton);
pressButton.setFont(buttonFont);
pressButton.addActionListener(this);
display();
}
//The Start() method adds one to countStart and calls the display method.

public void start()
{
++countStart;
display();
}

/*The diplay method adds one to countDisplay and displays the name of
each of the six methods with the current count and indicates how
many times the method has executed.*/

public void display()
{
++countDisplay;
messageInit.setText("Init " + countInit);
messageStart.setText("Start " + countStart);
messageDisplay.setText("display " + countDisplay);
messageAction.setText("action " + countAction);
messageStop.setText("stop " + countStop);
messageDestroy.setText("destroy " + countDestroy);
}

/*The stop() and destroy() methods each add one to the appropriate
counter and call the display() method.*/

public void stop()
{
++countStop;
display();
}
public void destroy()
{
++countDestroy;
display();
}

/*When the user clicks the button "pressButton", the following
actionPerformed() method executes. It adds one to countAction
and displays it.*/

public void actionPerformed(ActionEvent e)
{
++countAction;
display();
}
}
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears my HTML file was not included. I'll post it here.
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if this forum does not like you to copy and paste.
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you are unable to use the enter key between lines. Here at last is the HTML file. <HTML> <APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200> </APPLET> </HTML>
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I give up trying to send the HTML file. Sorry.
 
Keith Gottschalk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just found the typo. My init() method was keyed Init().
 
    Bookmark Topic Watch Topic
  • New Topic