Results 1 to 3 of 3
  1. #1
    Borneq is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default JButton has tag?

    Application has many buttons. How distinguish between its? Is any Tag field?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,646
    Rep Power
    5

    Default Re: JButton has tag?

    Buttons may be distinguished by their action commands via actionEvents. If the action command is not set, the button's name as passed via the constructor is used as the action command.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Borneq is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default Re: JButton has tag?

    I want to write spiecil multi-mode calculator. If I press the Shift button, the buttons captions changed.
    I think how to solve with tags: buttons have tags 0,1,2,3,4...in addition there will different operation codes:
    BTN_INV
    BTN_FRACT
    BTN_LOG
    BTN_10_x
    BTN_LN
    BTN_e_x
    Will configuration arrays, first for normal mode:
    BTN_INV
    BTN_LOG
    BTN_LN
    second for shift mode:
    BTN_FRACT
    BTN_10_x
    BTN_e_x

    I press button, get it Tag, see to array for opcode.

    But is problem: In JButton i have not tags, but distuinguish after name!
    Example:
    Handle action events for JButton | Examples Java Code Geeks


    JButton button1 = new JButton("Yes");
    JButton button2 = new JButton("No");

    //set action listeners for buttons
    button1.addActionListener(this);
    button2.addActionListener(this);

    //add buttons to the frame
    add(button1);
    add(button2);A potem rozróznianie public void
    actionPerformed(ActionEvent ae) {
    String action = ae.getActionCommand();
    if (action.equals("Yes")) {
    System.out.println("Yes Button pressed!");
    }
    else if (action.equals("No")) {
    System.out.println("No Button pressed!");
    }
    }

    Button must have one caption for one mode, socond for another mode.
    Several buttons can have the same caption, for example empty caption.

    How solve this problem?

Similar Threads

  1. Replies: 1
    Last Post: 01-15-2013, 06:44 PM
  2. JButton
    By Proshitness in forum AWT / Swing
    Replies: 11
    Last Post: 12-07-2011, 04:25 PM
  3. ActionListener for JButton after changing Button to JButton
    By ravi.joshi53 in forum Java Applets
    Replies: 2
    Last Post: 10-07-2011, 07:35 AM
  4. jbutton
    By Patea2000 in forum Advanced Java
    Replies: 1
    Last Post: 03-16-2011, 08:59 AM
  5. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM

Posting Permissions

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