Problema em piscar botão

21 respostas
jonsistemas

Meu pseudocódigo é o seguinte:

Botão começa em uma cor (vermelho por exemplo)

Função começa:
Muda o botão para um vermelho mais fraco
espera meio segundo
Muda o botão para o vermelho original
Fim de função

public void Pisca() 
{       
    	try 
        {                   
            jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
            Thread.sleep( 500 );  //Pausa a tela por meio segundo
            jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
        }   
        catch (InterruptedException ie) 
    	{   
            return;   
        }   
     }

Só que de alguma forma, o que está acontecendo é o seguinte:
Muda a cor para vermelho claro, no mesmo instante como se fosse paralelo muda para o botão vermelho, e só depois espera o tempo.

Fiz teste tirando a linha que volta para o vermelho original, e dá certo, isto é, muda a cor, só que fica na cor clara pra sempre.

21 Respostas

Luiz_Augusto_Prado

jonsistemas:
Meu pseudocódigo é o seguinte:

Botão começa em uma cor (vermelho por exemplo)

Função começa:
Muda o botão para um vermelho mais fraco
espera meio segundo
Muda o botão para o vermelho original
Fim de função

public void Pisca() 
{       
    	try 
        {                   
            jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
            Thread.sleep( 500 );  //Pausa a tela por meio segundo
            jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
        }   
        catch (InterruptedException ie) 
    	{   
            return;   
        }   
     }

Só que de alguma forma, o que está acontecendo é o seguinte:
Muda a cor para vermelho claro, no mesmo instante como se fosse paralelo muda para o botão vermelho, e só depois espera o tempo.

Fiz teste tirando a linha que volta para o vermelho original, e dá certo, isto é, muda a cor, só que fica na cor clara pra sempre.

cadê o main do seu programa? Como tá fazendo o layout? na mão?
primeiro eu tentaria entender como funciona a lib que pretende usar. No caso a lib que está utilizando é a swing?
já faz um tempo que to vendo alguém fazendo a mesma pergunta… “como usar frame?”
Se vc quer ajuda, posta o fonte sobre sua dúvida de forma mais completa.
O que tem feito?

jonsistemas

Luiz Augusto Prado:
jonsistemas:
Meu pseudocódigo é o seguinte:

Botão começa em uma cor (vermelho por exemplo)

Função começa:
Muda o botão para um vermelho mais fraco
espera meio segundo
Muda o botão para o vermelho original
Fim de função

public void Pisca() 
{       
    	try 
        {                   
            jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
            Thread.sleep( 500 );  //Pausa a tela por meio segundo
            jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
        }   
        catch (InterruptedException ie) 
    	{   
            return;   
        }   
     }

Só que de alguma forma, o que está acontecendo é o seguinte:
Muda a cor para vermelho claro, no mesmo instante como se fosse paralelo muda para o botão vermelho, e só depois espera o tempo.

Fiz teste tirando a linha que volta para o vermelho original, e dá certo, isto é, muda a cor, só que fica na cor clara pra sempre.

cadê o main do seu programa? Como tá fazendo o layout? na mão?
primeiro eu tentaria entender como funciona a lib que pretende usar. No caso a lib que está utilizando é a swing?
já faz um tempo que to vendo alguém fazendo a mesma pergunta… “como usar frame?”
Se vc quer ajuda, posta o fonte sobre sua dúvida de forma mais completa.
O que tem feito?

Comecei usando a interface grafica que o NetBeans tem, usando JFrame, só que depois passei editar o codigo na mão mesmo utilizando o eclipse, eu tenho que fazer um botão piscar para implementar o jogo Genius, primeiramente eu so queria fazer ele piscar, para depois usar as estruturas de dados e fazer o que realmente deve ser feito, só que nem piscar eu to conseguindo fazer, o código ta um pouco extenso, tem muita coisa desnecessária que veio da interface do NetBeans.

import java.awt.Color;




import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JOptionPane;

//import java.util.Stack;


/*
 * 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.
 */
/**
 *
 * @author Jonathas
 */
