Java Help on buttons with counter

public Keypad(Display myMonitor)
        // initialise instance variables
        monitor = myMonitor;
        JPanel p = new JPanel();
        p.setLayout(new GridLayout(5,4));
        String [] buttonLabels={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve",
        "Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty"};
        JButton [] buttons = new JButton[buttonLabels.length];
        for(int i = 0; i < buttonLabels.length; i++)
            buttons[i] = new JButton( buttonLabels[ i ] );
            buttons[i].addActionListener(this);
            p.add(buttons[i]);
            setFont(new Font("SansSerif",Font.BOLD,18));
          add("Center",p);
I need help on using the buttons to have a counter for example when someone clicks  the button "One" 5 times it display something like this : [5] One. So far the buttons work, but I cannot get a counter associate with them. Big Help is extremely needed.  Also the buttons need to be reset to zero; I dont want the counter to keep increasing forever.
Thanks Cheikh

You should create two new integer variables.
count and lastPressed
let lastPressed be set to a different numeric value for each button you have (button1 = 0, button2 = 1, and etc)
you set lastPressed each time a button is pressed (in the handler) to its specific associated value, and then set count to 1. If lastPressed is = to the integer button index of the current button, then you pressed the button last time, so we increment count (count++).
I hope this helps. I might not be explaining it well enough.
example:
if( lastPressed == 0 )
count++
else // we're in button 0, and lastPressed != to it.
count = 1;
lastPressed = 0;
// handle other stuff ,and return

