import java.awt.*; import java.net.*; import java.io.*; import java.util.*; import sun.io.*; public class dbAccess extends java.applet.Applet { String url; String path; Font fn; int bgr; int bgg; int bgb; int textr; int textg; int textb; Color backcolor; Color textcolor; String fonttype; String message = ""; String endmark = "******"; int fontsize; int msgx; int msgy; int TotalLines; public String ReceivedData[]; public String toSQL(String s) { try { CharToByteConverter toByte = CharToByteConverter.getConverter("Big5"); byte[] orig = toByte.convertAll(s.toCharArray()); char[] dest = new char[orig.length]; for ( int i = 0; i < orig.length; i++ ) dest[i] = (char)(orig[i] & 0xFF); return new String(dest); } catch ( Exception e ) { ShowMessage(e.toString()); return s; } } public String fromSQL(String s) { int i, j; char[] orig = s.toCharArray(); byte[] dest = new byte[orig.length]; for ( i = 0; i < orig.length; i++ ) dest[i] = (byte) (orig[i]&0xFF); try { ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5"); return new String(toChar.convertAll(dest)); } catch ( Exception e ) { ShowMessage(e.toString()); return s; } } public void ShowMessage(String msg) { message = msg; repaint(); } public String Request(String requrl, String reqpath, String reqparm) { String msg; String buffer; msg = "http://" + requrl + reqpath + reqparm + ": Connect Server. . . . . ."; ShowMessage(msg); try { URL serverURL = new URL("http://" + requrl + reqpath + reqparm); URLConnection connection = serverURL.openConnection(); DataInputStream inStream = new DataInputStream(connection.getInputStream()); TotalLines = 0; while ( true ) { buffer = inStream.readLine(); if ( buffer.equals(endmark) ) break; ReceivedData[TotalLines] = fromSQL(buffer); TotalLines++; } inStream.close(); } catch (MalformedURLException mfURLe) { msg = "MalformedURLException: " + mfURLe; ShowMessage(msg); return(msg); } catch (IOException ioe) { msg = "IOException: " + ioe; ShowMessage(msg); return(msg); } msg = " "; ShowMessage(msg); return("OK"); } public String GetData(int index) { return ReceivedData[index]; } public String JSRequest(String str) { return Request(url, path, str); } public void init() { url = getParameter("url"); path = getParameter("path"); fonttype = getParameter("fonttype"); fontsize = Integer.parseInt(getParameter("fontsize")); bgr = Integer.parseInt(getParameter("bgr")); bgg = Integer.parseInt(getParameter("bgg")); bgb = Integer.parseInt(getParameter("bgb")); backcolor = new Color(bgr, bgg, bgb); setBackground(backcolor); textr = Integer.parseInt(getParameter("textr")); textg = Integer.parseInt(getParameter("textg")); textb = Integer.parseInt(getParameter("textb")); textcolor = new Color(textr, textg, textb); msgx = Integer.parseInt(getParameter("msgx")); msgy = Integer.parseInt(getParameter("msgy")); fn = new Font(fonttype, Font.BOLD, fontsize); ReceivedData = new String [1000]; } public void paint(Graphics g) { g.setFont(fn); g.setColor(textcolor); g.drawString(message, msgx, msgy); } }