Mechanical Action of an array of buttons

I have an array of buttons that get dynamically built when the front panel is loaded. When I select one of the buttons it remains "pressed in". If I right click on the button the "Mechanical Action" is greyed out. I pulled the button out of the array and checked the settings and its set to latch when released, its just not happening. Is their any way to set this property?

Hi Rob,
enclosed you will find two other solutions, simulating a radio button array based on a standard button array,
this solution use a event loop.
Version 1: Simulates Radio Buttons without "Allow False" Option
Version 2: Simulates Radio Buttons with "Allow False" Option
Attachments:
ButtonArray1.vi ‏10 KB
ButtonArray2.vi ‏10 KB

Similar Messages

  • 'action performed' on array of buttons.

    Hi everyone!
    I am trying to set up an array of buttons on a panel in the main frame of my application. I can get them on to the panel, displaying them correctly but i can;t seem to attach an action performed method to them. Ive attached the following code - if you have any ideas on how to solve this problem i would be very grateful. DO you think it is because they are on this panel and not directly on the main Frame.?
    If i try to attach say Button1_action performed then it clashes with my original button 1!
    Thanks in advance.....
    static int N=10;
    String lett[]={"a","b","c","d","e","f","g","h","i","j"};
    Button button[]=new Button[N];
    for(int k=0;k<N;++k)
    {button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    button[k]_actionPerformed(e);
    this.panel1.add(button[k]);

A: 'action performed' on array of buttons.

viravan is right - your code should work except that button[k]_actionPerformed won't compile. Also, you don't need a separate ActionListener for each button - use a common one and test for the source.
e.g.
import java.awt.*;
import java.awt.event.*;
...code to define Frame, Panel etc...
static int N=10;
String lett[]={"a","b","c","d","e","f","g","h","i","j"};
Button button[]=new Button[N];
ActionListener common = (new ActionListener() {
     public void actionPerformed(ActionEvent e) {
            Button source = (Button)e.getSource();
             System.out.println("Label of button pressed = " + source.getLabel() );
for(int k=0;k<N;++k) {
    button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(common);
    panel1.add(button[k]);
}Another alternative is to addActionListener(this) and code the actionPerformed method as part of the Frame class.

viravan is right - your code should work except that button[k]_actionPerformed won't compile. Also, you don't need a separate ActionListener for each button - use a common one and test for the source.
e.g.
import java.awt.*;
import java.awt.event.*;
...code to define Frame, Panel etc...
static int N=10;
String lett[]={"a","b","c","d","e","f","g","h","i","j"};
Button button[]=new Button[N];
ActionListener common = (new ActionListener() {
     public void actionPerformed(ActionEvent e) {
            Button source = (Button)e.getSource();
             System.out.println("Label of button pressed = " + source.getLabel() );
for(int k=0;k<N;++k) {
    button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(common);
    panel1.add(button[k]);
}Another alternative is to addActionListener(this) and code the actionPerformed method as part of the Frame class.

  • Pass a variable number into an Action method from an array of buttons

    Hello,
    I have created an array of buttons like so:
                       private javax.swing.JButton[] barray = new JButton[8];
    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(K8055_Card_Control.JavaElectrodeSwitches1App.class).getContext().getActionMap(JavaElectrodeSwitches1View.class, this);
                 for (int i=0;i<8;i++)    // Create Output Check Boxes
              barray[i] = new JButton();
                            barray.setAction(actionMap.get("ButtonPressed"));
              barray[i].setName("Outbox"+ String.valueOf(i+1));
              barray[i].setText("Electrode " + String.valueOf(i+1));
    BoxLayout layout = new BoxLayout(jPanel1,BoxLayout.PAGE_AXIS);
    barray[i].setAlignmentX(JCheckBox.CENTER_ALIGNMENT) ;
    jPanel1.setLayout(layout);
    jPanel1.add(barray[i]);
    When a button is pressed it calls the method ButtonPressed()@Action
    public void ButtonPressed()
    // button pressed code here
    My problem is that once the button has been pressed I don't know how to find out which button called the method. Each button operates a different switch.
    I tried testing barray.isSelected(); however the ButtonPressed() method is only called once the button has released and is no longer selected.
    Any ideas?
    Thanks,

    Actually the answer to both of these questions is ActionEvent
    do for instance:
    JButton b = new JButton("test");
    JButon b2 = new JButton("test2");
    ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
      Object src = ae.getSource();
      String cmd = ae.getActionCommand();
      if (src == b) { //won't work unless you make b final
      //or
      if ("test".equals(cmd)) {
    b.addActionListener(al);
    b2.addActionListener(al);

  • LabVIEW 2012 SP1, Can't get correct mechanical action on boolean buttons

    I am trying to use boolean buttons and events to programatically change the properties of a graph.  I basically want to click a button on the FP, and have the graph change the desired property.  All the property changing is fine, but I am really struggling with the mechanical action of the buttons.
    I'll preface this by apologizing that I cannot post my code, as the computers with LV installed are isolated. My code is basically OK buttons, a while loop, and an event structure with a value change event for each button.
    I want the user to click and release the button. After the click and release, I want the button to be in the same state it started, and I want the value change event to only trigger once.  Sounds to me like I want the Latch When Released mechanical action.  The problem is that this isn't working.  I cannot create buttons that behave like this.  None of the 6 mechanical actions exhibit the desired behavior.
    To make matters worse, I have two OK buttons both set to Latch when released.  Both buttons are True before the click. One button behaves as intended (button is true again after the click and release) and the other button doesn't switch back.  I tried to copy the correctly working button, but still the copied button does not work the same as the original.  Both buttons fire a single value change event, dispite behaving differently.
    To answer the question "Where did I get the working button from?"  A while back I made a simple button test vi that tested all 6 of the mechanical actions and kept track of how many times they fired a value change event for a single click.  My buttons worked when I made this vi...eventually, i remember having trouble with this back then too.  The results of that trouble had me using switch until released buttons with mouse down events for a long time, until I got the button test VI working properly and learned how buttons actually work. But now buttons are being funny again.  I tried to copy working Latch when released button into my current program, but for some reason only one of the two copied buttons work as intended, despite them being copies of the same button.
    Is there some bug in LV2012 SP1 (64 bit) where mechanical actions don't work consistently?  Am I just being dumb?  I'm sorry I can't post the code.  I have this issue on both Windows 7 and Linux.
    A bit more info, as I wanted to make sure I tried eveyrthing before posting.  I tried to make a new button test VI.  The old one still works, but I cannot get the buttons in the new button test vi to behave the same as in the old one I made.  In the new one, Latch when pressed behaves the same as switch when pressed, and latch when relased behaves the same as switch when released.  Switch until released and latch until released behave slightly differently.  They both fire two value change events, but SuR actually switches twice (there and back again), where LuR just switches state once but still fires two value change events anyway.  I have checked to make sure the mechanical actions are set properly at least a dozen times.
    Pretty confused over here.  My old button test vi works as I expect it to, and the Latch when released button works like I want, but I can't for the life of me reproduce it.

    To Bob_Schor
    I realize the folly of mouse down events, and I'm trying to move away from them.  I originally started using them because I couldn't get the desired button behavior out of value change events and any other mechanical action.
    I use LabVIEW 64 bit because I was hitting the RAM limits with the 32 bit version.  I hit the limit when I try to plot a great deal of data in 3D, which I do fairly often. I get away with this because I don't interface with any equipment or use any of the specialized modules, but maybe I should consider only using 64 when it's absolutely necesary and get 32 bit on there as well.  But I have the same issue on Linux, which only has a 32 bit labview version (still 2012 SP1)
    There is only one event structure in the program.  I have two buttons because I'm just using them to fire two separate events.  My current situation is that I am plotting 9 plots on a single graph.  One of these buttons is a "check all" button for the visibility check boxes.  I click the check all button, and all 9 plots become visible.  The other button is an "Uncheck all" button, which does the opposite.
    That's for my current program.  I also have a button test vi which has 6 boolean buttons, each set to a different mechanical action.  A single event stucture in a while loop has a value change event for each button.  I made this so that I could see for myself how the buttons worked (i.e. I see that the switch when released mechanical action produced two value change events.).  I have an old version of this program which works as I expect it to.  This morning I tried to remake it (it's very simple) and it does not behave the same, despite the block diagram being pretty much identical.  I described the differences in the OP.
    I can reporduce the behavior on a second computer that is restricted.  Which is 32 bit labview for Linux. I don't have an unrestricted machine with LabVIEW installed.  If I did, I would have tried to rebuild my button test VI  (again) to see if it works.
    At it's most basic, create an OK button on the FP and set in the True state.  It defaults to the Latch when released mechanical action.  Throw an event structure in a while loop.  Give the ES a value change event for the button.  In this even just increment some counter to indicate how many times the value change has been triggered.  I did this using a shift register.  Run it.  For me, when I click the Latch when released button it fires one value change event and doesn't reset to true when after the click.  I can change the mechanical action of the button, and none of the 6 give me what I want.
    So my issue just boils down to Latch when released not behaving properly.
    In my original button test vi (which was this with 5 more buttons and 5 more value change events in the ES), the latch when released button DOES reset to true after my click.  Copy and pasting this button creates a new button which does not behave the same way, despite still being set to latch when released.
    My problem is not so much with the events, but the behavior of the button.  Am I correct that Latch when released is what I want?  A single click, and the button fires one VC event and returns to the same state before the click?

  • 9x9 array of buttons and not a single button worked

    im trying to build a 9 x 9 block composed of buttons. I used array of buttons.
    here's my code with my explanation and poor logic thinking details.
    public class ButtonArrayDemo extends JFrame implements ActionListener
    private JButton[] sButton;
    private int[] x;//manipulation purposes only
    public ButtonArrayDemo()
         JPanel buttonPanel = new JPanel();
         buttonPanel.setLayout( new GridLayout(9, 9) );
         sButton = new JButton[81];
         x = new int[81];
    // creates the buttons,action listeners, syntax is correct but
    // i doubt the logic
         for (int i = 0; i < sButton.length ; i++)
              JButton button = new JButton();
              button.setText(" ");
              button.addActionListener(this);
              sButton[i] = button;
              buttonPanel.add(sButton);
              x[i] = 0;
         getContentPane().add(buttonPanel,BorderLayout.SOUTH);
         setResizable(false);
    // what i want for this is that, when a button is clicked, it displays the
    //number 1 then increments by 1 if clicked again. Like,when i click a
    //blank button, it displays the number "1", if i clicked it again, it displays
    //the number 2. This goes on until number 9. When the button is clicked
    //on the 10th time, it leaves the button's text blank. Syntax is fine but
    //i doubt the logic.
    public void actionPerformed(ActionEvent e)
         int y;
         for(y = 0; y < sButton.length; y++)
              if(e.getActionCommand().equals(sButton[y]))
                   sButton[y].setText(Integer.toString(++x[y]));
                   if(x[y] == 10)
                   sButton[y].setText(" ");
                   x[y] = 0;
    Now, i created the main and compiled the program. The frames appeared complete with 81 buttons. But, when I click on any button,
    it does nothing. The button's text which is supposedly to change is not displaying anything. this is a vital thinking process for me and any help from someone would be very much appreciated.
    thanks for reading and i hope someone will respond to my problem.
    lots of thanks.

    I believe the problem is that you are using the actionCommand but you did not set the actioncommand for the buttons. I suggest you either set the action command for each button to a unique item or use getSource instead.
    Also, you might want to break out of your for loop once you find the correct button.
    Also, if the future use the code formatting tags and this probably should have been in the Swing forum.

  • Array of buttons with different boolean text ?

    I'm looking for a method of displaying a 2D button matrix with
    different boolean text on each button. It seems an array of booleans
    must all have the same text. Perhaps a cluster could be used, but the
    array makes button alignment easy and easy to determine which had been
    pressed (radiobutton style with only one button true at a time).
    Steve

    On 6 Dec 2002 05:31:21 -0800, [email protected] (humenik) wrote:
    >[email protected] (Steve Parus) wrote in message news:<[email protected]>...
    >> I'm looking for a method of displaying a 2D button matrix with
    >> different boolean text on each button. It seems an array of booleans
    >> must all have the same text. Perhaps a cluster could be used, but the
    >> array makes button alignment easy and easy to determine which had been
    >> pressed (radiobutton style with only one button true at a time).
    >It's easy to make them individuals in a cluster, and on the block
    >diagram use Cluster To Array to get it into array form for
    >manipulation. This can be superior to an array of buttons, not merely
    >because the buttons can thereby have differing colors and text. An
    >array of buttons cannot have the buttons Latched When Pressed; when in
    >a cluster, however, the latching action is available.
    When might that Latched When Pressed behavior be useful ? Using a 2D
    array of buttons (not cluster), in LV 6.1, a Value Changed event for
    the array can be used as you mention below to XOR the event's OldValue
    and NewValue and wire that to a local variable copy of the array.
    This easily gives a radio button effect for the entire 2D button
    matrix. The array control automatcially arranges the visual
    alignment of the buttons.
    For the cluster method, I'd like to programmatically change which
    button is true. All the approaches I come up with end up using
    Array-to-Cluster which then requires the cluster size to be specified.
    I may end up wanting to programmatically vary the number of buttons in
    both dimensions and hence the cluster size. LV's Align Objects and
    Distribue Objects ends up making the button visual alignment not
    difficult (for a 12 x 8 matrix).
    >Try this: take a cluster of four PB's (latched when pressed) put
    >inside a while loop. Initialize a boolean array of 4 to FALSE outside
    >the while loop, and attach it to a shift register input on the left
    >side of loop. Inside the loop, convert your cluster to an array. XOR
    >the shift register with this array from the buttons, and wire this to
    >the output shift register and to an indicator array. Set the boolean
    >to the loop so it will run free and start it up; on the control panel,
    >click on the PB's and you will see the outputs toggle.
    >
    >Greg

  • Mechanical action change in subpanel

    Hello,
    My problem is that if i open my vi in a subpanel, the mechanical action of the buttons are changing :\ for eg it is set to 'switch until released' but if the vi run in a subpanel it works as a regular switch :\ The program itself is a GUI vi which opens different VIs in a subpanel according to the selected menupoint.
    Pls help
    Attachments:
    GUI2.vi ‏30 KB

    Yeah you're right, i'm quite new to Labview The buttons that i was talking about are in the subvi, i'll attach it if you want. By the way do you know a better solution to decide which button is pressed in the menu? I've tried event structure with 'value changed' parameter but when i did i didn't get respond from the subvi ( for eg i connected a button to a led but the led didn't lit when i pressed the button ) Thx for the help
    Attachments:
    Mill.zip ‏151 KB

  • How to use same actions for differ pop-up buttons

    Hi gurus,
    I am using 2 popup in a view.same popup's having same buttons 'Yes', 'No'.when i use 1st one i have to create an action for that Yes button where i put my code for that particular Action.
    But when i used 2nd one the action define for that is not acceptable with differ name.it takes only standard one.
    Now my Query is : How to use same actions for differ pop-up buttons with in a similar view?Where i put my code.
    Plz sugges me.
    <b>Points will be sured.</b>
    Sanket sethi

    Hi ,
    u can use the method SUBSCRIBE_TO_BUTTON_EVENT of the IF_WD_WINDOW interface ... to handle the event fired by the popup .....used this method after creating the popup window ...
    regards
    Yash

  • Adobe premiere elements 12 - how to create menu bar action for my inserted image button

    adobe premiere elements 12 - how to create menu bar action for my inserted image button without using their movie menu theme

    forbemag
    I do not think that I am completely focused into this completely, so let us see if the following is going to help.
    You are going to need a base for your button. When you mention "image" button, I am assuming that you are using that term to differentiate between a text button and a thumbnail type button.
    The menus (main and scene) take their origin in .psd files on the hard drive and strict nomenclature and structure for Layers Palatte. And, the buttons on the menus trace back to the menu markers on the Timeline, main menu marker and order of placement of scene markers. The scene thumbnail will only appear when there is a scene marker on the Timeline to which it.
    In view of all that
    Where have you already inserted this "image (button)"...into the Layers Palette of a Photoshop document or other? Is this "image (button)" in a structured Layer Group in the Layers Palette with sublayer groups, text layers, graphic/background layer"?
    Let me give you an example
    If you have a button (with thumbnail) on the main menu and you want that to open to a specific scene in your movie, then you use a main menu marker on the Timeline at the spot that you want that button to target.
    If I am getting closer to what you seek, then please further clarify the DVD navigational envisioned scheme.
    Thanks.
    ATR
    Add On...I did not see the exchanges between us and SG until after I had posted mine. I thought that your discussions were concluded. Please excuse the interruption.

  • Connecting kurzweil sp88 to GB I want to connect my Kurzweil sp88 to GB. The Kurzweil has a baffling array of buttons and possible MIDI channels. It also has the old style MIDI plug ins. I've got the MIDI out connected to my MacBook Pro via USB adapter.

    I have my Kurzweil connected to my MacBook Pro via an adapter (old style MIDI from Kurzweil to USB adapter connecting to Mac). The Kurzweil has a baffling array of buttons and possible MIDI channels. Can anyone please tell me which of the channels I should use? Also, should I leave the MIDI In cable out of the Kurzweil? Thanks for as detailed an answer as possible. If you like you can respond directly to me at [email protected]

    First of all I do not own this keyboard. But a quick look at the manual (found on the internet) says that when first powered up the SP88 is in Internal Sounds mode. Meaning you hear the sounds selected when playing the keyboard. It also stated that the default Midi Transmit Channel is Midi Channel #1.
    Looks like you would need to go to the SP88 Keyboard's MIDI SETUP and simply select LOCAL OFF. Now the keyboard should be ready to transmit Midi Out only and no internal sounds should be heard.
    Next you may or may not need to do this but you might need to go into the Utilities Folder found in your Applications Folder on your Mac and double click AUDIO MIDI SETUP the keyboard Icon. Figure #1 below.
    Next you need to make a physical connection from the Midi Out of the SP88 to the Midi In on your Midi Interface. Figure #3 below. You may need to Click on Add Device first. Figure #2 below.
    In the examples shown below I have a Yamaha Electronic Drum Kit that is Midi Out only... not USB out. I had to plug a Midi cable from the Midi Out Port on the back of my Drum Module to the Midi In Port on the back of my Motu 828 Audio Inferface which is connected to my Mac. Next I created the Audio Interface and Drum Module "Devices" as mentioned above.
    I then double clicked on the Drum Module and made my Midi Out Selections. Figure #4 Below. And once it was setup and the icons closed I used my mouse to draw a virtual cable connection from the Drum Module Out to the Audio Interface In. Figure #3 below. This is how I got my Midi Devices to talk to one another.
    Once you have made your setup as I have outlined create a MIDI Instrument Track in Garageband, select an instrument for example a Piano then Record Enable that track in Garageband and see if you now hear what you are playing. In this example the SP88 is a Midi Controller only and you will only hear sounds selected in Garageband which is what you want.
    Keep in midi your setup may be different than mine. You can keep your SP88 Keyboard on the default Midi Channel #1. That would be a good place to start. Garageband receives Midi on all channels.

  • Array of buttons return indexof?

    Hi,
    I have an array of buttons. How do I get the value of the array so i know which button the user clicks on. If they click on button 10 i need to get the value 10. I cant copy and past the code here because its too long.If someones interested i can email the code and what i'm trying to do. If someone could give me a generic example of a situation that would be great.
    Thanks in advance

    public class KeyPadDemo extends Frame {
         KeyPad keyPad;
         TextArea textArea;
         public static void main(String[] args){
              new KeyPadDemo();
         public KeyPadDemo(){
              this.setSize(300,300);
              this.setLayout(new BorderLayout());
              this.add(textArea = new TextArea(), "North");
              this.add(keyPad = new KeyPad(textArea),"Center");
              this.setVisible(true);
    class KeyPad extends Panel{
         MyButton buttonZero, buttonOne, buttonTwo, buttonThree, buttonFour, buttonFive, buttonSix;
         MyButton buttonSeven, buttonEight, buttonNine, buttonDecimal, buttonZeroZero;
         TextArea outputArea;
         KeyPad(TextArea outputArea){
              this.outputArea=outputArea;
              setLayout(new GridLayout(4,3));                    //GUI number button pad
              add(buttonSeven = new MyButton("1"));
              add(buttonEight  = new MyButton("2"));
              add(buttonNine = new MyButton("3"));
              add(buttonFour = new MyButton("4"));
              add(buttonFive = new MyButton("5"));
              add(buttonSix = new MyButton("6"));
              add(buttonOne = new MyButton("7"));
              add(buttonTwo = new MyButton("8"));
              add(buttonThree = new MyButton("9"));
              add(buttonZero = new MyButton("0"));
              add(buttonDecimal  = new MyButton("."));
              add(buttonZeroZero = new MyButton("00"));
         class MyButton extends Button implements ActionListener{
              String string;
              public MyButton(String string){
                   super(string);
                   this.string=string;
                   addActionListener(this);
              public void actionPerformed(ActionEvent e){
                   outputArea.append(string);
    }

  • Array of buttons and Event Structure

    I have a the same problem... I was wondering if you were able to find a soln.
    I have literally thousands of buttons and each button as a unique key code and unique name.
    For Example :  
    Button Name    – Key code #
    PUSH              - 1
    POP                 - 2
    PULL               - 3
    The way I program this simple algorithm is deadly painful. 
    1)      I create 1000 buttons by going to control->buttons.
    2)      Then I have to go through one by one to change the Boolean text to “PUSH,POP,PULL…”  
    3)      Then used the Event Structure, adding in all the controls names “PUSH, POP, PULL..” In side each event, I placed the key codes “1,2,3..”
    I have search and tried for weeks to find a better way, and still nothing comes to mind.  
    Please help.

    Hi Ben,
    Thank you for your reply, I have attached my try_code and a picture of the code I currently have.  I  am new in Labview, but I am confident that, there must be a easier way to make an array of buttons with different button name and an associated number to that button.  
    The 1st file, is to show you want I am currently doing, (painful)
    The 2nd file attached is some of the things i tried, I had great hope with my try_code, array_jan25.  But I couldn't get it.  I think I am very close.
    Thanks again,
    Attachments:
    ThePainfulWay.doc ‏63 KB
    Array_jan25.vi ‏42 KB

  • Creating array of buttons

    I'm trying to create an array of buttons, but I keep getting a npe
    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl<Container.java:1031>
    at java.awt.Container.add<container.Java:352>
    at ButtonArray.main<ButtonArray.java:26>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ButtonArray{
    static JLabel jl;
    public static void main(String[] args){
    JFrame jf = new JFrame();
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    jl = new JLabel();
    int count = 30;
    JButton[] jbh;
    jbh = new JButton[count];
    //JButton[] jbh = new JButton[]{new JButton("1"), new JButton("2")};
    for(int x=1; x<count; x++) {
         jbh[x] = new JButton(Integer.toString(x));
    Container c = jf.getContentPane();
    for(int i = 0; i < jbh.length; ++i){
    p1.add(jbh);
    for(int i = 0; i < jbh.length; ++i){
    jbh[i].addActionListener(new ButtonListener());
    c.add(p1, BorderLayout.NORTH);
    p2.add(jl);
    c.add(p2, BorderLayout.SOUTH);
    jf.setSize(400,300);
    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent evt){
    System.exit(0);
    static class ButtonListener implements ActionListener{
    public void actionPerformed(ActionEvent evt){
    jl.setText("Button" + evt.getActionCommand() + " was pressed");

    Just spotted the error.
    Your for loop adding buttons to the array begins at 1. Therefore there is a null still in position 0 of your array which you attempt to access in your next for loop.
    [shakes fist at Enc]
    Edited by: flounder on Aug 7, 2009 11:08 AM

  • Cannot add an action after I select my "Button" Symbol

    Ok, I have been following a whole bunch of tutorials, and a
    lot of the tutorials I've found are using Flash 8. I downloaded the
    trial for Flash CS3 and when I'm following the tutorial on adding
    an action, or link, to a button, they say...
    "Click the button"
    "Hit F9, to open the actions panel"
    Then for them, the action panel opens up and gives them the
    ability to add an action to their button, and in the upper left
    corner tab, they say to MAKE SURE IT SAYS "Actions - Button" and
    NOT "Actions - Frame"
    Well, in Adobe CS3 and actionscript, if I click on the button
    and hit F9, the action panel opens up, but I can't add an action to
    the button for some reason. I can only add it to "Action - Frame".
    Am I doing something wrong or what because I follow the
    tutorial exactly, but it seems like something changed in
    Actionscript 3.0 verses 2.0.
    If I Open a new file using Actionscript 2.0, everything works
    ok with the tutorial, but if I open a file withh 3.0 and try adding
    an action to a button, it doesn't work. Could anyone help me please
    or tell me what I'm doing wrong, thanks.

    AS3 no longer supports the attachment of code to Object
    instances, and requires code to be placed on the timeline, which is
    proper. Additionally, you will need to use the eventDispatcher
    model to 'connect' a responding function to the event and add an
    'event listener' to the Object. So basically the format for AS3
    code is something like:
    function stopTheThing(event:MouseEvent) {
    stop();
    my_btn.addEventListener(MouseEvent.CLICK,
    stopTheThing);

  • Getting the index of the button pressed in an array of buttons

    Hi,
    I have an array of buttons.
    JButton buttons[];
    buttons = new JButton[18];
    for(int idx = 0; idx<buttons.length; idx++)
    buttons[idx] = new JButton("changing button name");
    buttons[idx].addActionListener(this);
    locationButtonGrid.add(buttons[idx]);
    locationButtonGrid.validate();
    I need to know the index of the button pressed. I can't work from the string that is to be sent to the actionListener as this is going to be coming from a database and changing all the time. The idea behind it is that I am narrowing a list of entries down in a database by dividing it into 18 different sections, then dividing that section into 18 different sections and so on.
    I need to know which of the 18 buttons was pressed. Is this possible?
    Please let it be so!
    Cheers,
    elmicko

    Try this (my code is in bold):
    JButton buttons[];
    buttons = new JButton[18];
    for(int idx = 0; idx<buttons.length; idx++)
    buttons[idx] = new JButton("changing button name");
    buttons[idx].addActionListener(this);
    buttons[idx].setID( String.valueOf( idx ) );
    locationButtonGrid.add(buttons[idx]);
    locationButtonGrid.validate();
    In the listener (assuming event is evt):
    buttons[ Integer.parseInt(evt.getSource().getID()) ]
    or
    int idx = Integer.parseInt(evt.getSource().getID());
    buttons[idx]
    finally, if you want to modify the button when you get the event, you can just call the JButton methods by casting the source to a JButton and working from there.

  • Maybe you are looking for