Results 1 to 2 of 2
  1. #1
    matinthehat is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Detecting the clicking of two specific JButtons to create an event

    Hello Everyone

    I am trying to make a java swing/awt app that is a basic simulation of a beverage vending machine.

    I need the program to recognise the clicking of two specific JButtons for a product code.

    For example if JButton 'E' was pressed then JButton '1' was pressed the program would know that is the code for soda and display the relevant message.

    Is there anyway to do this?

    Thanks you!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You would likely have a non-GUI model controlling the logic. It would know for instance that money has been inserted, how much, and would keep track of what button has been pushed. I'm thinking of something like

    Java Code:
    class VendingModel {
      private int centsEntered = 0;  // don't use a double for this!
      private String letterButtonText = "";
      private String numberButtonText = "";
      
      // constructors, getters, setters, etc...
      // method addToCentsEntered(int moreCents) {...}
      // method processOrder() {...}
    }
    And then the GUI would hold an instance of this model, and if money is entered would increment the centsEntered, if a button is pressed would call the appropriate model method in the button's actionListener,...etc

Similar Threads

  1. Replies: 3
    Last Post: 06-27-2010, 03:57 AM
  2. Make specific cell a hyperlink (triggers event)
    By javanewbie in forum AWT / Swing
    Replies: 3
    Last Post: 06-21-2009, 04:26 AM
  3. threads waiting the same event :searching for a specific notification
    By nabila.abdessaied in forum Threads and Synchronization
    Replies: 2
    Last Post: 03-31-2009, 11:41 AM
  4. threads waiting the same event :searching for a specific notification
    By nabila.abdessaied in forum Threads and Synchronization
    Replies: 0
    Last Post: 03-30-2009, 06:33 PM
  5. Detecting mouseEntered event in JComponent
    By djhallx in forum AWT / Swing
    Replies: 1
    Last Post: 02-26-2009, 11:39 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
  •