Results 1 to 3 of 3
  1. #1
    Razpet22 is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default 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.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default 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...

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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.

Similar Threads

  1. Why actions in url?
    By SomeoneHere in forum Struts
    Replies: 5
    Last Post: 01-10-2012, 06:07 AM
  2. ActionListener for JButton after changing Button to JButton
    By ravi.joshi53 in forum Java Applets
    Replies: 2
    Last Post: 10-07-2011, 08:35 AM
  3. Actions
    By What2do in forum New To Java
    Replies: 4
    Last Post: 01-31-2011, 05:45 PM
  4. How to Use Actions
    By AJArmstron@aol.com in forum New To Java
    Replies: 4
    Last Post: 04-18-2010, 10:03 PM
  5. Actions
    By alley in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •