/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package slippb_applet; import java.net.MalformedURLException; import java.net.URL; import javax.swing.JApplet; /** * * @author Doys * @see นี่คือ Class แรกที่ Applet เรียกใช้งาน */ public class AppletPrinting extends JApplet { @Override public void init() { try { String printingName = getParameter("printingName"); String urlXmlData = getParameter("urlXmlData"); String urlXmlMaster = getParameter("urlXmlMaster"); String serverPBPath = getParameter("serverPBPath"); String clientPBPath = getParameter("clientPBPath"); String serverVersion = getParameter("serverVersion"); String serverFiles = getParameter("serverFiles"); boolean autoUpdate = getParameter("autoUpdate").equals("1"); AutoUpdate autoUp = new AutoUpdate(serverPBPath, clientPBPath, serverFiles, serverVersion); if (autoUpdate) { //เช็คการ update slip โดยเรียก auto update หากไม่มี update ก็ไม่ทำงานอะไร autoUp.UpdateVersion(); } if (autoUp.GetClientVersion().equals(serverVersion)) { //ใช้คำสั่ง command line เรียก pbslip.exe //String[] cmd = {clientPBPath + "\\pbslip.exe", printingName, urlXmlData, urlXmlMaster}; String cmd = clientPBPath + "slippb.exe " + "runtime®" + printingName + "®" + urlXmlMaster + "®" + urlXmlData; Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); //ปิด java applet อัตโนมัติ try { //Applet applet = (Applet) comp; this.getAppletContext().showDocument(new URL("javascript:window.close()")); System.exit(0); } catch (MalformedURLException me) { } } else { throw new Exception("PBSlip version ไม่ตรงกันกรุณา up date เป็น version " + serverVersion); } } catch (Exception ex) { Alert(ex.getMessage()); } } public void Alert(String alert) { try { this.getAppletContext().showDocument(new URL("javascript:alert(\"" + alert + "\")")); } catch (MalformedURLException me) { } } }