Solved

An example of a marquee in an applet?

Posted on 2001-06-29
8
1,283 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 65
egit plugin on eclipse 8 28
MySQL  on Tomcat 8 23
MySqlDump not dumping triggers 1 13
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

930 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

10 Experts available now in Live!

Get 1:1 Help Now