public class NewJFrame extends javax.swing.JFrame implements Jogo1
{    
    
	
	//private static final long serialVersionUID = 1L;
	
	  
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public NewJFrame() 
    {
        
        initComponents();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    public void initComponents() 
    {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jRadioButton5 = new javax.swing.JRadioButton("Tamanho 8",true);
        jRadioButton6 = new javax.swing.JRadioButton("Tamanho 14",false);
        jRadioButton7 = new javax.swing.JRadioButton("Tamanho 20",false);
        jRadioButton8 = new javax.swing.JRadioButton("Tamanho 31:",false);
        
        radioGroup = new ButtonGroup();
        radioGroup.add(jRadioButton5);
        radioGroup.add(jRadioButton6);
        radioGroup.add(jRadioButton7);
        radioGroup.add(jRadioButton8);
        
        

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));
        setPreferredSize(new java.awt.Dimension(600, 600));

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setForeground(new java.awt.Color(51, 255, 0));
        jPanel1.setPreferredSize(new java.awt.Dimension(600, 600));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 300));

        jLabel1.setForeground(new java.awt.Color(204, 204, 255));
        jLabel1.setText("jLabel1");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel1MouseExited(evt);
            }
        });

        jLabel2.setBackground(new java.awt.Color(0, 51, 255));
        jLabel2.setForeground(new java.awt.Color(204, 204, 255));
        jLabel2.setText("jLabel2");
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel2MousePressed(evt);
            }
        });

        jButton1.setBackground(Color.RED);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton1MousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton1MouseReleased(evt);
            }
        });
       
        
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(0, 0, 255));

        jButton3.setBackground(new java.awt.Color(255, 255, 0));

        jButton4.setBackground(new java.awt.Color(0, 255, 0));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText("Tipo de jogo:");

        jButton5.setText("1");
        jButton5.setToolTipText("Repita a sequencia");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton5MousePressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel4.setText("Selecione o nivel de dificuldade:");

        jButton6.setText("2");
        jButton6.setToolTipText("Crie sua propria sequencia");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton6MousePressed(evt);
            }
        });

        jButton7.setText("3");
        jButton7.setToolTipText("Repita a sequencia, porém apertando um unico botão");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton7MousePressed(evt);
            }
        });

        
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        
        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });

        
        jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton7ActionPerformed(evt);
            }
        });
        
        jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton8ActionPerformed(evt);
            }
        });

        

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5)
                    .addComponent(jButton6)
                    .addComponent(jButton7)
                    .addComponent(jLabel3)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(120, 120, 120)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jRadioButton5)
                                        .addGap(24, 24, 24)
                                        .addComponent(jRadioButton6))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jRadioButton7)
                                        .addGap(18, 18, 18)
                                        .addComponent(jRadioButton8)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(226, 226, 226)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButton5)
                        .addComponent(jRadioButton6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton6)
                            .addComponent(jRadioButton7)
                            .addComponent(jRadioButton8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)))
                .addGap(32, 32, 32))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }//fim de init                    

    private void jLabel1MouseExited(java.awt.event.MouseEvent evt) 
    {                                    
        //jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        //jLabel1.setForeground(new java.awt.Color(204, 204, 204));
        //jButton1.setVisible(true);
        //jButton2.setVisible(true);
        //jButton3.setVisible(true);
        //jButton4.setVisible(true);
        
    }                                   

    public void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {                                     
        jPanel2.setBackground(Color.black);
        jLabel1.setForeground(Color.black);
        jLabel2.setForeground(Color.black);
        jButton1.setVisible(false);
        jButton2.setVisible(false);
        jButton3.setVisible(false);
        jButton4.setVisible(false);
        jButton5.setVisible(false);
        jButton6.setVisible(false);
        jButton7.setVisible(false);
        jRadioButton5.setVisible(false);
        jRadioButton6.setVisible(false);
        jRadioButton7.setVisible(false);
        jRadioButton8.setVisible(false);
        
    }                                    

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                     
        
    }                                    

    public void jLabel2MousePressed(java.awt.event.MouseEvent evt) {                                     
        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jLabel1.setForeground(new java.awt.Color(204, 204, 255));
        jLabel2.setForeground(new java.awt.Color(204, 204, 255));
        jButton1.setVisible(true);
        jButton2.setVisible(true);
        jButton3.setVisible(true);
        jButton4.setVisible(true);
        jButton5.setVisible(true);
        jButton6.setVisible(true);
        jButton7.setVisible(true);
        jRadioButton5.setVisible(true);
        jRadioButton6.setVisible(true);
        jRadioButton7.setVisible(true);
        jRadioButton8.setVisible(true);
    }                                    

    public void jButton1MousePressed(java.awt.event.MouseEvent evt) 
    {
   
    	jButton1.setBackground( Color.black);
        
    }                                     

    public void jButton1MouseReleased(java.awt.event.MouseEvent evt) {                                       
        jButton1.setBackground( new Color( 255, 0, 0 ) ); //vermelho normal  
    }
    
    public void jButton5MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
    		//JOptionPane.showMessageDialog(null, "Voce selecionou sequencia com tamanho 8");
    		//comecaJogo1T(8);
    		Pisca();
    		//Pisca2();
    		
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 14");
    		//jogo1.setTamanho(14);
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 20");
    	//	jogo1.setTamanho(8);
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 31");
    	}
    		
    }
  //  private void jogo1(int i) {
	//	// TODO Auto-generated method stub
		
