Black Rose
An unbreakable bond
I am trying to make java program with a start button to begin a thread. The problem is that I need the thread to stop inside the run method because when I press the start button twice it gives me an error message. I also need to draw numbers from a loop in the thread onto the JFrame with paint. I pass the numbers with variable (i) into paint. The number should change with every repaint. I am not sure what I am doing wrong in my code. If someone could check it out I would be grateful. 

Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication5;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.event.*;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Jeremy
*/
class MyClass implements Runnable {
public void run (){
for(int i=0; i<10; i++){
repaint(i);
System.out.println("Error value: " + i);
}
requestStop();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void requestStop() {
Thread.interrupted();
}
}
public class JavaApplication5 extends JPanel{
/**
* @param args the command line arguments
*/
int i = 0;
public void paint(Graphics g) {
int i = 0;
g.drawString("Watch the number change:" + i , 50, 50);
}
public static void main(String[] args) {
JPanel p = new JPanel(new GridBagLayout());
JTextField jt = new JTextField(20);
JButton b = new JButton("number");
JFrame f = new JFrame("Recurrent Neural Net");
f.add(new JavaApplication5());
f.setSize((516), (539));
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.add(b);
p.add(jt);
f.add(p);
Thread t = new Thread(new MyClass());
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
t.start();
}
});
}
}