Esempio n. 1
0
  /** Create a Query object and configure it. */
  public void init() {
    super.init();
    _query = new Query();
    _query.addCheckBox("check", "Check box", true);
    _query.setTextWidth(20);
    _query.addLine("line", "Entry box", "default entry");
    _query.addDisplay("display", "Display", "displayed string");

    String[] choices = {"a", "b", "c"};
    _query.addChoice("choice", "Choice", choices, "b");

    String[] moreChoices = {"d", "e", "f"};
    _query.addChoice("editchoice", "Editable Choice", moreChoices, "d", true);
    _query.addSlider("slider", "Slider", 0, -100, 100);

    String[] options = {"mayonnaise", "mustard", "both", "none"};
    _query.addRadioButtons("radio", "Radio buttons", options, "none");

    try {
      _query.addFileChooser("fileChooser", "FileChooser", "default", null, null);
    } catch (SecurityException security) {
      System.out.println("addFileChooser failed: " + security);
    }

    _query.addColorChooser("colorChooser", "ColorChoser", "{0.0, 0.0, 0.0, 1.0}");
    _query.addQueryListener(this);
    _query.setBackground(getBackground());
    getContentPane().add(_query);
  }
Esempio n. 2
0
  /**
   * Initialize the applet. This method is called by the browser or applet viewer to inform this
   * applet that it has been loaded into the system. It is always called before the first time that
   * the start() method is called. In this base class, this method creates a new workspace, and
   * instantiates in it the model whose class name is given by the <i>modelClass</i> applet
   * parameter. If that model does not contain a manager, then this method creates one for it.
   */
  public void init() {
    super.init();
    _setupOK = true;
    _workspace = new Workspace(getClass().getName());

    try {
      _toplevel = _createModel(_workspace);

      _toplevel.setModelErrorHandler(new BasicModelErrorHandler());

      // This might not actually be a top level, because we might
      // be looking inside. So we check before creating a manager.
      if ((_toplevel.getContainer() == null) && _toplevel instanceof CompositeActor) {
        if (((CompositeActor) _toplevel).getManager() == null) {
          _manager = new Manager(_workspace, "manager");
          _manager.addExecutionListener(this);
          ((CompositeActor) _toplevel).setManager(_manager);
        } else {
          _manager = ((CompositeActor) _toplevel).getManager();
        }
      }
    } catch (Exception ex) {
      _setupOK = false;
      report("Creation of model failed:\n", ex);
    }

    _createView();
  }
Esempio n. 3
0
  /** Read applet parameters, open the URL and display the contents in a TextArea. */
  public void init() {
    super.init();

    // Process the rows and columns applet parameters
    int rows;

    // Process the rows and columns applet parameters
    int columns;
    String rowsString = getParameter("rows");

    if (rowsString != null) {
      rows = Integer.parseInt(rowsString);
    } else {
      rows = 10;
    }

    String columnsString = getParameter("columns");

    if (columnsString != null) {
      columns = Integer.parseInt(columnsString);
    } else {
      columns = 40;
    }

    // Get the source applet parameter before we create the
    // _jTextArea in case there are problems with the parameter.
    String sourceURLString = getParameter("source");
    URL sourceURL = null;

    if (sourceURLString != null) {
      try {
        showStatus("Reading data . . .");
        sourceURL = new URL(getDocumentBase(), sourceURLString);
      } catch (MalformedURLException e) {
        System.err.println(e.toString());
      }
    }

    /* JFrame _frame = */ new JFrame();
    _jTextArea = new JTextArea(rows, columns);
    _jTextArea.setEditable(false);
    _scrollPane = new JScrollPane(_jTextArea);
    getContentPane().add(_scrollPane);

    String newline = System.getProperty("line.separator");

    if (sourceURL == null) {
      showStatus("Failed to open " + sourceURLString);
      System.err.println("Failed to open " + sourceURLString);
    } else {
      // Read in the data one line at a time.
      InputStream in = null;
      try {
        in = sourceURL.openStream();
        _bufferedReader = new BufferedReader(new InputStreamReader(in));

        String line = _bufferedReader.readLine();

        while (line != null) {
          _jTextArea.append(line + newline);
          line = _bufferedReader.readLine();
        }

        showStatus("Done");
      } catch (FileNotFoundException e) {
        System.err.println("File not found: " + e);
      } catch (IOException e) {
        System.err.println("Error reading input file: " + e);
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (Exception ex) {
            System.err.println("Failed to close " + sourceURLString + ":" + ex);
          }
        }
      }
    }

    // getContentPane().add(_frame);
    // getContentPane().add(_jTextArea);
    validate();
    repaint();
  }