//	}

	private void jButton6MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
    		
            JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 8");
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 14");
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 20");
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 31");
    	}
    }    
    private void jButton7MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
            JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 8");
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 14");
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 20");
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 31");
    	}
    }    
    
    

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             
    private void jRadioButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }
   // private void alteraJogo1(int t)
    //{
    	
    //}
    

    
    /**
     * @param args the command line arguments
     */
   
    static Thread t = Thread.currentThread( );
    private ButtonGroup radioGroup;
    // Variables declaration - do not modify                     
    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    public javax.swing.JButton jButton6;
    public javax.swing.JButton jButton7;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel3;
    public javax.swing.JLabel jLabel4;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JPanel jPanel2;
    public javax.swing.JRadioButton jRadioButton5;
    public javax.swing.JRadioButton jRadioButton6;
    public javax.swing.JRadioButton jRadioButton7;
    public javax.swing.JRadioButton jRadioButton8;
	
    //public Jogo1 jogo1;
    // End of variables declaration
       
    public void Pisca() 
    {       
        	try 
            {                   
                jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
                Thread.sleep( 500 );  //Pausa a tela por meio segundo
                jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
            }   
            catch (InterruptedException ie) 
        	{   
                return;   
            }   
     }
       
    @Override
	public void comecaJogo1T(int t)  // vou usar a variavel t mais a frente
	{
		
		Pisca();
     
	}



}

Main :

