Results 1 to 5 of 5
Thread: Help with JButton
- 05-20-2008, 09:19 PM #1
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
Help with JButton - how to make a button blink
Hi!
I am currently developing a game - poker dice - for a major project in matric. The project is coming along swimmingly :), but I still don't know how to make a JButton flash / blink. The intention is to attract the user's attention to the particular button.
Please can someone help me with the code / method for this problem. I am coding in Java format.
Thanks a millionLast edited by geoffreybarwise; 05-21-2008 at 10:43 AM.
- 05-21-2008, 05:08 AM #2
If you mean Jbutton blinks,
do it in thread...freedom exists in the world of ideas
- 05-21-2008, 05:51 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How about the use of a Timer. Define a array of colors, and with the timer tick change the background color of it.
- 05-21-2008, 10:41 AM #4
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
Array of colours
Thanks for the help man, i'll definately try that
- 05-21-2008, 10:48 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, why not. Try something like this. This is not what exactly you need, but the logic is there.
Java Code:import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class ButtonBlinker extends JFrame { private JButton btn; final Color[] colors = {Color.RED, Color.GREEN, Color.ORANGE}; ButtonBlinker() { Container content = getContentPane(); btn = new JButton("Blinker"); content.add(btn); pack(); setVisible(true); } public static void main(String[] args) { new ButtonBlinker().blinkTimer(); } private void blinkTimer(){ Timer tt = new Timer(2000, new ActionListener() { public void actionPerformed(ActionEvent e) { btn.setBackground(colors[colorChoocer()]); } }); tt.start(); } private int colorChoocer() { return new Random().nextInt(3); } }
Similar Threads
-
Help with JButton and layout
By adlb1300 in forum AWT / SwingReplies: 1Last Post: 12-25-2007, 08:33 AM -
Need help with JButton event
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-19-2007, 01:15 AM -
mouse over on JButton
By gradon in forum Java AppletsReplies: 1Last Post: 08-04-2007, 05:50 AM -
Few action in one Jbutton
By kubiasty in forum New To JavaReplies: 0Last Post: 07-25-2007, 10:19 AM -
Mouse over JButton
By sandor in forum AWT / SwingReplies: 1Last Post: 05-17-2007, 09:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks