Solved

Flashing Text In Java Applet

Posted on 2004-03-29
9
780 Views
Last Modified: 2013-12-29
Hi everyone,

I want to have flashing text in a chat room applet I have written.  I want the text to flash when the last person in the room speaks.  Can anyone think of any Ideas or examples??

Thanks in advance


Garth
0
Comment
Question by:garth15
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10703252
Use a Swing Timer, if using Swing and turn the text on and off on timer fired.
0
 

Author Comment

by:garth15
ID: 10703303
I am not using Swing as I want to make sure the applet compiles in Java 1.1 so more people can access the applet.  Any other ideas?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10703348
It's a little difficult to advise without knowing more about the gui, but the principle would be to send a message to each client applet to start a timer that 'turns on' and off the text. I must say this would annoy the hell out of me if i were using it ;-)
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10703349
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Draw extends JFrame implements ActionListener
{
      private JLabel label ;

      public Draw()
      {
            super();

            initialize();
      }

      private void initialize()
      {
            JPanel panel = (JPanel) getContentPane();
            panel.setLayout(new FlowLayout());

            label = new JLabel ("Welcome");
            panel.add(label);
            
            new MyTimerTask().start();
            
            setSize(500, 500);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
      
      class MyTimerTask extends Thread
      {
            public MyTimerTask()
            {
                  setDaemon(true);
            }
            
            public void run()
            {
                  while (true)
                  {
                        try
                        {
                              Thread.sleep(500);
                        }
                        catch (InterruptedException e)
                        {
                        }
                        
                        if (label.getText().length() > 0)
                              label.setText("");
                        else
                              label.setText("Welcome");
                  }
            }
      }
      
      public void actionPerformed(ActionEvent e)
      {
      }

      public static void main(String[] args)
      {
            new Draw();
      }
}
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.

 
LVL 37

Expert Comment

by:zzynx
ID: 10703359
mmuruganandam, he's not using swing he said.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10703370
Just take off the swing components and use the AWT.   It will work.
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 500 total points
ID: 10703390
AWT implementation

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Draw extends Frame implements ActionListener
{
      private Label label ;

      public Draw()
      {
            super();

            initialize();
      }

      private void initialize()
      {
            Panel p = new Panel();
            p.setLayout(new FlowLayout());

            label = new Label ("Welcome");
            p.add(label);
            
            add(p);
            
            new MyTimerTask().start();
            
            setSize(500, 500);
            setVisible(true);
      }
      
      class MyTimerTask extends Thread
      {
            public MyTimerTask()
            {
                  setDaemon(true);
            }
            
            public void run()
            {
                  while (true)
                  {
                        try
                        {
                              Thread.sleep(500);
                        }
                        catch (InterruptedException e)
                        {
                        }
                        
                        if (label.getText().length() > 0)
                              label.setText("");
                        else
                              label.setText("Welcome");
                  }
            }
      }
      
      public void actionPerformed(ActionEvent e)
      {
      }

      public static void main(String[] args)
      {
            new Draw();
      }
}
0
 
LVL 3

Expert Comment

by:JavaInTheMorning
ID: 10703436
Pseudo code:
if last person in the room then:
   while true:
        turn off text
        sleep for a sec
        turn on text

(Seperate thread)
Itsik
0
 
LVL 3

Expert Comment

by:JavaInTheMorning
ID: 10703441
if last person in the room then:
   while true:
        turn off text
        sleep for a sec
        turn on text
        sleep for a sec

Sorry
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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …

910 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

22 Experts available now in Live!

Get 1:1 Help Now