Write a Multithreading program using Runnable interface to blink Text on the frame.

import java.awt.*;
import java.awt.event.*;
public class BlinkText extends Frame implements Runnable
{
            Thread t;
            Label l1;
            int f;
            public BlinkText()
            {
                        t=new Thread(this);
                        t.start();
                        setLayout(null);
                        l1=new Label("Hello JAVA");
                        l1.setBounds(100,100,100,40);
                        add(l1);
                        setSize(300,300);
                        setVisible(true);
                        f=0;
            }
            public void run()
            {
                        try
                        {
                                    if(f==0)
                                    {
                                                t.sleep(200);
                                                l1.setText("");
                                                f=1;
                                    }
                                    if(f==1)
                                    {
                                                t.sleep(200);
                                                l1.setText("Hello Java");
                                                f=0;
                                    }
                        }catch(Exception e)
                        {
                                    System.out.println(e);
                        }
                        run();
            }
            public static void main(String args[])
            {
                        new BlinkText();
            }
}

Comments

Popular posts from this blog

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)