java - .jar not doing the same thing that in Eclipse -
i created .jar eclipse app. export -> jar file -> choose package + lib -> define main class program use rxtx lib.
here mainframe :
package main; import gnu.io.commportidentifier; import gnu.io.serialport; import java.awt.borderlayout; ... public class mainframe{ public final static string pathlogo1 = "a:/icomssoft/ivt corporation/bluesoleil/icon-logo.png"; public final static string pathlogo2 = "a:/icomssoft/ivt corporation/bluesoleil/icoms logo.jpg"; public final static string pathbluesoleilicon = "a:/icomssoft/ivt corporation/bluesoleil/bluetoothimage.png"; protected static final jcombobox<string> jb_choixportcom = null; static jbutton jb_connect; static string choixportcom = null; //********************************************************************************** //************************ rxtx variable ******************************************* //********************************************************************************** static commportidentifier serialportid; static enumeration<?> enumcomm; static serialport serialport; static outputstream outputstream; static inputstream inputstream; static boolean serialportcheck = false; static int baudrate = 9600; static int databits = serialport.databits_8; static int stopbits = serialport.stopbits_1; static int parity = serialport.parity_none; jpanel panel = new jpanel (new gridbaglayout()); jpanel panelsetup = new jpanel(new gridbaglayout()); jpanel panelcommunication = new jpanel(new gridbaglayout()); static jcombobox<string> selection = new jcombobox<string>(); jbutton open = new jbutton("open"); jbutton close = new jbutton("close"); jbutton actualise = new jbutton("actualisé"); jbutton envoie = new jbutton("message envoie"); jtextfield message = new jtextfield(); jcheckbox echo = new jcheckbox("echo"); static jtextarea recoit = new jtextarea(); jscrollpane recoitjscrollpane = new jscrollpane(); //********************************************************************************** //********************************************************************************** //********************************************************************************** public static void fenetreprincipal() { final jframe jf_principal = new jframe("icomssoft"); jf_principal.setvisible(true); jf_principal.setsize(1000,900); jf_principal.setlocationrelativeto(null); jf_principal.setresizable(false); jf_principal.seticonimage(toolkit.getdefaulttoolkit().getimage(pathlogo1)); //****************************************************************************************** //******************************** jpanel north ******************************************** //****************************************************************************************** jpanel jp_north = new jpanel(); // container du borderlayout.north jp_north.setpreferredsize(new dimension(600,150)); jpanel jp_logo = new jpanel(); // container du jlabel jp_logo.setbackground(color.white); jlabel jl_logo = new jlabel(new imageicon(pathlogo2)); jp_logo.add(jl_logo); jp_north.add(jp_logo); jp_north.setbackground(color.white); jp_north.setvisible(true); //****************************************************************************************** //******************************** jpanel center ******************************************** //****************************************************************************************** final jpanel jp_center = new jpanel(); jp_center.setpreferredsize(new dimension(600,700)); // 900- 600 = 300 left jp_center.setbackground(color.white); final jpanel jp_choixconnection = new jpanel(); jp_choixconnection.setborder(borderfactory.createtitledborder("choix connection : ")); jp_choixconnection.setpreferredsize(new dimension(540, 175)); jp_choixconnection.setbackground(color.white); imageicon pic = new imageicon(pathbluesoleilicon); jbutton jb_launchbluesoleil = new jbutton(pic); jb_launchbluesoleil.setpreferredsize(new dimension(100, 135)); jp_choixconnection.add(jb_launchbluesoleil); jp_center.add(jp_choixconnection); //****************************************************************************************** //******************************** jpanel south ******************************************** //****************************************************************************************** jpanel jp_south = new jpanel(); jp_south.setbackground(color.white); jp_south.setpreferredsize(new dimension(600,50)); jpanel jp_bouton = new jpanel(); jp_bouton.setbackground(color.white); jbutton jb_quit = new jbutton("quitter"); jb_quit.setpreferredsize(new dimension(85, 35)); jp_south.add(jp_bouton); jp_bouton.add(jb_quit); jf_principal.getcontentpane().add(jp_north, borderlayout.north); jf_principal.getcontentpane().add(jp_center, borderlayout.center); jf_principal.getcontentpane().add(jp_south, borderlayout.south); jf_principal.setvisible(true); //****************************************************************************************** //******************************** action listener ***************************************** //****************************************************************************************** jb_launchbluesoleil.addactionlistener(new actionlistener(){ public void actionperformed(actionevent arg0) { try { bluetooth.launch(bluetooth.getpath()); } catch (ioexception e) { e.printstacktrace(); } string[] listportcom = rxtx.getportcom(); int nbrport = integer.parseint(listportcom[99]); // string -> int final jpanel jp_choixportcom = new jpanel(); jp_choixportcom.setborder(borderfactory.createtitledborder("choix port com : ")); jp_choixportcom.setpreferredsize(new dimension(500, 100)); jp_choixportcom.setbackground(color.white); final jcombobox<string> jb_choixportcom = new jcombobox<string>(); for(int = 0; < nbrport; i++) jb_choixportcom.additem(listportcom[i]); jb_connect = new jbutton("connect"); jp_choixportcom.add(jb_choixportcom); jp_choixportcom.add(jb_connect); jp_center.add(jp_choixportcom); system.out.println("jp_choixconnection -> bye bye"); jp_choixconnection.setvisible(false); communicationbt.bt(jp_center); jb_choixportcom.additemlistener(new itemlistener(){public void itemstatechanged(itemevent e) { choixportcom = (string)jb_choixportcom.getselecteditem(); }}); jb_connect.addactionlistener(new actionlistener(){ public void actionperformed(actionevent arg0) { if (choixportcom.equals(null) == true ) joptionpane.showmessagedialog(null, "choose port com"); else rxtx.checkport(choixportcom); } }); } }); jb_quit.addactionlistener(new actionlistener(){ public void actionperformed(actionevent arg0) { jf_principal.dispose(); } }); } public static void main(string[] args) throws ioexception, interruptedexception { fenetreprincipal(); } }
and here call getportcom :
package main; import gnu.io.*; // rxtx import java.io.ioexception; import java.io.inputstream; import java.io.outputstream; import java.util.enumeration; public class rxtx { static commportidentifier serialportid; static enumeration<?> enumcomm; static serialport serialport; static outputstream outputstream; static inputstream inputstream; int baudrate = 9600; int databits = serialport.databits_8; int stopbits = serialport.stopbits_1; int parity = serialport.parity_none; static boolean serialportcheck = false; public static string[] getportcom(){ string[] list = new string[100]; // list[99] = nbrport int nbrport = 0; commportidentifier serialportid; enumeration<?> enumcomm; enumcomm = commportidentifier.getportidentifiers(); while (enumcomm.hasmoreelements()) { serialportid = (commportidentifier) enumcomm.nextelement(); if(serialportid.getporttype() == commportidentifier.port_serial) { //system.out.println(serialportid.getname()); list[nbrport] = serialportid.getname(); nbrport++; } list[99] = integer.tostring(nbrport); // int -> string } (int = 0; < nbrport; i++) { system.out.println(list[i]); } return list; } public static boolean checkport(string portname){ boolean foundport = false; if (serialportcheck != false) { system.out.println("serial port déjà ouvert"); return true; } enumcomm = commportidentifier.getportidentifiers(); while(enumcomm.hasmoreelements()) { serialportid = (commportidentifier) enumcomm.nextelement(); if (portname.contentequals(serialportid.getname())) { foundport = true; break; } } if (foundport != true) { system.out.println("serialport pas trouver: " + portname); return false; } try { serialport = (serialport) serialportid.open("ouvert + envoie", 500); } catch (portinuseexception e) { system.out.println("port -> ok"); } try { outputstream = serialport.getoutputstream(); } catch (ioexception e) { system.out.println("probleme en outputstream"); } try { inputstream = serialport.getinputstream(); } catch (ioexception e) { system.out.println("probleme en inputstream"); } serialportcheck = true; return true; } the thing don't understand why works in eclipse not jar, path correct don't :/
more information :
so app call program(bluesoleil) when click on button. problem .jar, when click on button program launchs correctly block there rest doesn't appear. suppose change jp_center (jpanel) switching jpanel -> launch getportcom , create jcombobox portcom available.
Comments
Post a Comment