:? A duvida é a seguinte, como eu faço para disparar uma função em modo background ? explicando melhor …
eu chamar uma função que contenha o trecho:
try{
for(int i=0;i<5;i++){ // faz de conta que sao 60 segundos ...
Thread.sleep(1000);
}
} catch(Exception e){
}
sem que ela trave o programa impedindo de eu fica realizando ações (quero que ela seja executa por exemplo enquanto meu botão esteja LIGADO).
segue um programinha básico para entender melhor a ideia:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class guj extends JFrame implements WindowListener, ActionListener{
private static final long serialVersionUID = 1L;
JPanel painel = new JPanel();
JButton botao = new JButton("INICIAR");
public guj(){
this.setLayout(null);
this.setTitle("Eventos Duplos - guj");
this.setResizable(false);
this.setSize(400,300);
this.addWindowListener(this);
this.add(this.painel);
this.painel.setBounds(3,3,389,269);
this.painel.setBackground(new Color(210,210,210));
this.botao.setBackground(new Color(175,10,10));
this.painel.add(this.botao);
this.botao.setBounds(300,200,50,30);
this.botao.addActionListener(this);
this.setVisible(true);
}
public static void main(String args[]){
new guj();
}
@Override
public void actionPerformed(ActionEvent o) {
Object object = o.getSource(); // SEM CAST
if(o.getSource().equals(botao)){
if(((JButton) object).getBackground().toString().equals("java.awt.Color[r=175,g=10,b=10]")){
((JButton) object).setBackground(new Color(0,185,0));
((JButton) object).setText("PARAR");
} else {
((JButton) object).setBackground(new Color(175,10,10));
((JButton) object).setText("INICIAR");
}
}
iniciarContagem();
}
public void iniciarContagem(){
try{
for(int i=0;i<5;i++){ // faz de conta que sao 60 segundos ...
Thread.sleep(1000);
}
JOptionPane.showMessageDialog(null, "60 segundos");
} catch(Exception e){
}
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
To aceitando qualquer tipo de ideia, sugestão, ou aonde procurar, ou até mesmo dicas sobre aonde ler 
obrigado!


