?
Solved

An example of a marquee in an applet?

Posted on 2001-06-29
8
Medium Priority
?
1,534 Views
Last Modified: 2013-11-23
Hello,

I would like to display a scrolling "Welcome" marquee in an applet - how do you make one of these marquees using multithreading?  Can anyone give me an example please.

I'd really appreciate all the help.
0
Comment
Question by:bita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Accepted Solution

by:
ahosang earned 200 total points
ID: 6239270
Just a basic example:
import java.awt.*;
import java.applet.Applet;

public class Welcome extends java.applet.Applet implements Runnable {
   
   Font f = new Font("Arial Black", Font.BOLD, 24);
   Color col = new Color(204,153,0);
   Color back = new Color(249,249,249);
   String wel = new String("WELCOME TO MY SITE");
   Thread runner;
   int x;
   int stringSize;
   
   public void init() {
      setForeground(col);
      setBackground(back);
       setFont(f);
       FontMetrics fm=getFontMetrics(f);
       stringSize=fm.stringWidth(wel);
   }

   public void start() {
      if (runner == null) {
         runner = new Thread(this);
         runner.start();
      }
   }

   public void stop() {
      if (runner != null) {
         runner = null;
      }
   }

   public void run() {
      Thread thisThread = Thread.currentThread();
      x = 10-stringSize;
      int cont = size().width;
      while (runner == thisThread) {
         x = x + 2;
         repaint();
         try {
            Thread.sleep(20);
         } catch (InterruptedException e) { }
         if (x > cont) x = -stringSize;
      }
   }

   public void paint(Graphics screen) {
     
      screen.drawString(wel, x, 25);
   }
}
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6239298
There are also hundreds of examples of these (some really flash/complex) at http://javaboutique.internet.com/text/horiz.html. Many of these will have full source code with them.
0
 

Author Comment

by:bita
ID: 6240191
hi ahosang,

Thank you for your example.  I tried to compile this code on the JDK1.2 but there was an error:

"Note:Welcome.java uses or overrides a deprecated API.  Recompile with "-deprecation" for details.
1 warning"

Can you tell me what this means and how to resolve this error please. Thanks again.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:ozymandias
ID: 6240384
That is not an error.
It is a warning.
A deprecated method is a method that had been flagged for future removal from the API.

In this instance it is the method size() used in this line :

    int cont = size().width;

This method has been flagged as deprecated because it has been replaced by the method getSize(). You can use either but the compiler is warning you that it is better to use the newer method because eventually the old one will be removed and your code won't work. The size() method in this case has been deprecated since JDK 1.1, so that's quite a long time.

To correct the code change the line so it reads :
   
    int cont = getSize().width;

and all will be well.

0
 

Author Comment

by:bita
ID: 6240429
Hello ozymandias ,

Thank you for your quick reply to the message about the warning.  I recompiled the program and yes, all is now well.
-----------------------
Thanks to both ahosang and yourself , I now have a clear idea about scrolling text in an applet!

bita
0
 

Author Comment

by:bita
ID: 6240430
Hello ozymandias ,

Thank you for your reply to the message about the warning.  I recompiled the program and yes, all is now well.
-----------------------
Thanks to both ahosang and yourself , I now have a clear idea about scrolling text in an applet!

bita
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6240658
Glad I could help :0)
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950454


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  points to ahosang


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question