Exemplo n.º 1
0
  /**
   * Sets the layout of the applet window to BorderLayout, creates all the components and associates
   * them with event listeners if neccessary.
   */
  private void initComponents() {
    setLayout(new BorderLayout());
    setBackground(java.awt.Color.white);

    // get the initial expression from the parameters
    String expr = getParameter("initialExpression");

    // write the expression into the text field
    if (expr != null) exprField = new java.awt.TextField(expr);
    else exprField = new java.awt.TextField("");

    // adjust various settings for the expression field
    exprField.setBackground(java.awt.Color.white);
    exprField.setName("exprField");
    exprField.setFont(new java.awt.Font("Dialog", 0, 11));
    exprField.setForeground(java.awt.Color.black);
    exprField.addTextListener(
        new java.awt.event.TextListener() {
          public void textValueChanged(java.awt.event.TextEvent evt) {
            exprFieldTextValueChanged(evt);
          }
        });

    add("North", exprField);

    // create the graph canvas and add it
    graphCanvas = new GraphCanvas(expr, exprField);
    add("Center", graphCanvas);
  }
Exemplo n.º 2
0
 /** Repaints the graphCanvas whenever the text in the expression field changes. */
 private void exprFieldTextValueChanged(java.awt.event.TextEvent evt) {
   String newExpressionString = exprField.getText();
   graphCanvas.setExpressionString(newExpressionString);
   graphCanvas.repaint();
 }