public class Teste
{
	public static void main(String args[]) 
    {
		
		//Jogo1 jogo1 = new Jogo1(12);
		try 
		{
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) 
            {
                if ("Nimbus".equals(info.getName())) 
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
    
		NewJFrame frame = new NewJFrame();
        frame.setVisible(true);
        frame.setResizable(false);                    
     
    }
}
Luiz_Augusto_Prado
jonsistemas:
Luiz Augusto Prado:
jonsistemas:
Meu pseudocódigo é o seguinte:

Botão começa em uma cor (vermelho por exemplo)

Função começa:
Muda o botão para um vermelho mais fraco
espera meio segundo
Muda o botão para o vermelho original
Fim de função

public void Pisca() 
{       
    	try 
        {                   
            jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
            Thread.sleep( 500 );  //Pausa a tela por meio segundo
            jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
        }   
        catch (InterruptedException ie) 
    	{   
            return;   
        }   
     }
Só que de alguma forma, o que está acontecendo é o seguinte: Muda a cor para vermelho claro, no mesmo instante como se fosse paralelo muda para o botão vermelho, e só depois espera o tempo.

Fiz teste tirando a linha que volta para o vermelho original, e dá certo, isto é, muda a cor, só que fica na cor clara pra sempre.

cadê o main do seu programa? Como tá fazendo o layout? na mão?
primeiro eu tentaria entender como funciona a lib que pretende usar. No caso a lib que está utilizando é a swing?
já faz um tempo que to vendo alguém fazendo a mesma pergunta... "como usar frame?"
Se vc quer ajuda, posta o fonte sobre sua dúvida de forma mais completa.
O que tem feito?

Comecei usando a interface grafica que o NetBeans tem, usando JFrame, só que depois passei editar o codigo na mão mesmo utilizando o eclipse, eu tenho que fazer um botão piscar para implementar o jogo Genius, primeiramente eu so queria fazer ele piscar, para depois usar as estruturas de dados e fazer o que realmente deve ser feito, só que nem piscar eu to conseguindo fazer, o código ta um pouco extenso, tem muita coisa desnecessária que veio da interface do NetBeans.

import java.awt.Color;




import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JOptionPane;

//import java.util.Stack;


/*
 * 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.
 */
/**
 *
 * @author Jonathas
 */
public class NewJFrame extends javax.swing.JFrame implements Jogo1
{    
    
	
	//private static final long serialVersionUID = 1L;
	
	  
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public NewJFrame() 
    {
        
        initComponents();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    public void initComponents() 
    {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jRadioButton5 = new javax.swing.JRadioButton("Tamanho 8",true);
        jRadioButton6 = new javax.swing.JRadioButton("Tamanho 14",false);
        jRadioButton7 = new javax.swing.JRadioButton("Tamanho 20",false);
        jRadioButton8 = new javax.swing.JRadioButton("Tamanho 31:",false);
        
        radioGroup = new ButtonGroup();
        radioGroup.add(jRadioButton5);
        radioGroup.add(jRadioButton6);
        radioGroup.add(jRadioButton7);
        radioGroup.add(jRadioButton8);
        
        

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));
        setPreferredSize(new java.awt.Dimension(600, 600));

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setForeground(new java.awt.Color(51, 255, 0));
        jPanel1.setPreferredSize(new java.awt.Dimension(600, 600));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 300));

        jLabel1.setForeground(new java.awt.Color(204, 204, 255));
        jLabel1.setText("jLabel1");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel1MouseExited(evt);
            }
        });

        jLabel2.setBackground(new java.awt.Color(0, 51, 255));
        jLabel2.setForeground(new java.awt.Color(204, 204, 255));
        jLabel2.setText("jLabel2");
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel2MousePressed(evt);
            }
        });

        jButton1.setBackground(Color.RED);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton1MousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton1MouseReleased(evt);
            }
        });
       
        
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(0, 0, 255));

        jButton3.setBackground(new java.awt.Color(255, 255, 0));

        jButton4.setBackground(new java.awt.Color(0, 255, 0));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText("Tipo de jogo:");

        jButton5.setText("1");
        jButton5.setToolTipText("Repita a sequencia");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton5MousePressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel4.setText("Selecione o nivel de dificuldade:");

        jButton6.setText("2");
        jButton6.setToolTipText("Crie sua propria sequencia");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton6MousePressed(evt);
            }
        });

        jButton7.setText("3");
        jButton7.setToolTipText("Repita a sequencia, porém apertando um unico botão");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton7MousePressed(evt);
            }
        });

        
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        
        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });

        
        jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton7ActionPerformed(evt);
            }
        });
        
        jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton8ActionPerformed(evt);
            }
        });

        

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5)
                    .addComponent(jButton6)
                    .addComponent(jButton7)
                    .addComponent(jLabel3)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(120, 120, 120)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jRadioButton5)
                                        .addGap(24, 24, 24)
                                        .addComponent(jRadioButton6))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jRadioButton7)
                                        .addGap(18, 18, 18)
                                        .addComponent(jRadioButton8)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(226, 226, 226)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButton5)
                        .addComponent(jRadioButton6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton6)
                            .addComponent(jRadioButton7)
                            .addComponent(jRadioButton8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)))
                .addGap(32, 32, 32))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }//fim de init                    

    private void jLabel1MouseExited(java.awt.event.MouseEvent evt) 
    {                                    
        //jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        //jLabel1.setForeground(new java.awt.Color(204, 204, 204));
        //jButton1.setVisible(true);
        //jButton2.setVisible(true);
        //jButton3.setVisible(true);
        //jButton4.setVisible(true);
        
    }                                   

    public void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {                                     
        jPanel2.setBackground(Color.black);
        jLabel1.setForeground(Color.black);
        jLabel2.setForeground(Color.black);
        jButton1.setVisible(false);
        jButton2.setVisible(false);
        jButton3.setVisible(false);
        jButton4.setVisible(false);
        jButton5.setVisible(false);
        jButton6.setVisible(false);
        jButton7.setVisible(false);
        jRadioButton5.setVisible(false);
        jRadioButton6.setVisible(false);
        jRadioButton7.setVisible(false);
        jRadioButton8.setVisible(false);
        
    }                                    

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                     
        
    }                                    

    public void jLabel2MousePressed(java.awt.event.MouseEvent evt) {                                     
        jPanel2.setBackground(new java.awt.Color(204, 204, 255));
        jLabel1.setForeground(new java.awt.Color(204, 204, 255));
        jLabel2.setForeground(new java.awt.Color(204, 204, 255));
        jButton1.setVisible(true);
        jButton2.setVisible(true);
        jButton3.setVisible(true);
        jButton4.setVisible(true);
        jButton5.setVisible(true);
        jButton6.setVisible(true);
        jButton7.setVisible(true);
        jRadioButton5.setVisible(true);
        jRadioButton6.setVisible(true);
        jRadioButton7.setVisible(true);
        jRadioButton8.setVisible(true);
    }                                    

    public void jButton1MousePressed(java.awt.event.MouseEvent evt) 
    {
   
    	jButton1.setBackground( Color.black);
        
    }                                     

    public void jButton1MouseReleased(java.awt.event.MouseEvent evt) {                                       
        jButton1.setBackground( new Color( 255, 0, 0 ) ); //vermelho normal  
    }
    
    public void jButton5MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
    		//JOptionPane.showMessageDialog(null, "Voce selecionou sequencia com tamanho 8");
    		//comecaJogo1T(8);
    		Pisca();
    		//Pisca2();
    		
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 14");
    		//jogo1.setTamanho(14);
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 20");
    	//	jogo1.setTamanho(8);
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 31");
    	}
    		
    }
  //  private void jogo1(int i) {
	//	// TODO Auto-generated method stub
		
