Results 1 to 3 of 3
- 05-02-2012, 01:27 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
Having more actions on just one jButton
Hey guys, I'm making a blackjack game for school, and I've stumbled upon a problem. In blackjack, you have a 'hit' and 'stand' button. Whenever I would press hit button, application would randomly select a card and put in in next jLabel (I used 5 jLabels). So when you'd click the hit button for the first time, you'd get a random card in jLabel1, when you'd click the button again, it would give you a random card in jLabel2 and so on.
I really don't know how to do this. ANY help would be very much appreciated.
- 05-02-2012, 04:27 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: Having more actions on just one jButton
See How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
And a suggestion: the specificity of an answer goes hand in hand with the specificity of the question. If you want an answer more specific you are going to have to ask a more specific question...and by that I mean providing context such as code (SSCCE), etc...
- 05-02-2012, 04:29 PM #3
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Having more actions on just one jButton
You can add a variable that will store information which JLabel should be given a random card. Let say you have an array of JLabel. You can create an integer variable that will act as a pointer to the JLabel in the array. If the index is 0 then you give a random card to the first JLabel, if the index is 1 then you give a random card to the second JLabel.
Website: Learn Java by Examples
Similar Threads
-
Why actions in url?
By SomeoneHere in forum StrutsReplies: 5Last Post: 01-10-2012, 05:07 AM -
ActionListener for JButton after changing Button to JButton
By ravi.joshi53 in forum Java AppletsReplies: 2Last Post: 10-07-2011, 07:35 AM -
Actions
By What2do in forum New To JavaReplies: 4Last Post: 01-31-2011, 04:45 PM -
How to Use Actions
By AJArmstron@aol.com in forum New To JavaReplies: 4Last Post: 04-18-2010, 09:03 PM -
Actions
By alley in forum AWT / SwingReplies: 2Last Post: 01-16-2008, 02:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks