Forum : Thread
Brief description  about Online courses   join in Online courses
View Ravi  Srivastava 's Profile

Thread

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SingleThread extends JApplet implements Runnable,ActionListener
{
JButton btnStart;
static String message[]={"Java","is","very","interesting"};
static Thread messThread1;
static JTextArea taMessage;
static boolean Thread1Alive=true;
static JLabel lblName;

public void init()
{
getContentPane().setLayout(null);
lblName=new JLabel();
lblName.setBounds(125,10,250,25);
getContentPane().add(lblName);

Font font=new Font("COMIC SANS SERIF",Font.BOLD,18);
lblName.setFont(font);

taMessage=new JTextArea();
taMessage.setBounds(115,50,270,120);

getContentPane().add(taMessage);

btnStart=new JButton("Start");
btnStart.setBounds(210,180,80,30);
getContentPane().add(btnStart);
btnStart.addActionListener(this);
}

//stop method of the Applet
public void stop()
{
if(messThread1.isAlive())
{
messThread1.stop();
messThread1=null;
}
}

public void run()
{
Data.print(Thread.currentThread().getName(),message);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnStart)
{
taMessage.setText(" ");
messThread1=new Thread(this,"first");
messThread1.start();
}
}
}

class Data
{
public static void print(String name,String list[])
{
SingleThread.taMessage.append("\n");
for(int i=0;i<list.length;i )
{
SingleThread.lblName.setText((Thread.currentThread()).getName() "thread is executing.");
SingleThread.taMessage.append(list[i] " ");
try
{
Thread.sleep((long)(1000 * Math.random()));
}
catch(InterruptedException ie)
{
System.out.println("Interruputed Exception..");
}
System.out.println("the current thread is " (Thread.currentThread()).getName() " " list[i]);
}
}
}

/* <applet code = "SingleThread.class" width="500" height="250">
</applet>*/


well in the above program there is a compilation error like--
"SingleThread.java uses or overrides a deprecated API.
Recompile with -XLint: deprecation for details."
Asked by Ravi Srivastava | Mar 1, 2010 |  Reply now
Replies (1)
View arun kumar das 's Profile
Hi Ravi,

I guess you have got this piece of code from internet or from a very old source. Let me explain what the above error really means:

There are a lot of methods that were defined in Java when it was first introduced. As and when newer versions of java were introduced lot of old methods were made to retire and were replaced with better methods. We get deprecation errors or warnings when we use old phased out methods in our programs instead of new ones which are supported by the latest Java versions.

Regards...
Mar 1, 2010