joystick event in java -


i have java application containing 1 text-field , i'm using joystick.

how can in text-field when button on joystick pressed?

/*  * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */    package op;  import net.java.games.input.controller;  /**  *  * @author ahmed  */ public class test extends javax.swing.jframe {      /**      * creates new form test      */     public test() {         initcomponents();         con();     }      private void con(){          jinputjoystick joystick = new jinputjoystick(controller.type.stick);         if( !joystick.iscontrollerconnected() ){                txt.settext("not connected");         }         else                txt.settext(joystick.getcontrollertype()+" "+joystick.getcontrollername()+" controller cound!");         if( !joystick.pollcontroller() ) {              txt.settext("controller disconnected!");         }         // number of buttons.      }      /**      * method called within constructor initialize form.      * warning: not modify code. content of method      * regenerated form editor.      */     @suppresswarnings("unchecked")     // <editor-fold defaultstate="collapsed" desc="generated code">                               private void initcomponents() {          txt = new javax.swing.jtextfield();          setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);          javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());         getcontentpane().setlayout(layout);         layout.sethorizontalgroup(             layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)             .addgroup(layout.createsequentialgroup()                 .addgap(70, 70, 70)                 .addcomponent(txt, javax.swing.grouplayout.default_size, 242, short.max_value)                 .addgap(88, 88, 88))         );         layout.setverticalgroup(             layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)             .addgroup(layout.createsequentialgroup()                 .addgap(122, 122, 122)                 .addcomponent(txt, javax.swing.grouplayout.preferred_size, 33, javax.swing.grouplayout.preferred_size)                 .addcontainergap(145, short.max_value))         );          pack();     }// </editor-fold>                              /**      * @param args command line arguments      */       // variables declaration - not modify                          private javax.swing.jtextfield txt;     // end of variables declaration                    } 

based on tutorial project here: https://theuzo007.wordpress.com/2013/10/26/joystick-in-java-with-jinput-v2/ looks have loop , check things, so

private void con(){     jinputjoystick joystick = new jinputjoystick(controller.type.stick);     while (joystick.iscontrollerconnected()) {         // go trough components of controller.         component[] components = joystick.getcomponents();         for(int i=0; < components.length; i++) {             component component = components[i];             identifier componentidentifier = component.getidentifier();              // buttons             if(componentidentifier.getname().matches("^[0-9]*$")){ // if component identifier name contains numbers, button.                 // button pressed?                 if(component.getpolldata() != 0.0f) {                     txt.settext("button got pressed!")                 }             }         }          // have give processor rest.         try {             thread.sleep(25);         } catch (interruptedexception ex) {             logger.getlogger(joysticktest.class.getname()).log(level.severe, null, ex);         }     }     txt.settext("controller not connected"); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -