Olá, preciso que o meu botão start a minha thread, porém não esta dando certo rsrs
segue o codigo
Tela
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
public class TelaTrabalho extends JFrame implements ActionListener{
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TelaTrabalho frame = new TelaTrabalho();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public TelaTrabalho() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JButton btn = new JButton("Ok");
btn.addActionListener(verificaArquivo.start());
Codigo
[code]
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Codigo extends Thread {
public void run(){
while(true)
leArquivo();
}
Thread verificaArquivo = new Thread();
public void leArquivo() {
long tamanhoArquivo;
File diretorio = new File("C:\\Teste");
File arquivo = new File(diretorio, "Nomes.txt");
try {
InputStream is = new FileInputStream(arquivo);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
tamanhoArquivo=arquivo.length();
String s = br.readLine(); // primeira linha
while (s != null) {
System.out.println(s);
s = br.readLine();
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
[/code]