Link to home
Start Free TrialLog in
Avatar of garth15
garth15

asked on

Flashing Text In Java Applet

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a Swing Timer, if using Swing and turn the text on and off on timer fired.
Avatar of garth15
garth15

ASKER

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?
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 ;-)
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();
      }
}
mmuruganandam, he's not using swing he said.
Just take off the swing components and use the AWT.   It will work.
ASKER CERTIFIED SOLUTION
Avatar of mmuruganandam
mmuruganandam
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pseudo code:
if last person in the room then:
   while true:
        turn off text
        sleep for a sec
        turn on text

(Seperate thread)
Itsik
if last person in the room then:
   while true:
        turn off text
        sleep for a sec
        turn on text
        sleep for a sec

Sorry