//	}

	private void jButton6MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
    		
            JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 8");
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 14");
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 20");
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 31");
    	}
    }    
    private void jButton7MousePressed(java.awt.event.MouseEvent evt) 
    {
    	if(jRadioButton5.isSelected()==true)
        {
            JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 8");
        }
    	else if((jRadioButton6.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 14");
    	}
    	else if((jRadioButton7.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 20");
    	}
    	else if((jRadioButton8.isSelected()==true))
    	{
    		JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 31");
    	}
    }    
    
    

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }                                             
    private void jRadioButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
    }
   // private void alteraJogo1(int t)
    //{
    	
    //}
    

    
    /**
     * @param args the command line arguments
     */
   
    static Thread t = Thread.currentThread( );
    private ButtonGroup radioGroup;
    // Variables declaration - do not modify                     
    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    public javax.swing.JButton jButton6;
    public javax.swing.JButton jButton7;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel3;
    public javax.swing.JLabel jLabel4;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JPanel jPanel2;
    public javax.swing.JRadioButton jRadioButton5;
    public javax.swing.JRadioButton jRadioButton6;
    public javax.swing.JRadioButton jRadioButton7;
    public javax.swing.JRadioButton jRadioButton8;
	
    //public Jogo1 jogo1;
    // End of variables declaration
       
    public void Pisca() 
    {       
        	try 
            {                   
                jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro    
                Thread.sleep( 500 );  //Pausa a tela por meio segundo
                jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original        
            }   
            catch (InterruptedException ie) 
        	{   
                return;   
            }   
     }
       
    @Override
	public void comecaJogo1T(int t)  // vou usar a variavel t mais a frente
	{
		
		Pisca();
     
	}



}

Main :

public class Teste
{
	public static void main(String args[]) 
    {
		
		//Jogo1 jogo1 = new Jogo1(12);
		try 
		{
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) 
            {
                if ("Nimbus".equals(info.getName())) 
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
    
		NewJFrame frame = new NewJFrame();
        frame.setVisible(true);
        frame.setResizable(false);                    
     
    }
}

tenta focar na sua dúvida. vc postou um codigo enorme. ninguem vai te ajudar neste forum a fazer nada. Vai lhe ajudar a entender mas pra que o pessoal se anime pra isso, tem que focar na dúvida.

O lance é que o JButton, tem vários eventos por tras dele quando clica. Pode ver que quando vc pressiona o botão do tipo JButton, ele fica cinza. Neste caso o melhor é utilizar um Button da lib java.awt. Exemplo incluindo o foco apenas na sua dúvida:
import javax.swing.*;
import java.awt.Button;
import java.awt.Color;
import java.awt.event.ActionEvent;

class Main
{
    Button btn;

    private Main()
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                JFrame jframe = new JFrame();
                jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                btn = new Button("teste");
                btn.setBackground(new Color( 0, 255,  0));
                jframe.getContentPane().add(btn);
                
                btn.addActionListener(new java.awt.event.ActionListener()
                { 
                    @Override
                    public void actionPerformed(ActionEvent ae)
                    { 
                        btn.setBackground(new Color(255, 0, 0)); 
                        try
                        {
                            Thread.sleep(1500);  //Pausa a tela por meio segundo   
                        }
                        catch (InterruptedException ie)
                        {
                        }
                        btn.setBackground(new Color(0, 255, 0));
                    }
                });
                jframe.setVisible(true);
            }
        });
    }

    public static void main(String args[])
    {
        new Main();
    }
}
jonsistemas

[quote=Luiz Augusto Prado][quote=jonsistemas][quote=Luiz Augusto Prado]

jonsistemas:
Meu pseudocódigo é o seguinte:

tenta focar na sua dúvida. vc postou um codigo enorme. ninguem vai te ajudar neste forum a fazer nada. Vai lhe ajudar a entender mas pra que o pessoal se anime pra isso, tem que focar na dúvida.

O lance é que o JButton, tem vários eventos por tras dele quando clica. Pode ver que quando vc pressiona o botão do tipo JButton, ele fica cinza. Neste caso o melhor é utilizar um Button da lib java.awt. Exemplo incluindo o foco apenas na sua dúvida:
import javax.swing.*;
import java.awt.Button;
import java.awt.Color;
import java.awt.event.ActionEvent;

class Main
{
    Button btn;

    private Main()
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                JFrame jframe = new JFrame();
                jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                btn = new Button("teste");
                btn.setBackground(new Color( 0, 255,  0));
                jframe.getContentPane().add(btn);
                