Similar Messages

  • Help creating buttons with actions

    I am looking for a way to program buttons with actions and conditional outputs. As an example: After populating a set number of cells, I would like to be able to program a button to copy the contents of those cellsto another set of cells. Also, a button programmed to clear the contents of the cellswould be nice.
    anyone?

    Buttons are typically associated to macros (VBA or other). As Numbers 1.0 does not support any macros, I am afraid that you are out of look.
    To copy values is very simple with formulas of course (=a1 and so on), but you probably know that, and need something more powerful.

  • Apple, please help. Problems with counter on .Mac front page.

    This problem has been there for quite some time already. Kindly look into this.
    Thanks.
    http://discussions.apple.com/thread.jspa?threadID=1081633
    http://discussions.apple.com/thread.jspa?threadID=1081518
    http://discussions.apple.com/thread.jspa?threadID=992846

    Apple won't help via these forums; instead send your feedback to .Mac support via the form at the bottom of this link...
    http://www.apple.com/support/dotmac/publishing/

  • Need help on creating a button with additional drop down menu

    Hi,
    I need to have a button with additional menu as we see in IE, please help me how can i do that. I want the button to be displayed normally with an additional arrow on the right side when clicked on it shows pop up menu. Please let me know if the solution has already there in the forum. I searched and couldn't get one .. :(

    Hey there buddy.
    Try this:
    http://www.koders.com/java/fid20361AB8C305DE9B9110DE90F2154FC43AA0E57C.aspx
    Jason.

  • XSLT mapping with Java helper classes

    Hi,
    I'm trying to implement a XSLT mapping to convert my request to a specific soap request message format for this I'm calling some methods from a java helper class. I have imported the jar file into the archives. When I tried to test the interface it keeps complaing there is some exception but doesn't give me the exact error. Has any one called any java helper classes with in XSLT mapping, if so I would appreciate if you could help me with this. Here is the code from xsl.
    <wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"   xmlns:UserToken="java:com.company.test.mapping.UserTokenMap">
    <wsse:UsernameToken>
        <wsse:Username xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
          <xsl:value-of select="UserToken:getUsername()"/>
        </wsse:Username>
        <wsse:Password wsse:Type="wsse:PasswordDigest" xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getPasswordDigest()"/>
        </wsse:Password>
        <wsse:Nonce xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getNonce()"/>
        </wsse:Nonce>
        <wsu:Created xsi:type="soapenc:string" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getCreateDate()"/>
    </wsu:Created>
    </wsse:UsernameToken>
    </wsse:Security>
    Thanks,
    Joe

    Hi,
    I'm getting following exception when I refer to the java class with in my XSLT mapping. Any one encountered the same problem.
    com.sap.engine.services.ejb.exceptions.BaseRemoteException:
    Exception in method transform.
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:218)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0p4_Skel.dispatch(MapServiceRemoteObjectImpl0p4_Skel.java:104)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native
    Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: java.lang.UnsupportedClassVersionError:
    com/earthlink/xi/mapping/UserTokenMap (Unsupported
    major.minor version 49.0)
         at java.lang.ClassLoader.defineClass0(Native
    Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
         at com.sap.engine.lib.xsl.xpath.JLBLibrary.<init>(JLBLibrary.java:33)
         at com.sap.engine.lib.xsl.xpath.LibraryManager.getFunction(LibraryManager.java:69)
         at com.sap.engine.lib.xsl.xpath.ETFunction.evaluate(ETFunction.java:98)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.innerProcess(XPathProcessor.java:56)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:43)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:51)
         at com.sap.engine.lib.xsl.xslt.XSLValueOf.process(XSLValueOf.java:76)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLTemplate.process(XSLTemplate.java:272)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:463)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:431)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:394)
         at com.sap.engine.lib.jaxp.TransformerImpl.transformWithStylesheet(TransformerImpl.java:398)
         at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:240)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingTransformer.transform(RepMappingTransformer.java:150)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepXSLTMapping.execute(RepXSLTMapping.java:81)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepSequenceMapping.execute(RepSequenceMapping.java:54)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80)
         at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107)
         at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127)
         at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:167)
         ... 10 more
    ; nested exception is:
         java.lang.UnsupportedClassVersionError:
    com/earthlink/xi/mapping/UserTokenMap (Unsupported
    major.minor version 49.0)

  • My iphone has developed sticky buttons with voice overide. I have tried restoring the phone to no avail. Please help!

    my iphone developed sticky buttons with voice overide. I tried to restore but that did not help. What should I do to get the phone to work again?

    If it is under warranty contact apple to get it repaired.
    http://expresslane.apple.com

  • I just need a little help to connect with eCommerce API. Could anyone please give a JAVA sample code

    Hi All,
    I am looking for a sample code to just to connect with Business Catalyst eCommerce API. My aim is to simply retirieve the list of the products and update them.
    It would be really helpful, if anyone please provide me a sample code in JAVA, just to connect with the API.
    Thanks
    Ani

    public static void main(String[] args) throws RemoteException, MalformedURLException {
                        String endpoint = "https://CC.sys.com/CatalystWebS1ervice/CatalystEcommerceWebservice.asmx?WSDL"; // endpoint url can be found under Site Settings -> API -> click on eCommerce and copy the URL on the browser here.
                        CatalystEcommerceWebserviceSoapProxy sq = new CatalystEcommerceWebserviceSoapProxy(endpoint);
                        Products[] prod = new Products[2];
                        prod = sq.product_ListRetrieve(Username , Password, SiteID, CatalogueID);
                        System.out.println(prod[1].getDescription());

  • Just started using Safari, 5.1 on Win XP.  Places where there used to be check boxes now have little buttons with triangles on them; clicking them seems to have no visible effect.  Help!

    I just started using Safari, using Safari 5.1 on Win XP.  Any place where there used to be a check box, there's now a little button with a triangle on it.  The triangle changes orientation as I move the mouse cursor around, but there is no visible change if I click on it.  Yet it appears that I must click on it to check, or uncheck, the box; I just can't tell whether it's checked.  If I can't get this to work better, I'll have to give up on Safari.  Please help.  (Note: there's one at the head of this thing saying "Mark this discussion as a Question - this encourages people to answer for points and helps you track answers."  I clicked on it, but don't know whether it's checked or not.  That's a fairly minor example.)

    Can you provide an SSCCE that demonstrates this behavior?

  • Help, my iPhone 5, I've turned it off and on and it has the same fault. What ever you press on the screen highlights with a box round it. When you press the round button with the square in the centre the voice on the phone tells you the time. Then the voi

    Help, my iphone 5 is locked and will not function! I've turned it off and on and it has the same fault. What ever you press on the screen highlights with a box round it. When you press the round button with the square in the centre the voice on the phone tells you the time. Then the voice says screen lock. If I try and unlock the phone the voice says phone unlock but you can't put the code in. If you hight the box it will say the number but not put the code in?! What's the crack?

    Quickly Triple tap the home button to de-activate VoiceOver.

  • HT1351 I'm trying to manually sync all my music to my iPod touch, but whenever I click the sync button it counts to 5 then stops. Is this because I have to check all 3055 songs individually? If so then I'm quitting with apple as a whole....

    I'm trying to manually sync all my music to my iPod touch, but whenever I click the sync button it counts to 5 then stops. Is this because I have to check all 3055 songs individually? If so then I'm quitting with apple as a whole....

    Sync and manually manage are two entirely different things.  You either sync or manually manage.
    Manually manage is drag and drop.
    Sync is when you select what you want and then sync.

  • HT5557 I cannot open an iBook on my iphone where it was purchased. There is a button with a square next to the book. Can anyone help?

    I cannot open an iBook on my iphone where it was purchased. There is a button with a square next to the book. Can anyone help?

    Hi bellenyc,
    Welcome to the Support Communities!
    The article below may be able to help you with this issue.
    Click on the link to see more details and screenshots. 
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    I hope this information helps ....
    Have a great day!
    - Judy 

  • Help with count and sum query

    Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
    SELECT 'ST' LEDGER,
    CASE
    WHEN c.Category = 'E' THEN 'Headcount Exempt'
    ELSE 'Headcount Non-Exempt'
    END
    ACCOUNTS,
    CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
    'MARCH_12' AS PERIOD,
    COUNT (a.empl_id) head_count
    FROM essbase.employee_pubinfo a
    LEFT OUTER JOIN MMS_DIST_COPY b
    ON a.cost_ctr = TRIM (b.bu)
    INNER JOIN MMS_GL_PAY_GROUPS c
    ON a.pay_group = c.group_code
    WHERE a.employee_status IN ('A', 'L', 'P', 'S')
    AND FISCAL_YEAR = '2012'
    AND FISCAL_MONTH = 'MARCH'
    GROUP BY a.company,
    b.district,
    a.cost_ctr,
    c.category,
    a.fiscal_month,
    a.fiscal_year;
    which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    user610131 wrote:
    ... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
    I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
    You may want both a sub-query and a different GROUP BY clause. For example:
    WITH    got_group_by_columns     AS
         SELECT  a.empl_id
         ,     CASE
                        WHEN  c.category = 'E'
                  THEN  'Headcount Exempt'
                        ELSE  'Headcount Non-Exempt'
                END          AS accounts
         ,       CASE
                        WHEN a.company = 'ZEE'
                        THEN 'OH'
                        ELSE 'NA'
                END          AS market
         FROM              essbase.employee_pubinfo a
         LEFT OUTER JOIN  mms_dist_copy             b  ON   a.cost_ctr     = TRIM (b.bu)
         INNER JOIN       mms_gl_pay_groups        c  ON   a.pay_group      = c.group_code
         WHERE     a.employee_status     IN ('A', 'L', 'P', 'S')
         AND        fiscal_year           = '2012'
         AND        fiscal_month          = 'MARCH'
    SELECT    'ST'               AS ledger
    ,       accounts
    ,       market
    ,       'MARCH_12'          AS period
    ,       COUNT (empl_id)       AS head_count
    FROM       got_group_by_columns
    GROUP BY  accounts
    ,            market
    ;But that's just a wild guess.
    You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
    Edited by: Frank Kulash on Apr 4, 2012 5:31 PM

  • TS4079 I hold down the home button with Siri enabled on my Iphone 4 but it will not open, internet is present.. help??

    I hold down the home button with Siri enabled on my Iphone 4 but it will not open, internet is present.. help??

    Make sure Siri isn't disabled in Settings > General > Restrictions.
    If that isn't it, did you try to restore as a new device?

  • Help!! Buttons with different actions on IPAD

    Why is in Ipad a button with different actions does not respond to these actions at the same time, but one at a time? In Android works fine!!
    What is happening is that in ipad I have to touch more than once on the button to go to the different actions that this button has!
    Help...

    Hi Tomas
    thanks for the quick response.  I think mine Adobe Content Viewer is the last update, from February 21, so the problem is not due to this.
    II'll explain the situation better, i have several identical situations. For example, I have a square that hides an image and I want that when you tap this square this image appears behind him, then i did the following: I selected at first the square and the image and transformed a multi- State Object, in which the first state is the box (State1) and the second is the image (state 2) then made a transparent button on top of this square and it gave the following actions - on release go to state 2 (image) here everything goes well, the problem is that as I have more buttons / squares that do the same and show different images, that when I turned the other one the next hide her image. So all the buttons in addition to the state that shows the picture / object matching (state 2) - i have also- go to state (name of the object: state 1) causes other squares hide their files, as they get the state 1. Here lies the problem, in ipad these actions do not react automatically but in different touches, it seems that it reads a touch for action and not all at once.
    I apologize for my English but I'm Portuguese, I hope you can understand everything explained.
    Marta

  • My classic has come up with a sreen which 5 lins of text (in large font) Line 1  says 5 in 1 line 2 sdrampass L3 chksum any ideas I've tried the MENU   CENTRE BUTTON with no joy HELP

    My classic has come up with a screen which has 5 lines of text (in large font) Line 1 says 5 in 1 Line 2 sdrampass L3 chksum Any ideas ? I've tried the MENU + CENTRE BUTTON with no joy HELP

    Hi starbugdriver,
    I recommend trying the iPod classic troubleshooting assistant here:
    iPod classic Troubleshooting Assistant
    http://www.apple.com/support/ipod/five_rs/classic/
    Have a good one!
    - Ari

Maybe you are looking for

  • How to re-install Premiere 8.1 (having MXF issues)

    Since upgrading to 8.2, I can't export MXF Comps without getting intermittent red flash frames. I have done clean installs of the newest 8.2 twice on my Mac Pro Late 2013 with the same results. The current previous install files on the CC server are

  • Animating a photoshop text layer in After Effects

    Im trying to animate the test from a page that was built in photoshop. I save the layers all seperatly but AE just recognizes the text box not the text itself, so i am unable to use the text animations on it. Is this even possible and if so how do i

  • TS4062 Sync Iphone 4 to New Ipad without usb

    How do I sync an iphone 4 to a new ipad with out a USB connection.  I have a wi fi connection but online instructions say to first connect via usb and the new ipad does not have a usb port.

  • Cant Save, Cant Print, Where is my Serial Key ?

    Hello together, i bought this App by the Mac App Store. Bought it seems that i can't use everything. But Why ? I bought by the App Store ? Could somebody help me ? Thanks

  • Antivirus crash after firmware update

    I installed the latest firmware update on my Yoga 10 last night and now my Avira antivirus has crashed.  I keep getting messages in the top bar about the crash.  I managed to delete Avira and reinstall it, but this has not fixed the problem.  I don't