How do i trigger a button using keyboardstrokes

hello,
im trying to trigger my button using keyboard strokes. For example pressing ALT + S would trigger my addbutton.
and like A would trigger my exit. I tried using some keylisteners to my Jbuttons but cant seem to get it to work.
Am i heading in the right direction using keylisteners to try to activate my buttons or should i be using some else?
Any tips on how to use keyboardstrikes to trigger my buttons would be much appreciated.
this is some of my code. i excluded some parts such as my JLIST
if you would rather see the whole code let me know
public class Class
         public static void main(String[] args)
             JFrame frame = new FutureValueFrame();
             frame.setVisible(true);
     class FutureValueFrame extends JFrame
         public FutureValueFrame()
             setTitle("Task assignment");
             setResizable(false);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             JPanel panel = new FutureValuePanel();
             this.add(panel);
             this.pack();
             centerWindow(this);
         private void centerWindow(Window w)
             Toolkit tk = Toolkit.getDefaultToolkit();
             Dimension d = tk.getScreenSize();
             setLocation((d.width-w.getWidth())/2, (d.height-w.getHeight())/2);
class FutureValuePanel extends JPanel implements ActionListener,KeyListener
         private JButton   
                             addButton,
                             exitButton,
                             assignButton,
                             reportButton,
                             deleteButton;
         public FutureValuePanel()
   JPanel comboBoxButtonPanel = new JPanel();
             comboBoxButtonPanel.setLayout(new GridBagLayout());
assignButton = new JButton("Assign");
             addButton=new JButton("Add");
             addButton.addActionListener(this);
             addButton.addKeyListener(this);
             comboBoxButtonPanel.add(addButton, getConstraints(0,4,1,1, GridBagConstraints.WEST));
             exitButton=new JButton("Exit");
             exitButton.addActionListener(this);
             exitButton.addKeyListener(this);
             comboBoxButtonPanel.add( exitButton, getConstraints(0,6,1,1, GridBagConstraints.WEST));
             add(comboBoxButtonPanel,getConstraints(2,0,1,1, GridBagConstraints.WEST));
private GridBagConstraints getConstraints(int gridx, int gridy,
         int gridwidth, int gridheight, int anchor)
             GridBagConstraints c = new GridBagConstraints();
             c.insets = new Insets(5, 5, 5, 5);
             c.ipadx = 5;
             c.gridx = gridx;
             c.gridy = gridy;
             c.gridwidth = gridwidth;
             c.gridheight = gridheight;
             c.anchor = anchor;
             return c;
  public void actionPerformed(ActionEvent e)
             Object source = e.getSource();
             if (source == exitButton)
                 System.exit(0);
             else if (source == addButton)
                  Object[] options = {"Employee",
                "Project"};
                  int n = JOptionPane.showOptionDialog(null,
                            "Add a new Employee Project?",
                            "Add Record",
                                 JOptionPane.YES_NO_OPTION,
                                 JOptionPane.QUESTION_MESSAGE,
                                 null,    
                                 options, 
                                 options[0]);
                  if (n == JOptionPane.YES_OPTION)
                       String k;
                       k=  JOptionPane.showInputDialog("Enter the name of the employee(name cant be duplicated).");
                       JOptionPane.showMessageDialog(null,k+" has been sucessfully added");
                       employeeListModel.addElement(k);
                   if (n==JOptionPane.NO_OPTION)
                         String j;
                        j=  JOptionPane.showInputDialog("Enter the name of the project(name cant be duplicated).");
                        JOptionPane.showMessageDialog(null,j+" has been sucessfully added");
                        projectListModel.addElement(j);

thank u so much. I put Mnemonics on nearly all my Jbuttons but when i press a key. It does not trigger the actionPerformed event.
i changed my code to this
i still have issues when pressing e the gui does not close.
any tips on how to fix this?
exitButton=new JButton("Exit");
            exitButton.setMnemonic(KeyEvent.VK_E);
             exitButton.addActionListener(this);
         public void actionPerformed(ActionEvent e)
             Object source = e.getSource();
             if (source == exitButton)
                 System.exit(0);
            

