Stop thread in java

***********************************************
COMPLETE SOURCE CODE FOR : StopThread.java
***********************************************


import javax.swing.JOptionPane;

public class StopThread implements Runnable
{
int currentValue=0;

public void run()
{
while(true)
{
JOptionPane.showMessageDialog(null,"currentValue = "+currentValue);

String temp=JOptionPane.showInputDialog(null,"CHOOSE 1 OR 2\n1-Continue Thread\n2-Stop Thread");

if(temp.equals("2"))
{
JOptionPane.showMessageDialog(null,"Thread Stop, Bye");
return;//This will make thread stop
}
else if(temp.equals("1"))
{
currentValue=currentValue+1;
JOptionPane.showMessageDialog(null,"Please stop me, i'm tired\ncurrentValue will add one");
}
else
{
JOptionPane.showMessageDialog(null,"I don't know your input");
}
}
}

public static void main(String[]args)
{
//Create a thread by create StopThread object
StopThread a=new StopThread();

//run thread
a.run();
}
}


***********************************************
JUST COMPILE AND EXECUTE IT
***********************************************

Create thread in java

Create thread in java

COMPLETE SOURCE CODE FOR CreateThread.java


public class CreateThread implements Runnable
{
//all thread implementation will be put in run method
public void run()
{
//Print hi
System.out.println("HI");
}

public static void main(String[]args)
{
//Create thread by create CreateThread object
CreateThread a=new CreateThread();

//run the thread
a.run();
}
}


JUST COMPILE AND EXECUTE IT