                btn.addActionListener(new java.awt.event.ActionListener()
                { 
                    @Override
                    public void actionPerformed(ActionEvent ae)
                    { 
                        btn.setBackground(new Color(255, 0, 0)); 
                        try
                        {
                            Thread.sleep(1500);  //Pausa a tela por meio segundo   
                        }
                        catch (InterruptedException ie)
                        {
                        }
                        btn.setBackground(new Color(0, 255, 0));
                    }
                });
                jframe.setVisible(true);
            }
        });
    }

    public static void main(String args[])
    {
        new Main();
    }
}

Obrigado cara, indiretamente voce me ajudou a fazer a função que precisava, não sei o que acontece por dentro ainda, com total entendimento, mas o metodo run e esse invoke later era o que faltava, no final o método a função ficou assim:

public void  piscaVermelho()  
    {  
    	java.awt.EventQueue.invokeLater(new Runnable()  
        {  
    		public void run()  
    		{   
    			jButton1.setBackground(Color.black);
                jButton5.addActionListener(new java.awt.event.ActionListener()  
                {   
                    public void actionPerformed(ActionEvent ae)  
                    {      
                    	try  
                        {  
                            Thread.sleep(500);  //Pausa a tela por meio segundo     
                        }  
                        catch (InterruptedException ie)  
                        {
                        	
                        }  
                        jButton1.setBackground(Color.red);   
                     }  
                    });    
             }  
        });  
    }
jonsistemas

Na verdade o metodo final ficou assim rs

public void  piscaVermelho()  
	 {  
			jButton1.setBackground(Color.black);
	    	java.awt.EventQueue.invokeLater(new Runnable()  
	        {  	    		
	    		public void run()  
	    		{   
	                try  
	                {  
	                	Thread.sleep(500);  //Pausa a tela por meio segundo     
	                }  
	                catch (InterruptedException ie)  
	                {
	                        	
	                }  
	                  jButton1.setBackground(Color.red);   
	              }  
	        });  
	 }
jonsistemas

Achei que estava resolvido mas não está, quando coloco o codigo:

piscaVermelho() ;

dá certo, e o botão vermelho é piscado, mas quando coloco por exemplo:

piscaVermelho()  ;

piscaVermelho()  ;

piscaVermelho()  ;

ou

piscaVermelho()  ;

piscaVerde();

piscaAmarelo();

ou qualquer trecho de codigo que contenha mais de um comando seguido desse tipo o que acontece é que
todos os botões piscam ao mesmo tempo, como se não respeitasse o tempo de cada instrução, e executam em paralelo sei lá, alguem sabe de alguma solução?

A

Pelo que descreveu, essas tarefas devem estar sendo executadas em um pool de threads. Você pode, ou, controlar com algum sincronizador o fluxo das tarefas ou executar numa única tarefa.

jonsistemas

Voce tem exemplo de qualquer um desses dois que voce citou?

A

Voce tem exemplo de qualquer um desses dois que voce citou?

Não tenho. Procure por exemplos de uso de semáforos.
Para executar numa tarefa, uma solução seria fazer um método que recebesse por parametro uma lista dos botões para piscar, e faz um loop piscando de acordo com a lista.

jonsistemas

Voce tem exemplo de qualquer um desses dois que voce citou?

Não tenho. Procure por exemplos de uso de semáforos.
Para executar numa tarefa, uma solução seria fazer um método que recebesse por parametro uma lista dos botões para piscar, e faz um loop piscando de acordo com a lista.

Na verdade eu tenho um metodo jogo que recebe os botoes que vao piscar mas os botoes sao representados como numeros inteiros.

public void rodar(int tam) // recebe quantas rodadas do jogo até o jogador ganhar
		{
			int n; 
			vetor = new int[tam]; 
			System.out.printf("Valor de tam %d\n", tam);
			for(i=0; i<tam; i++)
			{
				n = r.nextInt(4)+1; // gera numeros aleatorios de 1 até 4(1-vermelho,2-azul,3-amarelo,4-verde)
				vetor[i]= n; // atribui para o vetor
				
			}
			
			for(i=0; i<tam; i++)
			{	
				
				for(j=0; j<i; j++)
				{
					pisque(vetor[j]); // pisca a devida cor [problema aqui, o tempo de cada cor nao é esperado]
					System.out.printf("%d ", vetor[j]);
				}
				System.out.println();
				
				
				
			} 	
		}

essa função pisque recebe um inteiro de 1 a 4, que representa qual botão será piscado, mas conforme ja disse, não está de forma sequencial, todos os botoes estão sendo piscados de uma vez, e o tempo é esperado depois.

A

Passa o vetor para o método piscar e faz o loop no runnable. Junta os códigos dos botões num só (piscaVermelho, piscaVerde, etc).

jonsistemas

Mas esses codigos ja estao juntos na função pisque