Similar Messages

  • How can we prevent back button  using java script

    how can we prevent back button using java script

    Would be quicker for you to google for javaScript
    javascript:window.history.forward(-1);

  • How to display checkbox within button using skin?

    Hi,
    I am trying to put checkbox inside spark button using skin. The button looks like  -
    I want the button to repond mouse event (which is any way responding), but I also want check box too should respond to mouse event when mouse pointer is over check box.
    I am able to create button which looks like above. But when I move mouse pointer over button, the button look changed and looks like -
    As can be seen that there is no check box. I need check box to be shown always in button and should also be clickable.
    Do any one have idea how to solve it?
    Thanks,
    Prithveesingh Zankat.

    Hi,
    Here is complete skin code-
    <s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
                       minWidth="21" minHeight="21"
                       alpha.disabled="0.5"
                       width.up="84">
        <fx:Metadata>
            <![CDATA[
             * @copy spark.skins.spark.ApplicationSkin#hostComponent
            [HostComponent("spark.components.Button")]
            ]]>
        </fx:Metadata>
        <fx:Script fb:purpose="styling">
            <![CDATA[        
                import spark.components.Group;
                /* Define the skin elements that should not be colorized.
                For button, the graphics are colorized but the label is not. */
                static private const exclusions:Array = ["labelDisplay"];
                 * @private
                override public function get colorizeExclusions():Array {return exclusions;}
                 * @private
                override protected function initializationComplete():void
                    useChromeColor = true;
                    super.initializationComplete();
                 *  @private
                override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
                    var cr:Number = getStyle("cornerRadius");
                    if (cornerRadius != cr)
                        cornerRadius = cr;
                        shadow.radiusX = cornerRadius;
                        fill.radiusX = cornerRadius;
                        lowlight.radiusX = cornerRadius;
                        highlight.radiusX = cornerRadius;
                        border.radiusX = cornerRadius;
                    if (highlightStroke)
                        highlightStroke.radiusX = cornerRadius;
                    if (hldownstroke1)
                        hldownstroke1.radiusX = cornerRadius;
                    if (hldownstroke2)
                        hldownstroke2.radiusX = cornerRadius;
                    super.updateDisplayList(unscaledWidth, unscaledHeight);
                private var cornerRadius:Number = 2;
            ]]>       
        </fx:Script>
        <!-- states -->
        <s:states>
            <s:State name="up" />
            <s:State name="over" />
            <s:State name="down" />
            <s:State name="disabled" />
        </s:states>
        <!-- layer 1: shadow -->
        <!--- @private -->
        <s:Rect id="shadow" left="-1" right="-1" top="-1" bottom="-1" radiusX="2">
            <s:fill>
                <s:LinearGradient rotation="90">
                    <s:GradientEntry color="0x000000"
                                     color.down="0xFFFFFF"
                                     alpha="0.01"
                                     alpha.down="0" />
                    <s:GradientEntry color="0x000000"
                                     color.down="0xFFFFFF"
                                     alpha="0.07"
                                     alpha.down="0.5" />
                </s:LinearGradient>
            </s:fill>
        </s:Rect>
        <!-- layer 2: fill -->
        <!--- @private -->
        <s:Rect id="fill" left="1" right="1" top="1" bottom="1" radiusX="2">
            <s:fill>
                <s:LinearGradient rotation="90">
                    <s:GradientEntry color="0xFFFFFF"
                                     color.over="0xBBBDBD"
                                     color.down="0xAAAAAA"
                                     alpha="0.85" />
                    <s:GradientEntry color="0xD8D8D8"
                                     color.over="0x9FA0A1"
                                     color.down="0x929496"
                                     alpha="0.85" />
                </s:LinearGradient>
            </s:fill>
        </s:Rect>
        <!-- layer 3: fill lowlight -->
        <!--- @private -->
        <s:Rect id="lowlight" left="1" right="1" top="1" bottom="1" radiusX="2">
            <s:fill>
                <s:LinearGradient rotation="270">
                    <s:GradientEntry color="0x000000" ratio="0.0" alpha="0.0627" />
                    <s:GradientEntry color="0x000000" ratio="0.48" alpha="0.0099" />
                    <s:GradientEntry color="0x000000" ratio="0.48001" alpha="0" />
                </s:LinearGradient>
            </s:fill>
        </s:Rect>
        <!-- layer 4: fill highlight -->
        <!--- @private -->
        <s:Rect id="highlight" left="1" right="1" top="1" bottom="1" radiusX="2">
            <s:fill>
                <s:LinearGradient rotation="90">
                    <s:GradientEntry color="0xFFFFFF"
                                     ratio="0.0"
                                     alpha="0.33"
                                     alpha.over="0.22"
                                     alpha.down="0.12"/>
                    <s:GradientEntry color="0xFFFFFF"
                                     ratio="0.48"
                                     alpha="0.33"
                                     alpha.over="0.22"
                                     alpha.down="0.12" />
                    <s:GradientEntry color="0xFFFFFF"
                                     ratio="0.48001"
                                     alpha="0" />
                </s:LinearGradient>
            </s:fill>
        </s:Rect>
        <!-- layer 5: highlight stroke (all states except down) -->
        <!--- @private -->
        <s:Rect id="highlightStroke" left="1" right="1" top="1" bottom="1" radiusX="2" excludeFrom="down">
            <s:stroke>
                <s:LinearGradientStroke rotation="90" weight="1">
                    <s:GradientEntry color="0xFFFFFF" alpha.over="0.22" />
                    <s:GradientEntry color="0xD8D8D8" alpha.over="0.22" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Rect>
        <!-- layer 6: highlight stroke (down state only) -->
        <!--- @private -->
        <s:Rect id="hldownstroke1" left="1" right="1" top="1" bottom="1" radiusX="2" includeIn="down">
            <s:stroke>
                <s:LinearGradientStroke rotation="90" weight="1">
                    <s:GradientEntry color="0x000000" alpha="0.25" ratio="0.0" />
                    <s:GradientEntry color="0x000000" alpha="0.25" ratio="0.001" />
                    <s:GradientEntry color="0x000000" alpha="0.07" ratio="0.0011" />
                    <s:GradientEntry color="0x000000" alpha="0.07" ratio="0.965" />
                    <s:GradientEntry color="0x000000" alpha="0.00" ratio="0.9651" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Rect>
        <!--- @private -->
        <s:Rect id="hldownstroke2" left="2" right="2" top="2" bottom="2" radiusX="2" includeIn="down">
            <s:stroke>
                <s:LinearGradientStroke rotation="90" weight="1">
                    <s:GradientEntry color="0x000000" alpha="0.09" ratio="0.0" />
                    <s:GradientEntry color="0x000000" alpha="0.00" ratio="0.0001" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Rect>
        <!-- layer 7: border - put on top of the fill so it doesn't disappear when scale is less than 1 -->
        <!--- @private -->
        <s:Rect id="border" left="0" top="0" bottom="0" radiusX="2"
                right.disabled="0" width.disabled="69" height.disabled="20"
                right.down="0" width.down="69" height.down="20"
                right.over="0" width.over="69" height.over="20"
                left.up="0" right.up="0" top.up="0" bottom.up="0">
            <s:stroke>
                <s:LinearGradientStroke rotation="90" weight="1">
                    <s:GradientEntry color="0x000000"
                                     alpha="0.5625"
                                     alpha.down="0.6375" />
                    <s:GradientEntry color="0x000000"
                                     alpha="0.75"
                                     alpha.down="0.85" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Rect>
        <!-- layer 8: text -->
        <!--- @copy spark.components.supportClasses.ButtonBase#labelDisplay  -->
        <s:Label id="labelDisplay" left="10" top="2" bottom="2" maxDisplayedLines="1" textAlign="center"
                 verticalAlign="middle"
                 right.disabled="10" horizontalCenter.disabled="0" verticalCenter.disabled="1"
                 left.down="20" right.down="5" top.down="2" bottom.down="2" horizontalCenter.down="7"
                 left.over="20" right.over="5" top.over="2" bottom.over="2" horizontalCenter.over="7"
                 left.up="20"  right.up="5"    top.up="2"   bottom.up="2"   horizontalCenter.up="7"
                 verticalCenter.up="2">
        </s:Label>
        <s:CheckBox includeIn="up" left="2" top="2" bottom="2" width="16" verticalCenter="0"
                    right.disabled="10" horizontalCenter.disabled="0" verticalCenter.disabled="0" width.disabled="18"
                    left.down="2" top.down="2" bottom.down="2" verticalCenter.down="0" width.down="18"
                    left.over="0" top.over="2" bottom.over="2" verticalCenter.over="0" width.over="18"
                    left.up="2"   top.up="2"   bottom.up="2"   verticalCenter.up="0"   width.up="18"
                    />
    </s:SparkButtonSkin>
    Thank,
    Prithveesingh Zankat.

  • How to Create a Radio Buttons using Personlization

    Hi friends ,
    We have  requierment like , Wanted to havev two radio buttons  Employee Relative  : YES or NO values.
    These radio buttons I wanted to add on Oracle Provided page using personlization. But the Values for the radio buttons should be YES and another button is No.
    After addin it , we shall have this selected value handled in Custom Controller. How can I the radio Buttons with the above YES/No Values. Any guidelines would be greatly helpful.
    Thanks Guys
    Regards
    Raghu

    Hi,
    Using personalization you can create radio button s, the item style as: Message Radio Button
    and then extend the controller and use the below code in processrequest of the extended or custom controller:
    OAMessageRadioButtonBean appleButton = 
    (OAMessageRadioButtonBean)webBean.findChildRecursive("GroupButtonOne"); //First Radio Button 
    appleButton.setName("Yes"); 
    appleButton.setValue("Yes"); 
    OAMessageRadioButtonBean orangeButton = 
    (OAMessageRadioButtonBean)webBean.findChildRecursive("GroupButtonTwo"); //Second Radio Button 
    orangeButton.setName("No"); 
    orangeButton.setValue("No"); 
    May be it will help you.
    Regards
    Mahesh

  • How to select a radio button using javascript?

    Hi,
    I have 2 radio buttons as shown below:
    <input id="poBoxRadio" name="poBoxRadio" type="radio" class="radio-btn" value="No" /> No
    <input id="poBoxRadio" name="poBoxRadio" type="radio" class="radio-btn" value="Yes" /> YesI want to select one of this radio button, according to the following condition in javascript:
    <script type="text/javascript">
    if (<%=option1%> != ""){
         // Radiobutton "No" should be selected.
    else if (<%=option2%> != ""){
         // Radiobutton "Yes" should be selected.
    </script>How can I do this in Javascript? Any help will be highly appreciated.
    Thanks,
    Rishi

    I have solved this issue using the following:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    var a='', b='d';
    </script>
    </head>
    <body>
    <input id="poBoxRadioNo" name="poBoxRadio" type="radio" class="radio-btn" value="No" /> No
    <input id="poBoxRadioYes" name="poBoxRadio" type="radio" class="radio-btn" value="Yes" /> Yes
    <script type="text/javascript" defer="defer">
    <!--
    if(document.getElementById){
    if (a != ""){
    // Radiobutton "No" should be selected.
    document.getElementById('poBoxRadioYes').checked = false;
    document.getElementById('poBoxRadioNo').checked = true;
    else if (b != ""){
    // Radiobutton "Yes" should be selected.
    document.getElementById('poBoxRadioNo').checked = false;
    document.getElementById('poBoxRadioYes').checked = true;
    // -->
    </script>
    <input disabled type="button" value="UP" onclick="setVariable('move=1')">
    </body>
    </html>Thanks to all of you!

  • How to show ok & cancel button using showMessageDialog

    hi to all, when i use showMessageDialog it gives only ok option,
    like
    JOptionPane.ShowMessageDialog(null,"are you sure you want to continue" ,"Confirmation",JOptionPane.QUESTION_MESSAGE);
    this statement shows only ok option, i want ok and cancel option both.
    and can u tell me how to put actions in ok & cancel option
    like if user clicks ok option then he can continue the program , if user clicks cancel then he would exit from the program.
    can u tell how to comapre that using if statement
    please reply me as soon as possible.

    This is probably close to what you want. I believe messages can be replaced by null. You can probably figure out the rest from the API.
    response = JOptionPane.showConfirmDialog(myFrame,
                                             messages,
                                            "Delete hard drive?",
                                             JOptionPane.OK_CANCEL_OPTION);
    // If User hit CANCEL button we jump out
    if (response == JOptionPane.CANCEL_OPTION)
        return;

  • How to make a back button using AS3

    I'm trying to do my first project using ActionScript in CS4. I need to make a back button that will take the user back to the last "slide" they were on.
    I went through the effort of creating a back button that I only realized didn't work after I was finished. I had it set up to just go to the previous slide and totally ignored the fact that there are several branching scenarios.

    I'm more or less having to teach myself at this point. Where should I go to learn about using an array?

  • JDeveloper - How to create a "back button" using JSF

    As simple as it sounds, I'm having trouble creating a basic back button on my JSF page. I'm using a af:goButton with the Onclick attribute stating history.back(). I've also tried history.go(-1) to no avail.... is there a trick to this?
    Thanks,
    Richard

    If you are looking for a more advanced case as describe, you will need to reference the last navigation outcome in a managed bean so that you can execute it when the back button is clicked.
    --Ric                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to create a BRowse button using Swing?

    I want to create a browse button with the help og which i want to browse a file..
    please can anyone help me

    Bookmark the API (or search the downloads section if you want to get an offline set)
    {color:0000ff}http://java.sun.com/javase/6/docs/api/{color}
    JFileChooser:
    {color:0000ff}http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html{color}
    db

  • How to Disable the SUBMIT Button using the formula.

    Hi. Govindu and ohters.
                       I really appreciate your efforts in helping others.
    I am currently working with VC 7.0. Where I am working with Validation of Data.
    we have input buttons( fields) like Emp, Earea, Joining date (month & Year), Ending date((month & Year) etc.,
    Here we have one submit button 'submit'.
    Here what my client asks is unless and until, user fills all details then only
    the submit button should be enabled. Otherwise submit button should be in disable mode.
    I could be able to write formula for 'submit' button's properties( Disable) like this.
    BOOL(IF(LEN(@Emp_code)0 AND LEN(@Earea)0 AND LEN(@Edept)0 AND DSUB(DVAL(@Joining_date), DVAL(@Ending_date),'D')<0 ,false,true))
    Here condition is always make sure that 'Joining date' should be greater than 'Ending date' . where it is working fine for all fields except Calender Year month(Joining date & Ending date).
    the calender year month format is Example : """" May 2007""""
    But it is considering only month But not year.
    Can you kindly provide your inputs.
    Edited by: Vijay Kumar on Dec 2, 2008 10:51 AM

    Hi. Murtuza.
                        Thanks for Your valueable reply. I have already been trying with the following formula.
    But still I am not getting expected result.
                   BOOL(IF(LEN(@Material_Type)<>0 AND  LEN(@Plant)<>0 AND LEN(@Vendor)<>0 AND
                                           DSUB(DVAL(@To), DVAL(@Calendar_Year_Month),'D')<0 ,false,true))
                    I don't have any problem with   input buttons( fields) like Material type, Plant, Vendor.
                 But _'Calender Year  Month From'  should be  less than  to 'Calender Month To' then only the submit button should be enabled. Otherwise submit button should be in disable mode. This is not working.
                                     The calender year month format is Example : """" May 2007""""
                                                But it is considering only month But not year. 
       means It only considering Month only, It is not considering the Year. Please let me know the your information on this.
                                Thanks and Regards
    Edited by: Vijay Kumar on Dec 3, 2008 10:35 AM

  • How can block firefox back button {using some language..}

    Like This links...
    [http://example.com https://careers.infosys.com/sap/bc/webdynpro/sap/hrrcf_a_unreg_job_search?sap-client=400]

    Would be quicker for you to google for javaScript
    javascript:window.history.forward(-1);

  • How to trigger button using shortcut keys

    Hi Friends i want to trigger a button in java swings using keyboard keys.
    for ex: a button called "Enter" either i click mouse or i press ALT+E to trigger it.
    Plz give me sample coding if u have
    By
    vinod

    Try looking at the tutorials...
    http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

  • How to create a radio button on OA Page using Personalization

    I am trying to create a radio button on OA Page using Personalization. The item style , I can see is Message Radio Group.
    How to create Message Radio Button and bring them under one group.
    Thanks

    You should use jdev to define a radiogroup and radio buttons under that, wrap that definition inside a stackLayout in jdev, use personalization to add a stackLayout and extend the region which you had created earlier in jdev.

  • How to trigger a workflow using generic object services?

    Hi Experts,
    Let me know on how to trigger a workflow using generic object services.
    My requirement is to trigger the FI document reversal document using Object services.
    Any info or docs relevant to this, please share with me..
    Thanks,
    Dinesh.

    Dinesh,
    First of you need to check if the transaction has a BO (in released status) published to use the GOS.
    These are the pre-requisites for GOS
    http://help.sap.com/saphelp_46c/helpdata/en/94/aa532cddd511d289860000e8216438/content.htm
    Once done.. check that you have valid workflow linkages active for this BO.
    Now when you click on the 'start workflow' the system will show all relevant workflows for the BO to choose from and to start.

  • I have a Mac Air. I use the mail application all the time.. The red, yellow, and green buttons disappeared at the top of screen... now i have to force quit mail.. how do it get the buttons back?

    I have a Mac Air. I use the mail application al the time. THe red, yellow, and green buttons disappeard. i have to force-quit now to close mail.. How do i get the buttons back? thanks.

    Mail window may be in the Full Screen mode.
    Move the mouse pointer to the top right corner of the Mail window and hold it there.
    Menu bar should drop down and click the blue double arrow icon.
    Full Screen toggle shortcut:  control + command + F

Maybe you are looking for

  • Are software updates linked to the warrenty?

    Hi I have a laptop I purchased in mid 2013, I noticed that for quite a long time I don't get any alerts about software updates from HP Support assistant. Is this related to the warrenty expiring in mid 2014? Can't I get automatic updates anymore? If

  • Regarding user interface in LINUX for smartforms

    Hi Friends,            we run SAP on Linux platform.. we encountered a problem that , when we open SMARTFORMS   Tcode and create a new form,  it says that the user interface for the function is not supported by the OS.. what is the remedy for this..

  • Discover: error: The file /a.out was linked by an older link step. Please use the latest compiler to do the link.

    Hi, I have installed Solaris studio and wanted to use the memory analyzer from there. I am trying it on a sample program, but it returns the above error and does not instrument the executable. Could you please help me tracing where am I going wrong.

  • FM HR_CHECK_AUTHORITY_INFTY is failing

    Hi, I am logging in to ESS portal with two different IDs, which has same roles. For one ID it is returning the value as no_authorization whereas for the other ID, it is returning the value as Authorised.. Both the IDS have the same roles and profiles

  • Displaying Internal Link Properties in colletion Rendrer

    Dear Experts, I want to display the propeties of the Internal link in a colletion rendrer. When I try to do the same, Collection render is displaying the properties of the linked file in the link, where as I want display the properties of the link wh