Bom dia
Antes de postar tentei localizar alguma dúvida parecida. Encontrei algumas coisas parecidas, ate tentei realizar os procedimentos descritos pelos colegas porém sem sucesso.
Minha dúvida é a seguinte.
Criei um pequeno aplicativo que com um loop infinito para executar arquivo .bat, porém quando clico no botão INICIAR, este fica pressionado e trava o aplciativo, o BAT executa como eu planejei. Tentei usar Threads mas não obtive sucesso, se alguém puder me ajudar fico agradecido.
public class Tela extends Thread{
private JButton btInicia = new JButton("INICIAR");
private JButton btPara = new JButton("PARAR");
private JLabel jlTexto = new JLabel("SISTEMA EM STANDBY");
private JPanel painel1 = new JPanel(new BorderLayout());
private JFrame tela = new JFrame("Vigilante1.0");
public Tela(){
btInicia.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jlTexto.setText("SISTEMA ATIVO");
try{
while (0==0){
Runtime.getRuntime().exec("c://teste.bat");
Thread.sleep(20000);
}
}catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
painel1.add(btInicia, BorderLayout.SOUTH);
painel1.add(btPara);
painel1.add(jlTexto, BorderLayout.NORTH);
tela.add(painel1);
tela.setSize(200, 200);
tela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tela.setVisible(true);
}