Example #1
0
 public void init() {
   context = this.getAppletContext();
   String audioURL = this.getParameter("audio");
   if (audioURL == null) {
     audioURL = "http://localhost:8080/TGMC-version1/abc.wav?Text=who";
   }
   try {
     URL url = new URL(this.getDocumentBase(), audioURL);
     clip = context.getAudioClip(url);
   } catch (MalformedURLException e) {
     e.printStackTrace();
     context.showStatus("Could not load audio file!");
   }
 }
Example #2
0
  /**
   * opens existing file
   *
   * @param a_file
   */
  public GlyphFile(File a_file) {
    super();

    m_fileName = a_file;

    URL url = null;

    try {
      url = a_file.toURI().toURL();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    init(url);
  }
Example #3
0
 /**
  * Gets the url associated with this resource.
  *
  * @return the URL
  */
 public URL getURL() {
   if (url == null && file != null) {
     String path = getAbsolutePath();
     try {
       if (path.startsWith("/")) { // $NON-NLS-1$
         url = new URL("file:" + path); // $NON-NLS-1$
       } else {
         url = new URL("file:/" + path); // $NON-NLS-1$
       }
     } catch (MalformedURLException ex) {
       ex.printStackTrace();
     }
   }
   return url;
 }
Example #4
0
  /**
   * Closes the applet. This method can be implemented by invoking <code>
   * getAppletContext().showDocument(...)</code>.
   */
  protected void close() {
    AppletContext appletContext;
    try {
      appletContext = getAppletContext();
    } catch (Throwable e) {
      appletContext = null;
    }

    if (appletContext == null) {
      System.exit(0);
    } else {
      getContentPane().removeAll();
      ((JComponent) getContentPane()).revalidate();
      try {
        appletContext.showDocument(new URL(getDocumentBase(), getParameter("PageURL")));
      } catch (MalformedURLException ex) {
        ex.printStackTrace();
      }
    }
  }
  public FormatTestFrame() {
    JPanel buttonPanel = new JPanel();
    okButton = new JButton("Ok");
    buttonPanel.add(okButton);
    add(buttonPanel, BorderLayout.SOUTH);

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 3));
    add(mainPanel, BorderLayout.CENTER);

    JFormattedTextField intField = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField.setValue(new Integer(100));
    addRow("Number:", intField);

    JFormattedTextField intField2 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField2.setValue(new Integer(100));
    intField2.setFocusLostBehavior(JFormattedTextField.COMMIT);
    addRow("Number (Commit behavior):", intField2);

    JFormattedTextField intField3 =
        new JFormattedTextField(
            new InternationalFormatter(NumberFormat.getIntegerInstance()) {
              protected DocumentFilter getDocumentFilter() {
                return filter;
              }
            });
    intField3.setValue(new Integer(100));
    addRow("Filtered Number", intField3);

    JFormattedTextField intField4 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField4.setValue(new Integer(100));
    intField4.setInputVerifier(
        new InputVerifier() {
          public boolean verify(JComponent component) {
            JFormattedTextField field = (JFormattedTextField) component;
            return field.isEditValid();
          }
        });
    addRow("Verified Number:", intField4);

    JFormattedTextField currencyField = new JFormattedTextField(NumberFormat.getCurrencyInstance());
    currencyField.setValue(new Double(10));
    addRow("Currency:", currencyField);

    JFormattedTextField dateField = new JFormattedTextField(DateFormat.getDateInstance());
    dateField.setValue(new Date());
    addRow("Date (default):", dateField);

    DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
    format.setLenient(false);
    JFormattedTextField dateField2 = new JFormattedTextField(format);
    dateField2.setValue(new Date());
    addRow("Date (short, not lenient):", dateField2);

    try {
      DefaultFormatter formatter = new DefaultFormatter();
      formatter.setOverwriteMode(false);
      JFormattedTextField urlField = new JFormattedTextField(formatter);
      urlField.setValue(new URL("http://java.sun.com"));
      addRow("URL:", urlField);
    } catch (MalformedURLException ex) {
      ex.printStackTrace();
    }

    try {
      MaskFormatter formatter = new MaskFormatter("###-##-####");
      formatter.setPlaceholderCharacter('0');
      JFormattedTextField ssnField = new JFormattedTextField(formatter);
      ssnField.setValue("078-05-1120");
      addRow("SSN Mask:", ssnField);
    } catch (ParseException ex) {
      ex.printStackTrace();
    }

    JFormattedTextField ipField = new JFormattedTextField(new IPAddressFormatter());
    ipField.setValue(new byte[] {(byte) 130, 65, 86, 66});
    addRow("IP Address:", ipField);
    pack();
  }
Example #6
0
  public void fetchExternalJSLibrary(String targetURLString) {

    final URL targetURL;
    String targetFile = "";
    String s = null;

    InputStream is = null;
    BufferedReader dis = null;

    try {
      // ------------------------------------------------------------//
      // Step 2:  Create the URL.                                   //
      // ------------------------------------------------------------//
      // Note: Put your real URL here, or better yet, read it as a  //
      // command-line arg, or read it from a file.                  //
      // ------------------------------------------------------------//

      targetURL = new URL(targetURLString);

      // ----------------------------------------------//
      // Step 3:  Open an input stream from the url.  //
      // ----------------------------------------------//

      is = targetURL.openStream();

      // -------------------------------------------------------------//
      // Step 4:                                                     //
      // -------------------------------------------------------------//
      // Convert the InputStream to BufferedReader                   //
      // -------------------------------------------------------------//

      dis = new BufferedReader(new InputStreamReader(is));

      // ------------------------------------------------------------//
      // Step 5:                                                    //
      // ------------------------------------------------------------//
      // Now just read each record of the input stream, and print   //
      // it out.  Note that it's assumed that this problem is run   //
      // from a command-line, not from an application or applet.    //
      // ------------------------------------------------------------//

      while ((s = dis.readLine()) != null) {
        targetFile = targetFile + "\n" + s;
      }

      alert(targetFile);
      System.out.println(targetFile);

    } catch (MalformedURLException mue) {

      alert("Ouch - a MalformedURLException happened.");
      System.out.println("Ouch - a MalformedURLException happened.");
      mue.printStackTrace();
      System.exit(1);

    } catch (IOException ioe) {

      alert("Ouch - an IOException happened.");
      System.out.println("Ouch - an IOException happened.");
      ioe.printStackTrace();
      System.exit(1);

    } catch (Exception e) {
      alert("Ouch - Something wrong happened.");
      alert(e.toString());
      alert(e.getMessage());
    } finally {

      // ---------------------------------//
      // Step 6:  Close the InputStream  //
      // ---------------------------------//

      try {
        is.close();
        dis.close();
      } catch (IOException ioe) {
        // just going to ignore this one
      }
    } // end of 'finally' clause
  }