home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / AFC102 / Samples / LoanCalc / Src / WZInterest.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  2.1 KB  |  81 lines

  1. //
  2. // (c) 1997 Microsoft Corporation.  All rights reserved.
  3. //
  4. import com.ms.ui.*;
  5. import com.ms.fx.*;
  6. import java.awt.Event;
  7. import java.awt.Insets;
  8.  
  9. public class WZInterest extends UIWizardStep implements LCConsts
  10. {
  11.     public InterestPnl pnl;
  12.  
  13.     public WZInterest()
  14.     {
  15.         super(new UIGraphic(LCImages.get(INTEREST)), new InterestPnl());
  16.         pnl = (InterestPnl)getContent();
  17.     }
  18. }
  19.  
  20. class InterestPnl extends FocusUIPanel implements LCConsts, IFxTextConstants
  21. {
  22.     public UIEditChoice i_ec;
  23.  
  24.     public InterestPnl()
  25.     {
  26.         setLayout(new UIBorderLayout());
  27.  
  28.         // Main text
  29.         UIDrawText intro = new UIDrawText(INTEREST_TXT);
  30.         intro.setWordWrap(IFxTextConstants.wwKeepWordIntact);
  31.         //UIText intro = new UIText(INTEREST_TXT, UIText.LEFT);
  32.  
  33.         // Interest Rate label
  34.         UIText i_t = new UIText("Interest Rate:", UIText.RIGHT);
  35.  
  36.         // Create Interest Rate combobox
  37.         i_ec = new UIEditChoice();
  38.  
  39.         for ( int j = 24; j <= 200; j++ )
  40.             i_ec.add(new UIText("" + new PRCNT(j), UIText.LEFT));
  41.         i_ec.setSelectedIndex(INIT_RATE - MIN_RATE);
  42.  
  43.         add(new HSL(intro, 
  44.                     new VSL(i_t, 
  45.                             new BL(i_ec, 35,10,35,0),
  46.                             180),
  47.                     45),
  48.             "center");
  49.     }
  50.  
  51.     public boolean action(Event e, Object arg)
  52.     {
  53.         // if user hits "enter" in UIEditChoice arg will equal null
  54.         if ( (e.target == i_ec) && (arg == null) )
  55.         {
  56.             double eighths = 0.0;
  57.             String value_str = i_ec.getValueText();
  58.             if ( value_str.endsWith(" %") )
  59.                 i_ec.setSelectedIndex(i_ec.getSelectedIndex());
  60.             else {
  61.                 // User can enter anything in the UIEditChoice edit control
  62.                 //   if entry is not well formed, make 3% selected
  63.                 try {
  64.                     eighths = (new Double(value_str)).doubleValue() * 8.0;
  65.                 }
  66.                 catch ( NumberFormatException nfe ) { } // do nothing, initialization
  67.                                                         //  will do correct thing.
  68.                 if ( eighths < 24.0 )
  69.                     i_ec.setSelectedIndex(0);
  70.                 else if ( eighths > 200.0 )
  71.                     i_ec.setSelectedIndex(176);
  72.                 else
  73.                     i_ec.setSelectedIndex((int)(Math.round(eighths) - MIN_RATE));
  74.             }
  75.         }
  76.         return super.action(e, arg);
  77.     }    
  78.  
  79.     public Insets getInsets() { return new Insets(10,0,0,0); }
  80. }
  81.