Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: (Timer?) Problems

  1. #1
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default (Timer?) Problems

    Hey, I'm one section away from finishing up my short Java class and the teacher finally decided to throw a tough assignment at us for the first time in awhile. I've partially guessed as to what to do so any pointers would help.

    I'm writing a small applet that will display a string, slowly move it halfway down the page and then off the screen to the right. We also need to use an array to hold the strings since the latest unit was on arrays. My idea was to find out some way to call a method to change the X/Y coords and a few other things every second and then repaint the string so that it would appear to move.

    I'm fairly sure that the idea will work but I've been having a bit of trouble finding the proper way to call a method every second. A few of the links I checked out on google all had, seemingly, different ways of doing it so I wasn't sure which one to use so I just examined one of them and attempted to figure out how it works so that I could use it in my program. If anyone can point out (but not fix for me) my mess-ups in the code it would be very helpful.

    Code:
    import java.applet.Applet;
    import java.awt.*;
     
    public class AssignmentJ13PartFour extends Applet implements Runnable
    {
    	String [] stringArray = new String[5]; //Creates a string array. NOTE: The rows and columns must be 1 number higher than you will use.
     
     
    	int xPos = 150; //Used to manipulate the X coords of the displayed string.
    	int yPos = -10; //Used to manipulate the Y coords of the displayed string.
    	int tempVariable = 0; //Controls which string in the array will be used.
    	int tempVariable2 = 0; //Controls the text color.
    	boolean tempBoolean = false; //If false then the string won't move on the X axis, if true then it won't move on the Y axis.
     
    	Thread threadRunner;
     
    	public void main()
    	{
    		stringArray[0] = "Kiseki No Umi";
    		stringArray[1] = "Suffocated";
    		stringArray[2] = "Neon Pegasus";
    		stringArray[3] = "Happy Little Clouds";
    		stringArray[4] = "Garden of Your Mind";
    	}
     
    	public void paint(Graphics gr)
    	{
    		if (tempVariable2 == 0)
    			gr.setColor(Color.black);
    		else if (tempVariable2 == 1)
    			gr.setColor(Color.red);
    		else if (tempVariable2 == 2)
    			gr.setColor(Color.green);
    		else if (tempVariable2 == 3)
    			gr.setColor(Color.blue);
    		else if (tempVariable2 == 4)
    			gr.setColor(Color.yellow);
     
            gr.drawString(stringArray[tempVariable], xPos, yPos); //What the string says, X coords, Y Coords.
    	}
     
    	public void start() //Starts the thread. NOTE: Must be named start.
    	{
    		if(threadRunner == null)
    		{
    			threadRunner = new Thread(this);
    			threadRunner.start();
    		}
    	}
     
    	public void run() //NOTE: Must be named run or an error occurs upon compiling.
    	{
    		while(true)
    		{
    			if (tempBoolean == false)
    				yPos = (yPos - 10);
    			else
    				xPos = (xPos + 10);
     
    			if (xPos >= 400) //When the song title reaches this far off screen spot then this will change the string being displayed and the color in preparation for the next string, it also re-sets the X and Y coord variables.
    			{
    				tempVariable ++;
    				tempVariable2 ++;
    				xPos = 150;
    				yPos = -10;
    			}
     
    			if ( (tempVariable == 5) && (tempVariable == 5) )
    			{
    				tempVariable = 0;
    				tempVariable2 = 0;
    				xPos = 150;
    				yPos = -10;
    			}
     
    			repaint();
    			try {threadRunner.sleep(1000);}
    			catch (InterruptedException e) {}
    		}
    	}
    }

    Html Page:
    <html>
     <body>
     <applet code = "AssignmentJ13PartFour.class" width=300 height=300>
     </applet>
     </body>
     </html>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: (Timer?) Problems

    my mess-ups in the code
    What happens when you compile and execute the code?
    If there are any errors copy the full text of the message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: (Timer?) Problems

    There are no errors when compiling. When I test the applet all you see is the blank webpage.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: (Timer?) Problems

    Check to see if there are execution time errors. If using a browser, look in the browser's java console.
    Or use the appletviewer program in a command prompt window.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: (Timer?) Problems

    I'm using Google Chrome, would that be the same as right clicking the page and checking out the page source or inspecting the elements?
    (We've barley done anything with applets in the class so I'm used to using the cmd for everything.)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: (Timer?) Problems

    No, the java console is controlled by the Java Icon in the Control Panel.
    Try using the appletviewer program that comes with the jdk.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    tyeeeee1 (December 10th, 2012)

  8. #7
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: (Timer?) Problems

    After using "appletviewer -debug AssignmentJ13PartFour.java" the following appeared in the cmd:

    Initializing jdb...

    *I typed 'run'*

    run sun.applet.Main AssignmentJ13Partfour.java
    Set uncaught java.lang.Throwable
    Set deferred uncaught java.lang.Throwable

    VM Started:
    The application exited.


    What I got from that, I think, is that I should do something different with the main method other than just setting my array strings. I figured that it would just set them right away and then the thread would start and the rest of the program would work, I'll assume I was wrong?

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: (Timer?) Problems

    The appletviewer should read the <applet tag to start executing an applet program. Pass it the html file for input.

    do something different with the main method
    Take a look at the tutorial:
    http://docs.oracle.com/javase/tutori...let/index.html

    The main() method is not used in applets.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: (Timer?) Problems

    Here is what my console said after I had the applet open for a few seconds, I only understood the first line of the error which leads me to think that the applet is skipping the main method and trying to run the rest of the applet without having any filled strings to use.

    C:\Users\EditedOut\Desktop\j2sdk1.4.2_19\bin>appletviewer AssignmentJ13Partfour.html
     
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at sun.awt.RepaintArea.paint(RepaintArea.java:177)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at sun.awt.RepaintArea.paint(RepaintArea.java:177)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException: string is null
            at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2521)
            at AssignmentJ13PartFour.paint(AssignmentJ13PartFour.java:49)
            at java.awt.Container.update(Container.java:1333)
            at sun.awt.RepaintArea.paint(RepaintArea.java:169)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3678)
            at java.awt.Container.dispatchEventImpl(Container.java:1627)
            at java.awt.Component.dispatchEvent(Component.java:3477)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:201)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:151)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
     
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
     
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
     
    C:\Users\Tyler\Desktop\j2sdk1.4.2_19\bin>

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: (Timer?) Problems

    the applet is skipping the main method
    See my last post. The main() method is not used by applets. Read the tutorial at the link in my post to see what methods are used by applets.


    You can give values to an array when you define it:
    String[] anArry = {"ad","asda"};
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    tyeeeee1 (December 10th, 2012)

  13. #11
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: (Timer?) Problems

    Thank's for the tutorial link, I'll go through it and see what I can learn.

    --- Update ---

    Edit: I managed to get it working and finish the assignment after a bit more googling and a lot of trial/error. Thanks a lot for the help Norm.

    Just in case anyone found this page while googling for something here is the code that I ended up with.

    import java.applet.Applet;
    import java.awt.*;
     
    public class AssignmentJ13PartFour extends Applet implements Runnable
    {
    	String [] stringArray = new String[5]; //Creates a string array. NOTE: The rows and columns must be 1 number higher than you will use.
     
     
    	int xPos = 150; //Used to manipulate the X coords of the displayed string.
    	int yPos = -10; //Used to manipulate the Y coords of the displayed string.
    	int tempVariable = 0; //Controls which string in the array will be used.
    	int tempVariable2 = 0; //Controls the text color.
    	boolean tempBoolean = false; //If false then the string won't move on the X axis, if true then it won't move on the Y axis.
     
    	Thread threadRunner;
     
    	public void init()
    	{
    		setBackground(Color.black);
     
    		stringArray[0] = "Kiseki No Umi";
    		stringArray[1] = "Suffocated";
    		stringArray[2] = "Neon Pegasus";
    		stringArray[3] = "Happy Little Clouds";
    		stringArray[4] = "Garden of Your Mind";
    	}
     
    	public void paint(Graphics gr)
    	{
    		System.out.println("Test!");
    		if (tempVariable2 == 0)
    			gr.setColor(Color.white);
    		else if (tempVariable2 == 1)
    			gr.setColor(Color.red);
    		else if (tempVariable2 == 2)
    			gr.setColor(Color.green);
    		else if (tempVariable2 == 3)
    			gr.setColor(Color.blue);
    		else if (tempVariable2 == 4)
    			gr.setColor(Color.yellow);
     
    		gr.clearRect(0, 0, getWidth(), getHeight());
            gr.drawString(stringArray[tempVariable], xPos, yPos); //What the string says, X coords, Y Coords.
    	}
     
    	public void start() //Starts the thread. NOTE: Must be named start.
    	{
    		if(threadRunner == null)
    		{
    			threadRunner = new Thread(this);
    			threadRunner.start();
    		}
    	}
     
    	public void run() //NOTE: Must be named run or an error occurs upon compiling.
    	{
    		while(true)
    		{
    			if (tempBoolean == false)
    				yPos = (yPos + 10);
    			else
    				xPos = (xPos + 10);
     
    			System.out.println("xPos is: "+xPos+" and yPos is:"+yPos+"");
    			if (xPos >= 400) //When the song title reaches this far off screen spot then this will change the string being displayed and the color in preparation for the next string, it also re-sets the X and Y coord variables.
    			{
    				tempVariable ++;
    				tempVariable2 ++;
    				xPos = 150;
    				yPos = -10;
    				tempBoolean = false;
    			}
     
    			if (yPos == 150) //When the string reaches the yPos of 150 then the direction changes and it moves to the right.
    				tempBoolean = true;
     
     
    			if ( (tempVariable == 5) && (tempVariable == 5) ) //Resets everything so the applet can seemlessly re-play forever.
    			{
    				tempVariable = 0;
    				tempVariable2 = 0;
    				xPos = 150;
    				yPos = -10;
    			}
     
    			repaint(); //Calls the paint() method, this is the ONLY way to do it as far as I know atm.
    			try {threadRunner.sleep(100);}
    			catch (InterruptedException e) {}
    		}
    	}
    }

Similar Threads

  1. game timer
    By powder in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2012, 09:15 AM
  2. Timer.schedule
    By johnboyofsj in forum Java Theory & Questions
    Replies: 1
    Last Post: October 14th, 2012, 10:02 PM
  3. Updating timer
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 26th, 2011, 06:02 AM
  4. need help with Timer and sound
    By amahara in forum AWT / Java Swing
    Replies: 4
    Last Post: February 18th, 2010, 11:22 AM
  5. Timer?
    By TimW in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 27th, 2009, 07:43 AM