Results 1 to 4 of 4
Thread: strange code
- 12-22-2008, 09:15 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
strange code
well not really strange, but but it is when I got up to speed faster with C/C++
Java Code:import java.applet.*; import java.awt.*; import java.util.Date; import java.text.DateFormat; /** An Applet to display the current time */ public class TimeDate extends Applet implements Runnable { /** A Thread to run the timer */ protected Thread timerThread; /** The date object */ Date date = new Date(); /** The date format */ protected DateFormat format = DateFormat.getTimeInstance(); /* Applet Lifestyle Methods */ public void start() { timerThread = new Thread(this, "Clock"); timerThread.start(); } public void stop() { if (timerThread == null) return; timerThread = null; } /** Show the time, and wait a while. */ public void run() { while (timerThread != null) { repaint(); // request a redraw try { timerThread.sleep(1000); } catch (InterruptedException e) { /* do nothing*/ } } } // end of run() /** Display the time. */ public void paint(Graphics g) { Font type = new Font("Monospaced", Font.BOLD, 30); g.setFont(type); int test =5/2; date.setTime(System.currentTimeMillis()); g.drawString(format.format(date), 10, 100); } } // end of TimeDate class
In this code
start() stop() run() and paint() functions never seem to be called up yet the code runs OK
-
The methods (this being Java requires that there are no "functions", just methods) will be called behind the scenes by the JVM.
- 12-22-2008, 11:46 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
Thank you Fubarable for mentioning the JVM now it is clear.
I remember reading something about it in my text book (I have misplaced at the moment)
But I found this via google at sun web site
Life Cycle of an Applet: Basically, there are four methods in the Applet class on which any applet is built.
# init: This method is intended for whatever initialization is needed for your applet. It is called after the param attributes of the applet tag.
# start: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages.
# stop: This method is automatically called whenever the user moves away from the page containing applets. You can use this method to stop an animation.
# destroy: This method is only called when the browser shuts down normally.
- 12-22-2008, 11:51 PM #4
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
AffinedTransform strange behaviour
By Echilon in forum AWT / SwingReplies: 3Last Post: 12-11-2008, 09:58 AM -
strange Error message
By little_polarbear in forum New To JavaReplies: 4Last Post: 08-25-2008, 11:45 PM -
Strange problem
By Tamir in forum EclipseReplies: 1Last Post: 08-18-2008, 09:44 PM -
What is the answer to this strange problem:
By willemjav in forum New To JavaReplies: 5Last Post: 08-11-2008, 09:31 PM -
Strange behaviour in swing
By cbalu in forum AWT / SwingReplies: 1Last Post: 05-23-2008, 09:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks