Solved

Flashing Text In Java Applet

Posted on 2004-03-29
9
822 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
MySQL  on Tomcat 8 70
Desingning Refactoring existing code 2 26
Why doesn't this text field show up on my Applet frame? 2 20
Crystal Reports Licensing Questions 4 37
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

830 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