Solved

An example of a marquee in an applet?

Posted on 2001-06-29
8
1,493 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 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
Industry Leaders: 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

691 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