Solved

An example of a marquee in an applet?

Posted on 2001-06-29
8
1,211 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
8 Comments
 
LVL 12

Accepted Solution

by:
ahosang earned 50 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now