swing - Getting a button to blink when selected Java -


i have created grid of buttons. when user clicks on button needs blink. know need timer, stuck on how implement makes button blink. below creates grid , changes button yellow when clicked.

    private void showgrid(int gridsize) {      gridpanel = new jpanel();     gridpanel.setlayout(new gridlayout(gridsize, gridsize));     gridpanel.setpreferredsize(new dimension(300,300));      buttons = new jbutton[gridsize][gridsize];     labels = new jlabel[gridsize][gridsize];      (int row = 0; row < gridsize; row++) {          (int col = 0; col < buttons[row].length; col++) {             buttons[row][col] = new jbutton();             labels[row][col] = new jlabel();             buttons[row][col].addactionlistener(this);             gridpanel.add(buttons[row][col]);          }     }     contentpanel.add(gridpanel, borderlayout.center);     add(contentpanel, borderlayout.center);  }   public void actionperformed(actionevent e) {       jbutton btn = (jbutton)e.getsource();     if(e.getsource() != newgame)     {         //how blink?         btn.setbackground(color.yellow);       } } 

you can implement same through thread

use

thread.sleep(100);

then set previous color again.

steps provided .hope can implement.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -