Solved

Flashing Text In Java Applet

Posted on 2004-03-29
9
859 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
[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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 82
hibernate example for saving data 19 107
Java string replace 11 74
ejb wildfly example 2 106
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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

738 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