home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / POPMENU.EXE / PopMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-29  |  3.4 KB  |  121 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10.  
  11. public class PopMenu extends Applet {
  12.    private static final int BUTTON_LIMIT = 20;
  13.    private String qFileName;
  14.    private String[] URLName = new String[20];
  15.    private String[] caption = new String[20];
  16.    private Image[] buttonImage = new Image[20];
  17.    private PopBtn[] button = new PopBtn[20];
  18.    private int[] labelPos = new int[20];
  19.    private int buttonCount;
  20.    private String frame;
  21.    private int defaultLabelPos;
  22.    private static final String PARAM_URL = "HREF";
  23.    private static final String PARAM_IMAGE = "SRC";
  24.    private static final String PARAM_TEXT = "TEXT";
  25.    private static final String PARAM_FRAME = "FRAME";
  26.    private static final String PARAM_LABEL_POS = "LABELPOS";
  27.  
  28.    public String[][] getParameterInfo() {
  29.       String[][] var1 = new String[][]{{"HREF", "String", "URL name - append number"}, {"SRC", "Image", "Image name - append number"}, {"TEXT", "String", "Text - append number"}, {"FRAME", "String", "Frame name - default _top"}, {"LABELPOS", "String", "Label position - default below"}};
  30.       return var1;
  31.    }
  32.  
  33.    public String getAppletInfo() {
  34.       return "Name: PopMenu\r\n" + "Author: David Griffiths\r\n" + "Created with Microsoft Visual J++ Version 1.0";
  35.    }
  36.  
  37.    public boolean mouseUp(Event var1, int var2, int var3) {
  38.       for(int var4 = 0; var4 < this.buttonCount; ++var4) {
  39.          if (this.button[var4].equals(var1.target)) {
  40.             ((Applet)this).getAppletContext().showStatus(this.URLName[var4]);
  41.  
  42.             try {
  43.                URL var5 = new URL(((Applet)this).getDocumentBase(), this.URLName[var4]);
  44.                ((Applet)this).getAppletContext().showDocument(var5, this.frame);
  45.             } catch (MalformedURLException var7) {
  46.                ((Applet)this).getAppletContext().showStatus("Bad URL: " + this.URLName[var4]);
  47.                return false;
  48.             }
  49.          }
  50.       }
  51.  
  52.       return true;
  53.    }
  54.  
  55.    private int setLabelPos(String var1, int var2) {
  56.       int var3;
  57.       if (var1 != null) {
  58.          if ("RIGHT".equals(var1.toUpperCase())) {
  59.             var3 = 0;
  60.          } else {
  61.             var3 = var2;
  62.          }
  63.       } else {
  64.          var3 = var2;
  65.       }
  66.  
  67.       return var3;
  68.    }
  69.  
  70.    private void initGUI() {
  71.       for(int var1 = 0; var1 < this.buttonCount; ++var1) {
  72.          ((Container)this).add(this.button[var1] = new PopBtn(this.caption[var1], this.buttonImage[var1], this.labelPos[var1]));
  73.       }
  74.  
  75.    }
  76.  
  77.    public void init() {
  78.       String var1 = "a";
  79.       int var2 = 0;
  80.       int var3 = 0;
  81.       var1 = ((Applet)this).getParameter("FRAME");
  82.       if (var1 != null) {
  83.          this.frame = var1;
  84.       } else {
  85.          this.frame = "_top";
  86.       }
  87.  
  88.       var1 = ((Applet)this).getParameter("LABELPOS");
  89.  
  90.       for(this.defaultLabelPos = this.setLabelPos(var1, 1); var2 < 20 && var3 < 40; ++var3) {
  91.          var1 = ((Applet)this).getParameter("HREF" + var3);
  92.          if (var1 != null) {
  93.             this.URLName[var2] = var1;
  94.             var1 = ((Applet)this).getParameter("TEXT" + var3);
  95.             if (var1 != null) {
  96.                this.caption[var2] = var1;
  97.             }
  98.  
  99.             var1 = ((Applet)this).getParameter("SRC" + var3);
  100.             if (var1 != null) {
  101.                this.buttonImage[var2] = ((Applet)this).getImage(((Applet)this).getDocumentBase(), var1);
  102.             }
  103.  
  104.             var1 = ((Applet)this).getParameter("LABELPOS" + var3);
  105.             this.labelPos[var2] = this.setLabelPos(var1, this.defaultLabelPos);
  106.             ++var2;
  107.          }
  108.       }
  109.  
  110.       this.buttonCount = var2;
  111.       this.initGUI();
  112.    }
  113.  
  114.    public void paint(Graphics var1) {
  115.       var1.setColor(Color.white);
  116.       var1.drawRect(1, 1, ((Component)this).size().width - 2, ((Component)this).size().height - 2);
  117.       var1.setColor(Color.gray);
  118.       var1.drawRect(0, 0, ((Component)this).size().width - 2, ((Component)this).size().height - 2);
  119.    }
  120. }
  121.