aspose file tools
The moose likes Beginning Java and the fly likes Simple method program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Simple method program" Watch "Simple method program" New topic
Author

Simple method program

Keith Gottschalk
Greenhorn

Joined: Jul 28, 2000
Posts: 8
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

Joined: Jul 28, 2000
Posts: 8
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

Joined: Jul 28, 2000
Posts: 8
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
Keith Gottschalk
Greenhorn

Joined: Jul 28, 2000
Posts: 8
<HTML>
<APPLET CODE = "LifeCycle.class" WIDTH = 450 HEIGHT = 200>
</APPLET>
</HTML>
Keith Gottschalk
Greenhorn

Joined: Jul 28, 2000
Posts: 8
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

Joined: Jul 28, 2000
Posts: 8
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

Joined: Jul 28, 2000
Posts: 8
I give up trying to send the HTML file. Sorry.
Keith Gottschalk
Greenhorn

Joined: Jul 28, 2000
Posts: 8
I've just found the typo. My init() method was keyed Init().
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Simple method program
 
Similar Threads
JMenuBar on the move
grid bag panels overlap : please HELP if you can
Applet not displaying icon
Need help with applet
Creating an application (can be hosted on LAN)