Results 1 to 8 of 8

Thread: applet problem

  1. #1

    Thread Starter
    Junior Member lemenz70's Avatar
    Join Date
    Apr 2005
    Location
    Canada (Quebec)
    Posts
    23

    applet problem

    Hi!
    I'm very new to applets and I made an applet directly from another project that I had. When I start the applet in JBuilder everything works fine but when I start it with internet explorer i can click on my button but nothing works... i hope someone can help me it may be some refresh thing or something like that.

    My applet

    Thanks for help
    Last edited by lemenz70; Apr 28th, 2005 at 11:03 PM.
    William

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: applet problem

    You'll need to change some of the architecture of the program. You might have to use a Thread instead of timer...That way, you could already have the component added to the container at runtime instead of only when the buttons clicked. Then, when the button is clicked, start the thread.

  3. #3

    Thread Starter
    Junior Member lemenz70's Avatar
    Join Date
    Apr 2005
    Location
    Canada (Quebec)
    Posts
    23

    Re: applet problem

    thanks I'll try with a thread.
    William

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: applet problem (solved)

    Did you see the one I made with a thread? It's in the same thread(forum thread!) as Andy's, but mine scrolls horizontal.

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: applet problem (solved)

    So how'd you fix it?

  6. #6

    Thread Starter
    Junior Member lemenz70's Avatar
    Join Date
    Apr 2005
    Location
    Canada (Quebec)
    Posts
    23

    Re: applet problem (solved)

    here is your code

    Code:
    public void run()
    {
        	/*  we start a while loop, that will loop will it is true, and since 
        	 *  nothing ever makes it false it never stops.  So no matter how long the 
        	 *  program is run, it will always be going.
        	 */
        	while (true)
        	{
        		/*  Since we are working with threads, we must put our operations in a try
        		 *  catch clause so that we can trap errors that will possibly arise.
        		 */
         	   try
          	  {        
          	  		/*  get the old text, which is just the text on the JLabel at this
          	  		 *  moment.  We will need this later.
          	  		 */        
          	      	String oldText = adLabel.getText();
          	      	/*  create a new String, that will perform some operations on the old text
          	      	 *  and then set the text of the JLabel to the new text.  The first part of this
          	      	 *  (substring(0)), takes one parameter, this parameter is the starting index of the
          	      	 *  string, and then grabs everything else.  Again, index's start at index 0, so this 
          	      	 *  is cutting the string off by one.  So, if the text is "text", then the first part 
          	      	 *  cuts it down to "ext".  Then you have the concatenating operater(+) that adds text
          	      	 *  to the preceding string.  The third part, oldText.substring(0,1), has two parameters,
          	      	 *  the beginning index, and the ending index.  We specify 0, and 1.  This basicly means it
          	      	 *  grabs the first character of the old text.  So, if we had "text", as the label, then it 
          	      	 *  would get the "t" out of text since it is the first letter.  Then that is added to the\
          	      	 *  first operation(where we got "ext"....This ends up putting the text as "extt", but of course 
          	      	 *  if you had spaces after the message, it would be much clearer("ext  t", then "xt   te", then
          	      	 *  "t  tex", and last "    text", and it would loop from there.
          	      	 */
    				StringBuffer newText = StringBuffer.append(oldText.substring(1) + oldText.substring(0, 1));
    				
    				//set the text of the label to the new text
    				adLabel.setText(newText);
    
    			  /*  The thread class has a method called sleep().  This method will pause the thread for a given
    			   *  amount of time in milliseconds.  We specify 250, but this can be changed.  You put the time 
    			   *  in milliseconds as the parameter for the method.
    			   */
              	  Thread.sleep(250);
    
               }
              		/*  If you use a thread, you must catch the interrupted exception.  This exception
              		 *  will occur if the thread is interrputed in anyway, hence the name interrupted
              		 *  exception.  If this exception occurs, we don't want to continue.
              		 */
                 	catch (InterruptedException e)
           		{
           		      /*  Since we don't want to continue if this exception occurs, we make a call to
           		       *  the stop method.  This wll stop the thread all together.
           		       */
               	      stop();
            	}
           }
    I can't make it run in my applet because of this:
    StringBuffer newText = StringBuffer.append(oldText.substring(1) + oldText.substring(0, 1));

    for some reason it makes an error...
    William

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: applet problem (solved)

    What was the error?

    I did this on a label, so that could be your problem. You must have the text on a label, or else you'll have to change a few lines.

  8. #8

    Thread Starter
    Junior Member lemenz70's Avatar
    Join Date
    Apr 2005
    Location
    Canada (Quebec)
    Posts
    23

    Re: applet problem (solved)

    I added a label called adLabel but the problem comes from the append on the substring... it can't be done this way and maybe when I try to modify it I change it's effect in the applet and nothing works.
    William

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width