SIIJ.JAVA

Electronics For You - - CONSTRUCTION -

Data:”);

Jla­bel bud­lab = new Jla­bel(“bu­drate:”);

Jla­bel data­lab = new Jla­bel(“databit:”);

Jla­bel par­ity­lab = new Jla­bel(“par­ity:”);

Jla­bel sto­plab = new Jla­bel(“stop­bits:”);

Di­men­sion scrn = Toolkit.get­de­fault­Toolkit().getscreen­size();

frame. set­bounds( scrn. width/ 2200,scrn.height/2-130,480,275);

frame.seti­con­im­age(new Image­icon(cl. ge­tre­source(“pic/eg_i­con/eg_i­con.jpg”)). getim­age());

frame.set­de­fault­close­op­er­a­tion (JFRAME.DO_NOTHING_ON_CLOSE); frame.se­tre­siz­able(false); frame.ad­dwin­dowlis­tener(new Win­dowadapter() {

public void win­dow­clos­ing(win­dow­event e) { frame.setvis­i­ble(false); tray.get­tray­i­con(). dis­playmes­sage(“se­rial Port In­ter­fac­ing”,”pro­gram is run­ning”,tray­i­con.mes­sagetype.info);

} }); frame.get­root­pane(). set­de­fault­but­ton(snd­but); rec­scrl.setho­r­i­zon­talscroll­bar­pol­icy(js CROLLPANE.HORIZONTAL_SCROLLBAR_NEVER);

rec­scrl.setver­ti­calscroll­bar­pol­icy(js CROLLPANE.VERTICAL_SCROLLBAR_ALWAYS);

snd­scrl.setho­r­i­zon­talscroll­bar­pol­icy (JSCROLLPANE.HORIZONTAL_SCROLLBAR_NEVER); snd­scrl.setver­ti­calscroll­bar­pol ICY(JSCROLLPANE.VERTICAL_SCROLLBAR_ALWAYS); rectext.sete­d­itable(false); snd­text.sete­d­itable(false); clrchk.set­s­e­lected(true); snd­but.seten­abled(false); bu­drate.set­max­i­mum­row­count(5); bu­drate.set­s­e­lecte­din­dex(6); databit.set­s­e­lecte­din­dex(3); re­clab.set­bounds(10,10,85,20); snd­lab.set­bounds(180,10,70,20); rec­scrl.set­bounds(10,35,150,125); snd­scrl.set­bounds(180,35,150,125); snd­but.set­bounds(353,10,98,20); clr­but.set­bounds(353,45,98,20); con­nect­but.set­bounds(353,80,98,20); se­ri­al­port.set­bounds(353,115,98,20); clrchk.set­bounds(360,150,90,20); snd­but.setm­nemonic(‘s’); clr­but.setm­nemonic(‘c’); frm­pan.set­lay­out(null); frm­pan.add(re­clab); frm­pan.add(rec­scrl); frm­pan.add(snd­scrl); frm­pan.add(snd­lab); frm­pan.add(snd­but); frm­pan.add(clr­but); frm­pan.add(con­nect­but); frm­pan.add(se­ri­al­port); frm­pan.add(clrchk); se­ri­al­pan.add(bud­lab); se­ri­al­pan.add(bu­drate); se­ri­al­pan.add(data­lab); se­ri­al­pan.add(databit); se­ri­al­pan.add(par­ity­lab); se­ri­al­pan.add(par­ity); se­ri­al­pan.add(sto­plab); se­ri­al­pan.add(stop­bit); snd­but.ad­dac­tion­lis­tener(this); clr­but.ad­dac­tion­lis­tener(this); con­nect­but.ad­dac­tion­lis­tener(this); se­ri­al­port.ad­ditem­lis­tener(new com­boboxlis­tener());

frame.get­con­tent­pane(). add(frm­pan,bor­der­lay­out.cen­ter);

frame.get­con­tent­pane(). add(se­ri­al­pan,bor­der­lay­out.north);

frame.get­con­tent­pane().add(new JLA­bel(“De­vel­oped by Muhammad Aj­mal P”),bor­der­lay­out.south);

frame.setvis­i­ble(true); } public static void main(string[] args)

SIIJ siij = new SIIJ(); } pri­vate void set­com­bobox(boolean chs) bu­drate.seten­abled(chs); databit.seten­abled(chs); stop­bit.seten­abled(chs); par­ity.seten­abled(chs); se­ri­al­port.seten­abled(chs); } public void ac­tion­per­formed(ac­tion­event ae) { if(ae.get­source() == snd­but) try {

int rec­value = In­te­ger.

if(rec­value >= 0 && rec­value <= 255) sdata.send­value(rec­value);

else Jop­tion­pane.showmes­sage­di­alo g(frame,”in­va­lied In­put\nen­ter a value be­tween 0 - 255”,”Er­ror”,jop­tion­pane. ERROR_ MES­SAGE, new Image­icon( cl. ge­tre­source(“pic/siij/err.png”))); } catch(ex­cep­tion e) {

Jop­tion­pane. showmes­sage­di­a­log( frame,”in­va­lied In­put\nen­ter a value be­tween 0 - 255”,”Er­ror”,jop­tion­pane. ERROR_ MES­SAGE, new Image­icon( cl. ge­tre­source(“pic/siij/err.png”)));

}

if( clrchk. is­s­e­lected()) set­text(“”); } else if(ae.get­source() == clr­but) { rectext.set­text(“”); snd­text.set­text(“”); } else if(ae.get­source() == con­nect­but) { if(con­nect­but.is­s­e­lected()) {

sdata.set­port­data(bu­drate.get­s­e­lecte­ditem().tostring()

, databit. get­s­e­lecte­ditem(). tostring(),par­ity.get­s­e­lecte­din­dex() ,stop­bit.get­s­e­lecte­din­dex()); con­nect­but.set­text(“dis­con­nect”); sdata.set­con­nec­tion(true); set­com­bobox(false); snd­but.seten­abled(true);

{ } }

snd­fld. } else { con­nect­but.set­text(“con­nect”); sdata.set­con­nec­tion(false); set­com­bobox(true); snd­but.seten­abled(false);

}

}

} class com­boboxlis­tener im­ple­ments ItemLis­tener {

public void item­stat­e­changed(ite­mevent ie) {

if(ie.get­source() == se­ri­al­port && ie.get­stat­e­change() == Ite­mevent.se­LECTED) {

sdata.set­por­tid(se­ri­al­port.get­s­e­lecte­ditem().tostring());

Sys­tem. out. println (“COM port changed - “+ se­ri­al­port. get­s­e­lecte­ditem().tostring());

} }

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.