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);
}

Similar Messages

  • 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.

  • Bugreport: Apex 4.2.1 Button 'Return to application' doesn't return to app

    Hi there,
    I think there is a bug, when searching for a page number that doesn't exist in the application (e.g. typing error).
    When you edit a page and enter a page number where the page doesn't exist (that means in Field "go_to_page"), the error "Error processing condition. ORA-01403: no data found" appears correctly, but with button 'Return to application' you don't come back to the application.
    The same behavior is when you enter a non-existing page number in "Search Application" (P0_SEARCH) on the overview page of an application
    e.g. http://apex.oracle.com/pls/otn/
    WS: uBrennerDemo
    demo/demo
    Application: 61765 (Demo01)
    go to page: 5
    Regards Uli

    I get this a lot - it's frustrating!

  • 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 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

  • Applescript buttons returned from display dialog

    Hi!
    I have been learning Applescript for about a month and found the following issue which I thought was an easy implementation.
    On the "text returned" I get the error condition described. Do not understand!
    Any help would be appreciated.
    display dialog ("ENTER COMPANY NAME") with title ("TOTAL SHARE SPECIFICATION")
    buttons {"Cancel", "Company"} default button "Company" default answer ""
      set BUTTON_Returned to button returned of the result
      set CompanyName to text returned of the result
    error "Can’t get text returned of \"Company\"." number -1728 from text returned of "Company"
    MacBook 6.1     OS X Yosemite     Vn 10.10.1
    Script Editor  Vn. 2.7 (176)
    Applescript 2.4
    Regards

    No question that Applescript can be frustrating to learn. Many things about it have to be figured out by trial and error and when dealing with scripting applications all bets are off. The application designer can pretty much do as they want so what works in one app might not work in another even though you are using the same and correct applescript
    I find Introduction to AppleScript Language Guide by Apple to be a good source of answers and usually always have it open when I'm scripting  for quick reference.
    Spend some time getting familiar with the script editor. It is intelligent and can usually steer you in the right  direction when it comes to debugging.  Especially get use to and pay attention to the colors it assigns to items in your script.
    For example in your original script notice the colors of Button_Returned and CompanyName (your variables) and compare those to result and button returned. Also notice how text returned is a different color from button returned even though both are essentially the same thing. This is an indication that something is not right and it is where the error message occurred. (for a list of the default colors used open the Script Editors preferences and look at the Formatting tab).
    Notice  also how the editor formats your scripts, again the way the script gets formatted can tell you a lot if there is an error.
    Finally the error messages while cryptic can offer some clues. In your case the error message was
    error "Can’t get text returned of \"Company\"." number -1728 from text returned of "Company"
    generated by the line
    set CompanyName to text returned of the result
    The last part of the error message is essentially the line that caused the error after evaluation. So here result evaluated to “Company” which doesn't seem right, display dialog returns a record.
    Finally there is the log statement which will print its value to the log window
    Hope this helps
    regards

  • Applescript button returned of list

    Hi
    Here is my script:
    set firstList to {"Sincronizza proprietà avanzate", "Escludi proprietà avanzate"}
    set listchoice1 to choose from list firstList with prompt "Le proprietà avanzate di una cartella sono l'icona della cartella, la posizione degli elementii al suo interno e l'icona delle cartelle al suo interno." with title "Fai una selezione" without multiple selections allowed
    At the end of the list there are two buttons, "Ok" and "Cancel", if I select "Ok" it goes ahed, if I select "Cancel" it still goes ahed.
    Instead I want that if the button "Cancel" is selected, regardless of the choice made, the application must close.
    How can I do that?

    Returend result from choose from list
    Result
    If the user clicks the OK button, returns a list of the chosen number and/or text items; if empty selection is allowed and nothing is selected, returns an empty list ({}). If the user clicks the Cancel button, returns false
    So check to see if the result returned is false and if it is exit.
    Something like (there are other ways to do this)
    if listchoice1 is false then
         tell me to quit
    end

  • 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

  • Somehow the back button on my Safari browser got replaced with an autofill button; how do I get the back button returned to the toolbar?

    Somehow the back/forward button on my Safari browser got replaced with an autofill button; how do I get the back button returned to the toolbar and get rid of the autofill button

    Good to hear, Tom. Did you use "Customize" from the View Menu?

  • Hide button return delivery

    Hi all,
    Can anyone guide me how to hide the button return delivery. We don't want to use the function.
    Thank you for the help
    Gregor

    Hi Gregor,
    You can use the BBP_UI_CONTROL_BADI to hide this buttons.
    In this BADI, you have to create an implementation using the method BBP_CONF_UI_CTRL.
    Here is some sample code.
    IF sy-dynnr = '2310'.
    CASE iv_fieldname.
    WHEN ' the field name for the delivery return button'.
    cv_invisible = 'X'.
    ENDCASE.
    ENDIF.
    The parameter cv_invisible when has the value 'X' hides the button.
    Hope this helps.
    Thanks
    Pradeep

  • '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.

  • 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

  • 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);

  • 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.

  • 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

  • Maybe you are looking for

    • Refering Cells in webi for calculation

      Hi, We have done calculations separately in multiple reports. Please let me know as to how to refer/use those calculated values across any report, for example, where we could use a sum of a report (sum is assigned to a cell) which could be associated

    • Change future periods for Fiscal year variant-OB29

      Hi experts, We are using 4-4-5 rule, Fiscal year variant is M1, Future Periods for FY variant M1 is not maintained correctly.  Our year end is on 6/25/2011 but in our variant M1 it is defined as 7/2/2011 and periods following that are defined incorre

    • WorkFlow event

      hello everybody ... Please help me as to how to create a workflow event and how to trigger it when my me21n transaction is completed. what are the steps involved.. Please need this quite urgently.....

    • Java servlet

      I don t really know if this is the right place to post this message I have been developing java application and applet for a while and know i would like to start servlet but i am a little lost i am using eclipse 3.2 on mac os and i dont really where

    • Read internal table with key not equal to

      Hi, How can I read internal table with key not equal to some other field. Basically in read statement we can read only fields equal to others fields.