Solved

Flashing Text In Java Applet

Posted on 2004-03-29
9
753 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

746 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

13 Experts available now in Live!

Get 1:1 Help Now