Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

some java help needed!

Options
  • 24-03-2004 4:51pm
    #1
    Registered Users Posts: 742 ✭✭✭


    Doing an atm simulator

    Need an if statement so the user has to enter an amount in multiples of 20, ie 20 40 60 80 and so on. When the user clicks ok and hasnt entered it like this i will use a msg box.

    Also need an if statement so that when the user clicks ok and the text field is empty that i wont get an error and can msg box instead i have tried a few ways but they dont seem to be working.

    Finally need a method to deselect all the radio buttons and call the method from a button

    public void Deselect()
    {
    twentyBtn.setSelected(false);
    fiftyBtn.setSelected(false);
    hundredBtn.setSelected(false);
    twohundredBtn.setSelected(false);
    fivehundredBtn.setSelected(false);
    }
    this doesnt seem to work for me


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    1. best approach: Regular Expressions ( must be a 2,4,6,8 AND at least one zero..)

    2. just test if field ==null || field.equals("") --> call a popup box..

    3. Button -> ActionEvent -- trigger the Deselect()

    something along the lines of:

    Create a button called ClearButton and add action listener
    and..
    public void actionPerformed(ActionEvent event)
    {
      Object source = event.getSource();
    
      if(source == ClearButton)
      {
        deselect();
      }
    }
    


  • Registered Users Posts: 919 ✭✭✭timeout


    Why do you need to deselect a button?

    If you are reading the values from the buttons I can understand but why not read it directly from a text box. Simply make a textbox that will display the selected value.Set it so its unEditable. As the user selects the different values, clear the text box and replace it with the new value. Now just read the value from the textbox. when needed.


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    Originally posted by Loco
    Need an if statement so the user has to enter an amount in multiples of 20, ie 20 40 60 80 and so on.
    if (value % 20 != 0) will catch all values that aren't multiples of 20.


  • Registered Users Posts: 742 ✭✭✭Loco


    thanks for the replies

    I need the radio buttons to be deselected when the panel is exited(im using cardlaylout).. so when the user comes back there is not already one selected.
    calling it from the buttons when the panel is exited does do anything
    ----


    if(amountFld==null)
    {
    JOptionPane.showMessageDialog(null, "Please enter a value");
    }

    this code gives me the error:

    java.lang.NumberFormatException: For input string: ""

    with a long list underneath it


  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    Paste code + the full stack trace (error) please.


  • Advertisement
  • Registered Users Posts: 742 ✭✭✭Loco


    java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Integer.parseInt(Integer.java:476)
    at Otheramount.actionPerformed(Otheramount.java:66)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)


  • Registered Users Posts: 742 ✭✭✭Loco


    multiples of 20 thingy is working now thanks guys


    still need to catch that blank textfield error & clear radio buttons

    that method just is not working i think, its doesnt respond to the method at all
    am i using the wrong commands ?


  • Registered Users Posts: 742 ✭✭✭Loco


    its a JTextField and JRadiobuttons if that makes any difference O_o


  • Registered Users Posts: 742 ✭✭✭Loco


    just the radio buttons now .setSelected isnt workin for meh jradio buttons for some reason


  • Registered Users Posts: 919 ✭✭✭timeout


    You really need to post up some sample code for us to look at. With most radio buttons at least one must be selected. Have you placed them in a button group? here try thislink might sort something for you.

    Again post some sample code. Try .equals("") on the textbox.

    Timeout


  • Advertisement
Advertisement