Results 1 to 4 of 4
- 05-05-2009, 03:11 PM #1
How can I get this to work properly -animation issue with an applet.
I need someone to tell me what to write in the while(true) statement in order to have this animation working?
Java Code:import java.awt.*; import java.util.*; public class RemainingTime extends java.applet.Applet implements Runnable { Font f = new Font("TimesNewRoman", Font.BOLD,21); Date datum; int theDate; int year; int month; int day; String dd; String hr; Thread runner; int theHours; int theMinutes; int theSeconds; public int subTotal; int remainingDays; public void start() { if (runner == null); { runner = new Thread(this); runner.start(); } } public void run() { dd = getParameter("datum"); //får värdet i "datum" från htlm filen StringTokenizer tokens1, tokens2; tokens1 = new StringTokenizer(dd, "/"); //Tokenizing stringen med / som avgränsare. year = Integer.parseInt(tokens1.nextToken()); //konvert varje token till integer. month = Integer.parseInt(tokens1.nextToken()); day = Integer.parseInt(tokens1.nextToken()); hr = getParameter("time"); //får ett värde (i "time") från htlm filen tokens2 = new StringTokenizer(hr, ":"); int hours = Integer.parseInt(tokens2.nextToken()); int minutes = Integer.parseInt(tokens2.nextToken()); int seconds = Integer.parseInt(tokens2.nextToken()); GregorianCalendar now = new GregorianCalendar(); int thisMonth = now.get(now.MONTH); int thisDay = now.get(now.DAY_OF_MONTH); int countDays = 0; for (int i = thisMonth+1; i <= 12; i++) { subTotal += countDays; ///////////////////////////////////////////////////////// switch (month){ case 1: //jan case 3: //mars case 5: //maj case 7: //juli case 8: //aug case 10: //okt case 12: //dec countDays = 31; break; case 2: // feb 2009 countDays = 28; break; case 4: //apr case 6: //juni case 9: //sept case 11: //nov countDays = 30; break; } } remainingDays = subTotal + thisDay; int thisHour = now.get(now.HOUR); int thisMinute = now.get(now.MINUTE); int thisSecond = now.get(now.SECOND); int timeInSec = (thisHour*60*60) + (thisMinute*60) + thisSecond; int finish = (hours*60*60) + (minutes*60) + seconds; int totalRemSec; if (timeInSec > finish) totalRemSec = 86400 - timeInSec + finish; else totalRemSec = finish - timeInSec; int totalMin = totalRemSec / 60; theHours = totalMin / 60; theMinutes = totalMin % 60; theSeconds = totalRemSec % 60; Thread thisThread = Thread.currentThread(); while (runner == thisThread) { while(true){ repaint(); try {Thread.sleep(1000);} catch(InterruptedException e) {} } } } public void paint(Graphics s) { s.setFont(f); s.drawString("Remaining time to year 2010:", 5, 25); s.drawString((String.valueOf(remainingDays)), 5, 50); s.drawString("days", 50, 50); s.drawString((String.valueOf(theHours)), 5, 75); s.drawString("hours", 50, 75); s.drawString((String.valueOf(theMinutes)), 5, 100); s.drawString("minutes", 50, 100); s.drawString((String.valueOf(theSeconds)), 5, 125); s.drawString("seconds", 50, 125); } }
information from the HTML fileXML Code:<HTML> <HEAD> <TITLE>Remaining time to year 2010 </TITLE> </HEAD> <BODY> <APPLET CODE = "RemainingTime.class" WIDTH=400 HEIGHT=300> <PARAM NAME= datum VALUE="2009/12/31"> <PARAM NAME= time VALUE="24:00:00"> </APPLET> </BODY> </HTML>
- 05-05-2009, 07:08 PM #2
Nothing. Use a SwingTimer to control animations. The setup can be done in init(), rather than making it Runnable. You can parse a whole date at once using DateFormat.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-05-2009, 08:14 PM #3
but how to do that? I´m very new to Java and this is actually my first applet by myself. Thanks
- 05-06-2009, 12:11 AM #4
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Similar Threads
-
Animation Applet
By Unome in forum Java AppletsReplies: 7Last Post: 10-17-2008, 07:34 AM -
Eclipse Documentation does not work properly.
By krawetko in forum EclipseReplies: 0Last Post: 10-05-2008, 10:06 AM -
Applet Vs JApplet ?? which is better for animation?
By Mba7eth in forum New To JavaReplies: 3Last Post: 09-09-2008, 04:55 PM -
Will this applet ever work?
By willemjav in forum Java AppletsReplies: 4Last Post: 04-20-2008, 05:40 PM -
why doesn't this short applet work?
By kim85 in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks