java - Event on chekbox -
i'm developing java interface coding in swing
, use checkbox. when click on checkbox make continuous event (because in event make weft , send microcontroller) don't know how do. tried make actionlistener
make action 1 time.
who can me please ? :)
here code tried :
checkbox.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { // ------------------------------------------------------------| // déclaration des variables de la trame de la liaison // montante| // -----------------------------------------------------------| float capgps = -30; float longi = 30; float lat = 50; float h = 50; float capm = 50; float v = 50; float r = 50; float tsurvol = 50; float dist = 45; float phie = -30; float thetae = 30; float psie = 45; float psiscan = 30; float tfcam = 0; string strrealfr = thetafld.gettext(); float thetacam = float.valueof(strrealfr); float psicam = float.valueof(psifld.gettext()); byte[] length = new byte[1]; length[0] = 7; byte[] typemission = new byte[1]; typemission[0] = 1; // -----------------------------------------------------| // initialisation du tableau d'octets contenant la // trame| // ----------------------------------------------------| byte[] trame = new byte[0]; trame = tools.concatenatebytearrays(trame, "$".getbytes());// starflag trame = tools.concatenatebytearrays(trame, "!".getbytes());// flag nav trame = tools.concatenatebytearrays(trame, "m".getbytes());// mémorisation trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(capgps));// capgps trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(longi));// longitude trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(lat));// latitude trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(h));// altitude trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(capm));// cap // magnétque trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(v));// vitesse trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(r));// rayon de // révolution trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(tsurvol));// temps de // survol trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(dist));// distance trame = tools.concatenatebytearrays(trame, "rt".getbytes());// retour au point initial trame = tools.concatenatebytearrays(trame, "§".getbytes());// flag attitude trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(phie));// angle de // roulis trame = tools.concatenatebytearrays(trame, typemission);// type // de // mission trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(thetae));// angle de // tangage trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(psie));// angle de // lacet trame = tools.concatenatebytearrays(trame, "#".getbytes());// mode de fonctionnement trame = tools.concatenatebytearrays(trame, "o".getbytes());// marche/arret trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(-thetacam));// tangage // caméra trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(psicam));// angle de // lacet // caméra trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(psiscan));// vitesse // de // balayage // caméra trame = tools.concatenatebytearrays(trame, tools.convertsingletobytes(tfcam));// tems de // fonctionnement // de la // caméra trame = tools.concatenatebytearrays(trame, "*".getbytes());// fin de trame try { if (port != null) { fluxecriture.write(trame); } } catch (ioexception ex) { system.err.println(ex.getmessage()); } } // fin actionperformed });
(sorry bad english, i'm french student .... :/ )
you shouldn't doing non-gui related work on edt anyways.
create new java.util.timer
, call timer#scheduleatfixedrate
in actionperformed
method. do not use javax.swing.timer
, executes on edt, , seems dealing lot of non-gui related things in actionperformed
method. instead, use eventqueue.invokelater
post things gui related edt
you need pass scheduleatfixedrate
method timertask
(which contains code want execute repeatedly), delay amount (wait time befire starting task) , period amount (delay time between each execution):
java.util.timer timer = new java.util.timer(); actionlistener listener = new actionlistener() { @override public void actionperformed(actionevent e) { timer.scheduleatfixedrate(new timertask() { public void run() { //code execute repeatedly } }, 0, 0); };
Comments
Post a Comment