home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PILOT / PC / JUMP / DECHEX / DECHEX.JAV < prev    next >
Encoding:
Text File  |  1997-01-01  |  3.0 KB  |  109 lines

  1. import palmos.*;
  2.  
  3. class DecHex {
  4.   static final int kidfMain = 1000;
  5.   static final int kidmMain = 1000;
  6.  
  7.   static final int kidmAbout   = 1002;
  8.   static final int kidcConvert = 1003;
  9.   static final int kidcDecimal = 1004;
  10.   static final int kidcHex     = 1005;
  11.  
  12.   static final int kidrAboutAlert      = 1000;
  13.   static final int kidrInputErrorAlert = 1001;
  14.   static final int kidrRangeErrorAlert = 1002;
  15.  
  16.   static int fldDecimal;
  17.   static int fldHex;
  18.  
  19.   public static int PilotMain(int cmd, int cmdBPB, int launchFlags)
  20.   {
  21.     if (cmd != 0) {
  22.       return 0;
  23.     }
  24.  
  25.     Palm.FrmGotoForm(kidfMain);
  26.     Event e = new Event();
  27.     Short err = new Short();
  28.     while (e.eType != Event.appStopEvent) {
  29.       Palm.EvtGetEvent(e, -1);
  30.       if (!Palm.SysHandleEvent(e)) {
  31.         if (!Palm.MenuHandleEvent(0, e, err)) {
  32.           if (!ApplicationHandleEvent(e)) {
  33.             if (!MainFormHandleEvent(e)) {
  34.               Palm.FrmHandleEvent(Palm.FrmGetActiveForm(), e);
  35.             }
  36.           }
  37.         }
  38.       }
  39.     }
  40.     return 0;
  41.   }
  42.  
  43.   static boolean ApplicationHandleEvent(Event e)
  44.   {
  45.     if (e.eType == Event.frmLoadEvent) {
  46.       int form = Palm.FrmInitForm(e.formID());
  47.       Palm.FrmSetActiveForm(form);
  48.       fldDecimal = Palm.FrmGetObjectPtr(form, Palm.FrmGetObjectIndex(form, kidcDecimal));
  49.       fldHex     = Palm.FrmGetObjectPtr(form, Palm.FrmGetObjectIndex(form, kidcHex));
  50.       return true;
  51.     }
  52.     return false;
  53.   }
  54.  
  55.   static boolean MainFormHandleEvent(Event e)
  56.   {
  57.     if (e.eType == Event.frmOpenEvent) {
  58.       Palm.FrmDrawForm(Palm.FrmGetActiveForm());
  59.       return true;
  60.     } else if (e.eType == Event.menuEvent) {
  61.       if (e.itemID() == kidmAbout) {
  62.         Palm.FrmAlert(kidrAboutAlert);
  63.         return true;
  64.       }
  65.     } else if (e.eType == Event.ctlSelectEvent) {
  66.       if (e.controlID() == kidcConvert) {
  67.         Convert();
  68.         return true;
  69.       }
  70.     }
  71.     return false;
  72.   }
  73.  
  74.   static void Convert()
  75.   {
  76.     if (Palm.FldDirty(fldDecimal)) {
  77.       String s = Palm.FldGetTextPtr(fldDecimal);
  78.       if (s == null) {
  79.         Palm.FrmAlert(kidrInputErrorAlert);
  80.         return;
  81.       }
  82.       try {
  83.         Integer i = Integer.valueOf(s);
  84.         Palm.FldFreeMemory(fldHex);
  85.         String t = Integer.toHexString(i.intValue());
  86.         Palm.FldInsert(fldHex, t, t.length());
  87.       } catch (NumberFormatException nfe) {
  88.         Palm.FrmAlert(kidrInputErrorAlert);
  89.       }
  90.     } else if (Palm.FldDirty(fldHex)) {
  91.       String s = Palm.FldGetTextPtr(fldHex);
  92.       if (s == null) {
  93.         Palm.FrmAlert(kidrInputErrorAlert);
  94.         return;
  95.       }
  96.       try {
  97.         Integer i = Integer.valueOf(s, 16);
  98.         Palm.FldFreeMemory(fldDecimal);
  99.         String t = String.valueOf(i.intValue());
  100.         Palm.FldInsert(fldDecimal, t, t.length());
  101.       } catch (NumberFormatException nfe) {
  102.         Palm.FrmAlert(kidrInputErrorAlert);
  103.       }
  104.     }
  105.     Palm.FldSetDirty(fldDecimal, false);
  106.     Palm.FldSetDirty(fldHex, false);
  107.   }
  108. }
  109.