void pisque(int cor)
	{
		if(cor==1)
		{
			
			piscaVermelho();
			 
		}
		else if(cor==2)
		{
			piscaAzul();
			
		}
		else if(cor==3)
		{
			piscaAmarelo();
			
		}
		else if(cor==4)
		{
			
			piscaVerde();
		}		
	}

voce ta falando de criar um metodo piscar parecido com esse?

public void piscar(final int vet[])
	{
		java.awt.EventQueue.invokeLater(new Runnable()  
        {  	    		
    		public void run()  
    		{   
                try  
                {  
                	for(i=0; i<vet.length; i++)
            		{
            			for(j=0; j<=i; j++)
            			{
            				pisque(vet[i]);
            			}
            		}    
                } 
                finally
                {
                
                }
                  
              }  
        });

Criei mas nao deu certo também ;/

A

Você precisa no lugar do pisque(vet[i]) colocar os códigos que estão nos métodos piscaVermelho, piscaVerda, etc.
Sem chamar chamar novamente o invokeLater.

Ou então, alterar os métodos, retirando o runnable.

O objetivo é ter apenas um runnable.

jonsistemas

A H Gusukuma:
Você precisa no lugar do pisque(vet[i]) colocar os códigos que estão nos métodos piscaVermelho, piscaVerda, etc.
Sem chamar chamar novamente o invokeLater.

Ou então, alterar os métodos, retirando o runnable.

O objetivo é ter apenas um runnable.

Tentei fazer aqui o que você falou, mas ou sou muito ignorante, ou estou zicado mesmo, os os dois , tentei isso e também não funcionou :frowning:

public void piscar(final int vet[])
	{
		
		for(i=0; i<vet.length; i++)
		{
            	
            for(j=0; j<=i; j++)
          	{
            	if(vet[i]==1)
            	{
            		jButton1.setBackground(Color.black);
           	    	java.awt.EventQueue.invokeLater(new Runnable()
           	    	{
           	    		public void run()  
                		{
           	    			try 
            			    {    		
            			    	Thread.sleep(1000);
            			    } 
            			    catch (InterruptedException e1) 
            			    {	
            			    	e1.printStackTrace();
            			    }
           	    			jButton1.setBackground(Color.red);
            			}
            		});
            	}
            	else if(vet[i]==2)
            	{
            		jButton2.setBackground(Color.black);
           	    	java.awt.EventQueue.invokeLater(new Runnable()
           	    	{
           	    		public void run()  
                		{
           	    			try 
            			    {    		
            			    	Thread.sleep(1000);
            			    } 
            			    catch (InterruptedException e1) 
            			    {	
            			    	e1.printStackTrace();
            			    }
           	    			jButton2.setBackground(Color.red);
            			}
            		});
            	}
            	else if(vet[i]==3)
            	{
            		jButton3.setBackground(Color.black);
           	    	java.awt.EventQueue.invokeLater(new Runnable()
           	    	{
           	    		public void run()  
                		{
           	    			try 
            			    {    		
            			    	Thread.sleep(1000);
            			    } 
            			    catch (InterruptedException e1) 
            			    {	
            			    	e1.printStackTrace();
            			    }
           	    			jButton3.setBackground(Color.red);
            			}
            		});
            	}
            	if(vet[i]==4)
            	{
            		jButton4.setBackground(Color.black);
           	    	java.awt.EventQueue.invokeLater(new Runnable()
           	    	{
           	    		public void run()  
                		{
           	    			try 
            			    {    		
            			    	Thread.sleep(1000);
            			    } 
            			    catch (InterruptedException e1) 
            			    {	
            			    	e1.printStackTrace();
            			    }
           	    			jButton4.setBackground(Color.red);
            			}
            		});
            	}
            	
           }
		}
     }
jonsistemas

Tentei dessa outra forma e nem piscando está mais

public void piscar(final int vet[])
	{
		
	    java.awt.EventQueue.invokeLater(new Runnable()
	    {
	    	public void run()  
    		{
	    		try
	    		{
            		Thread.sleep(1000);
            		for(i=0; i<vet.length; i++)
    				{
    		            	
    		            for(j=0; j<=i; j++)
    		          	{
    		            	if(vet[j]==1)
    		            	{
    		            		jButton1.setBackground(Color.black);
    		            		try
    		    	    		{
    		                		Thread.sleep(1000);
    		    	    		}
    		    	    		catch (InterruptedException e1) 
    		    	            {	
    		    	            	e1.printStackTrace();
    		    	            }
    		            		jButton1.setBackground(Color.red);
    							System.out.printf("%d ", vet[j]);
    		            	}
    		            	else if(vet[j]==2)
    		            	{
    		            		jButton2.setBackground(Color.black);
    		            		try
    		    	    		{
    		                		Thread.sleep(1000);
    		    	    		}
    		    	    		catch (InterruptedException e1) 
    		    	            {	
    		    	            	e1.printStackTrace();
    		    	            }
    		            		jButton2.setBackground(Color.blue);
    		            		System.out.printf("%d ", vet[j]);

    		            	}
    		            	else if(vet[j]==3)
    		            	{
    		            		jButton3.setBackground(Color.black);
    		            		try
    		    	    		{
    		                		Thread.sleep(1000);
    		    	    		}
    		    	    		catch (InterruptedException e1) 
    		    	            {	
    		    	            	e1.printStackTrace();
    		    	            }
    		            		jButton3.setBackground(Color.yellow);
    		            		System.out.printf("%d ", vet[j]);

    		            	}
    		            	else if(vet[j]==4)
    		            	{
    		            		jButton4.setBackground(Color.black);
    		            		try
    		    	    		{
    		                		Thread.sleep(1000);
    		    	    		}
    		    	    		catch (InterruptedException e1) 
    		    	            {	
    		    	            	e1.printStackTrace();
    		    	            }
    		            		jButton4.setBackground(Color.green);
    		            		System.out.printf("%d ", vet[j]);
    		            	}
    		            	
    		          	}
    				}
	    		}
	    		catch (InterruptedException e1) 
	            {	
	            	e1.printStackTrace();
	            }
	    		
    		}
			    	
	    });
   }
A

Inclu um sleep(200) após o setBackground com a cor, não entendi os dois loops

jonsistemas

Os loops fazem o seguinte:

vamos se por que a primeira cor é amarela(3), entao vai aparecer 3
depois na proxima rodada, vai aparecer 3 e outra cor, por exemplo azul(2), ou seja, vai aparecer 3 2
depois na proxima 3 2 e mais uma cor, por exemplo vermelho(1), ou seja vai aparecer 3 2 1
e assim por diante

o try só esta ai para o sleep

A

Mudou algo?

jonsistemas

Não deu certo, esse trabalho eu teria que entregar amanhã :frowning:

A

Não deu certo, esse trabalho eu teria que entregar amanhã :(
Qual o erro?

Luiz_Augusto_Prado

vou te dar umas dicas…

cara, vc sabe o que é isso?

java.awt.EventQueue.invokeLater(new Runnable()  
{  
....
}

isso é usado para vc ter um paralelismo entre o que sua logica de negocios realiza e a interface gráfica. Ou seja é uma thread. Vc só precisa dela uma única vez, no corpo do construtor principal que irá chamar o primeiro elemento da sua interface.
ver:


vc pode ter um grande número de threads, mas se sua interface gráfica também não tiver dentro de uma, não ocorrerão atualizações na sua tela. Vai ficar parecendo que travou. Pra vc entender isso, tem que ler.

a segunda dica é que vc pesquise linha por linha de todos os dos fontes mostrados aqui e entenda o que cada linha faz, se não, não vai conseguir aprender. A galera aqui não é de pegar na mão pra mostrar como se faz.

Se vc já conhece um pouco sobre, metodos, funções, programação estruturada e orientada a objetos (não precisa tanto conhecer thread tanto pois o que quer é simples), pode modificar o fonte abaixo e implementar de acordo com suas necessidades.

import javax.swing.*;  
    import java.awt.Button;  
    import java.awt.Color;  
    import java.awt.event.ActionEvent;  
      
    class Main  
    {  
        Button btn;  
      
        private Main()  
        {  
            java.awt.EventQueue.invokeLater(new Runnable()  
            {  
                public void run()  
                {  
                    JFrame jframe = new JFrame();  
                    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                    btn = new Button("teste");  
                    btn.setBackground(new Color( 0, 255,  0));  
                    jframe.getContentPane().add(btn);  
                      
                    btn.addActionListener(new java.awt.event.ActionListener()  
                    {   
                        @Override  
                        public void actionPerformed(ActionEvent ae)  
                        {   
                            // tente chamar seu metodo aqui:
                            piscar();
                        }  
                    });  
                    jframe.setVisible(true);  
                }  
            });  
        }  

       // corrigir o que falta aqui:
        piscar()
       {
               btn.setBackground(new Color(255, 0, 0));   
               try  
                            {  
                                Thread.sleep(1500);  //Pausa a tela por meio segundo     
                            }  
                            catch (InterruptedException ie)  
                            {  
                            }  
                            btn.setBackground(new Color(0, 255, 0));  
        }
      
        public static void main(String args[])  
        {  
            new Main();  
        }  
    }
Criado 28 de novembro de 2014
Ultima resposta 1 de dez. de 2014
Respostas 21
Participantes 3