Results 1 to 2 of 2
- 05-05-2011, 08:26 PM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
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!
-
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
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,...etcJava 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() {...} }
Similar Threads
-
Detecting color change and clicking a button. awt.robot not fast enough?
By doejohn in forum New To JavaReplies: 3Last Post: 06-27-2010, 02:57 AM -
Make specific cell a hyperlink (triggers event)
By javanewbie in forum AWT / SwingReplies: 3Last Post: 06-21-2009, 03:26 AM -
threads waiting the same event :searching for a specific notification
By nabila.abdessaied in forum Threads and SynchronizationReplies: 2Last Post: 03-31-2009, 10:41 AM -
threads waiting the same event :searching for a specific notification
By nabila.abdessaied in forum Threads and SynchronizationReplies: 0Last Post: 03-30-2009, 05:33 PM -
Detecting mouseEntered event in JComponent
By djhallx in forum AWT / SwingReplies: 1Last Post: 02-26-2009, 10:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks