home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jazzy example source code file (JSpellApplet.java)

This example Jazzy source code file (JSpellApplet.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jazzy tags/keywords

awt, event, fileinputstream, fileinputstream, gridbagconstraints, gridbagconstraints, gridbaglayout, gridbaglayout, insets, ioexception, jbutton, jbutton, jtextarea, jtextcomponentspellchecker, net, network, swing, thread, zip, zipinputstream

The Jazzy JSpellApplet.java source code

Jazzy - a Java library for Spell Checking
Copyright (C) 2001 Mindaugas Idzelis
Full text of license can be found in LICENSE.txt

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
package com.swabunga.spell.swing;

import com.swabunga.spell.engine.SpellDictionary;
import com.swabunga.spell.engine.SpellDictionaryHashMap;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipInputStream;

 * @author aim4min
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
public class JSpellApplet extends JApplet {

  private static final String dictionaryFile = "dict/english.0.zip";
  private SpellDictionary dictionary;
  JTextArea text = null;
  JButton spell = null;

   * @see java.awt.Component#paint(Graphics)
  public void paint(Graphics arg0) {


   * @see java.applet.Applet#init()
  public void init() {

    try {
      URL resource = null;
      ZipInputStream zip = null;
      try {
        resource = new URL(getCodeBase().toExternalForm() + dictionaryFile);
        zip = new ZipInputStream(resource.openStream());
        /* getCodeBase() throws a NullPointerException when run
         * outside the context of a browser
      } catch (NullPointerException e) {
        FileInputStream fin = new FileInputStream(dictionaryFile);
        zip = new ZipInputStream(fin);
      dictionary = new SpellDictionaryHashMap(new BufferedReader(new InputStreamReader(zip)));

    } catch (MalformedURLException e) {
    } catch (FileNotFoundException e) {
    } catch (IOException e) {


  private void initGUI() {
    Container frame = getContentPane();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.CENTER;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1.0;
    c.weighty = 1.0;
    text = new JTextArea("The quck brwn dog jmped over the fnce.");
    addToFrame(frame, text, gridbag, c, 0, 0, 1, 1);

    GridBagConstraints spellcon = new GridBagConstraints();
    spellcon.anchor = GridBagConstraints.NORTH;
    spellcon.insets = new Insets(5, 5, 5, 5);

    spell = new JButton("spell check");
    final JTextComponentSpellChecker sc = new JTextComponentSpellChecker(dictionary);
    spell.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        Thread t = new Thread() {
          public void run() {
            try {
            } catch (Exception ex) {

    addToFrame(frame, spell, gridbag, spellcon, 1, 0, 1, 1);

  // Helps build gridbaglayout.
  private void addToFrame(Container f, Component c, GridBagLayout gbl, GridBagConstraints gbc, int x, int y, int w, int h) {
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = w;
    gbc.gridheight = h;
    gbl.setConstraints(c, gbc);

Other Jazzy examples (source code examples)

Here is a short list of links related to this Jazzy JSpellApplet.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.