Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

Swing Chapter 20. (Advanced topics) Constructing a Word Processor. Easy for reading, Click here!

Custom Search
Swing Chapter 20. (Advanced topics) Constructing a Word Processor. Easy for reading, Click here!

[ Return to Swing (Book) ]

Page: 8/9 



Previous Page Previous Page (7/9) - Next Page (9/9) Next Page
Subpages: 1. Word Processor: part I - Introducing RTF
2. Word Processor: part II - Managing fonts
3. Word Processor: part III - Colors and images
4. Word Processor: part IV - Working with styles
5. Word Processor: part V - Clipboard and undo/redo
6. Word Processor: part VI - Advanced font mangement
7. Word Processor: part VII - Paragraph formatting
8. Word Processor: part VIII - Find and replace
9. Word Processor: part IX - Spell checker [using JDBC and SQL]

20.8  Word Processor: part VIII - Find and replace

Along with font and paragraph dialogs, find and replace functionality has also become a fairly common tool in GUI-based text editing environments. It is safe to assume that most users would be sadly disappointed if this functionality was not included in a new word processor application. In this section we will show how to add this functionality. Traditionally such tools are represented in an "Edit" menu and can be activated by keyboard accelerators. We will use a dialog containing a single tabbed pane with tabs for finding and replacing a specific region of text. We will also provide several options for searching: match case, search whole words only, and search up or down.

Figure 20.9 WordProcessor with complete find and replace functionality; "Find" tab shown here

<<file figure20-9.gif>>

Figure 20.10 "Replace" tab of our custom find and replace dialog used in a word processor application.

<<file figure20-10.gif>>

The Code: WordProcessor.java

see \Chapter20\8

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.util.*;

import javax.swing.*;

import javax.swing.text.*;

import javax.swing.event.*;

import javax.swing.border.*;

import javax.swing.text.rtf.*;

import javax.swing.undo.*;

import dl.*;

public class WordProcessor extends JFrame

{

  // Unchanged code from section 20.7

  protected FontDialog m_fontDialog;

  protected ParagraphDialog m_paragraphDialog;

  protected FindDialog m_findDialog;

  protected JMenuBar createMenuBar() {

    // Unchanged code from section 20.7

    mEdit.addSeparator();

    Action findAction = new AbstractAction("Find...",

     new ImageIcon("edit_find.gif"))

    {

      public void actionPerformed(ActionEvent e) {

        WordProcessor.this.repaint();

        if (m_findDialog==null)

          m_findDialog = new FindDialog(WordProcessor.this, 0);

        else

          m_findDialog.setSelectedIndex(0);

        Dimension d1 = m_findDialog.getSize();

        Dimension d2 = WordProcessor.this.getSize();

        int x = Math.max((d2.width-d1.width)/2, 0);

        int y = Math.max((d2.height-d1.height)/2, 0);

        m_findDialog.setBounds(x + WordProcessor.this.getX(),

          y + WordProcessor.this.getY(), d1.width, d1.height);

        m_findDialog.show();

      }

    };

    item = mEdit.add(findAction); 

    item.setMnemonic('f');

    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,

      KeyEvent.CTRL_MASK));

    Action replaceAction = new AbstractAction("Replace...") {

      public void actionPerformed(ActionEvent e) {

        WordProcessor.this.repaint();

        if (m_findDialog==null)

          m_findDialog = new FindDialog(WordProcessor.this, 1);

        else

          m_findDialog.setSelectedIndex(1);

        Dimension d1 = m_findDialog.getSize();

        Dimension d2 = WordProcessor.this.getSize();

        int x = Math.max((d2.width-d1.width)/2, 0);

        int y = Math.max((d2.height-d1.height)/2, 0);

        m_findDialog.setBounds(x + WordProcessor.this.getX(),

          y + WordProcessor.this.getY(), d1.width, d1.height);

        m_findDialog.show();

      }

    };

    item =  mEdit.add(replaceAction); 

    item.setMnemonic('r');

    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,

      KeyEvent.CTRL_MASK));

    menuBar.add(mEdit);

    // Unchanged code from section 20.7

    return menuBar;

  }

  // Unchanged code from section 20.7

  public Document getDocument() { return m_doc; }

  public JTextPane getTextPane() { return m_monitor; }

  public void setSelection(int xStart, int xFinish, boolean moveUp) {

    if (moveUp) {

      m_monitor.setCaretPosition(xFinish);

      m_monitor.moveCaretPosition(xStart);

    }

    else

      m_monitor.select(xStart, xFinish);

    m_xStart = m_monitor.getSelectionStart();

    m_xFinish = m_monitor.getSelectionEnd();

  }

  public static void main(String argv[]) {

    new WordProcessor();

  }

  // Unchanged code from section 20.7

}

// Unchanged code from section 20.7

class FindDialog extends JDialog

{

  protected WordProcessor m_owner;

  protected JTabbedPane m_tb;

  protected JTextField m_txtFind1;

  protected JTextField m_txtFind2;

  protected Document m_docFind;

  protected Document m_docReplace;

  protected ButtonModel m_modelWord;

  protected ButtonModel m_modelCase;

  protected ButtonModel m_modelUp;

  protected ButtonModel m_modelDown;

  protected int m_searchIndex = -1;

  protected boolean m_searchUp = false;

  protected String  m_searchData;

  public FindDialog(WordProcessor owner, int index) {

    super(owner, "Find and Replace", false);

    m_owner = owner;

    m_tb = new JTabbedPane();

    // "Find" panel

    JPanel p1 = new JPanel(new BorderLayout());

    JPanel pc1 = new JPanel(new BorderLayout());

    JPanel pf = new JPanel();

    pf.setLayout(new DialogLayout(20, 5));

    pf.setBorder(new EmptyBorder(8, 5, 8, 0));

    pf.add(new JLabel("Find what:"));

    m_txtFind1 = new JTextField();

    m_docFind = m_txtFind1.getDocument();

    pf.add(m_txtFind1);

    pc1.add(pf, BorderLayout.CENTER);

    JPanel po = new JPanel(new GridLayout(2, 2, 8, 2));

    po.setBorder(new TitledBorder(new EtchedBorder(),

      "Options"));

    JCheckBox chkWord = new JCheckBox("Whole words only");

    chkWord.setMnemonic('w');

    m_modelWord = chkWord.getModel();

    po.add(chkWord);

    ButtonGroup bg = new ButtonGroup();

    JRadioButton rdUp = new JRadioButton("Search up");

    rdUp.setMnemonic('u');

    m_modelUp = rdUp.getModel();

    bg.add(rdUp);

    po.add(rdUp);

    JCheckBox chkCase = new JCheckBox("Match case");

    chkCase.setMnemonic('c');

    m_modelCase = chkCase.getModel();

    po.add(chkCase);

    JRadioButton rdDown = new JRadioButton("Search down", true);

    rdDown.setMnemonic('d');

    m_modelDown = rdDown.getModel();

    bg.add(rdDown);

    po.add(rdDown);

    pc1.add(po, BorderLayout.SOUTH);

    p1.add(pc1, BorderLayout.CENTER);

    JPanel p01 = new JPanel(new FlowLayout());

    JPanel p = new JPanel(new GridLayout(2, 1, 2, 8));

    ActionListener findAction = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        findNext(false, true);

      }

    };

    JButton btFind = new JButton("Find Next");

    btFind.addActionListener(findAction);

    btFind.setMnemonic('f');

    p.add(btFind);

    ActionListener closeAction = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        setVisible(false);

      }

    };

    JButton btClose = new JButton("Close");

    btClose.addActionListener(closeAction);

    btClose.setDefaultCapable(true);

    p.add(btClose);

    p01.add(p);

    p1.add(p01, BorderLayout.EAST);

    m_tb.addTab("Find", p1);

    // "Replace" panel

    JPanel p2 = new JPanel(new BorderLayout());

    JPanel pc2 = new JPanel(new BorderLayout());

    JPanel pc = new JPanel();

    pc.setLayout(new DialogLayout(20, 5));

    pc.setBorder(new EmptyBorder(8, 5, 8, 0));

    pc.add(new JLabel("Find what:"));

    m_txtFind2 = new JTextField();

    m_txtFind2.setDocument(m_docFind);

    pc.add(m_txtFind2);

    pc.add(new JLabel("Replace:"));

    JTextField txtReplace = new JTextField();

    m_docReplace = txtReplace.getDocument();

    pc.add(txtReplace);

    pc2.add(pc, BorderLayout.CENTER);

    po = new JPanel(new GridLayout(2, 2, 8, 2));

    po.setBorder(new TitledBorder(new EtchedBorder(),

      "Options"));

    chkWord = new JCheckBox("Whole words only");

    chkWord.setMnemonic('w');

    chkWord.setModel(m_modelWord);

    po.add(chkWord);

    bg = new ButtonGroup();

    rdUp = new JRadioButton("Search up");

    rdUp.setMnemonic('u');

    rdUp.setModel(m_modelUp);

    bg.add(rdUp);

    po.add(rdUp);

    chkCase = new JCheckBox("Match case");

    chkCase.setMnemonic('c');

    chkCase.setModel(m_modelCase);

    po.add(chkCase);

    rdDown = new JRadioButton("Search down", true);

    rdDown.setMnemonic('d');

    rdDown.setModel(m_modelDown);

    bg.add(rdDown);

    po.add(rdDown);

    pc2.add(po, BorderLayout.SOUTH);

    p2.add(pc2, BorderLayout.CENTER);

    JPanel p02 = new JPanel(new FlowLayout());

    p = new JPanel(new GridLayout(3, 1, 2, 8));

    ActionListener replaceAction = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        findNext(true, true);

      }

    };

    JButton btReplace = new JButton("Replace");

    btReplace.addActionListener(replaceAction);

    btReplace.setMnemonic('r');

    p.add(btReplace);

    ActionListener replaceAllAction = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        int counter = 0;

        while (true) {

          int result = findNext(true, false);

          if (result < 0)    // error

            return;

          else if (result == 0)    // no more

            break;

          counter++;

        }

        JOptionPane.showMessageDialog(m_owner,

          counter+" replacement(s) have been done", "Info",

          JOptionPane.INFORMATION_MESSAGE);

      }

    };

    JButton btReplaceAll = new JButton("Replace All");

    btReplaceAll.addActionListener(replaceAllAction);

    btReplaceAll.setMnemonic('a');

    p.add(btReplaceAll);

    btClose = new JButton("Close");

    btClose.addActionListener(closeAction);

    btClose.setDefaultCapable(true);

    p.add(btClose);

    p02.add(p);

    p2.add(p02, BorderLayout.EAST);

    // Make button columns the same size

    p01.setPreferredSize(p02.getPreferredSize());

    m_tb.addTab("Replace", p2);

    m_tb.setSelectedIndex(index);

    getContentPane().add(m_tb, BorderLayout.CENTER);

    WindowListener flst = new WindowAdapter() {

      public void windowActivated(WindowEvent e) {

        m_searchIndex = -1;

        if (m_tb.getSelectedIndex()==0)

          m_txtFind1.grabFocus();

        else

          m_txtFind2.grabFocus();

      }

      public void windowDeactivated(WindowEvent e) {

        m_searchData = null;

      }

    };

    addWindowListener(flst);

    pack();

    setResizable(false);

  }

  public void setSelectedIndex(int index) {

    m_tb.setSelectedIndex(index);

    setVisible(true);

    m_searchIndex = -1;

  }

  public int findNext(boolean doReplace, boolean showWarnings) {

    JTextPane monitor = m_owner.getTextPane();

    int pos = monitor.getCaretPosition();

    if (m_modelUp.isSelected() != m_searchUp) {

      m_searchUp = m_modelUp.isSelected();

      m_searchIndex = -1;

    }

    if (m_searchIndex == -1) {

      try {

        Document doc = m_owner.getDocument();

        if (m_searchUp)

          m_searchData = doc.getText(0, pos);

        else

          m_searchData = doc.getText(pos, doc.getLength()-pos);

        m_searchIndex = pos;

      }

      catch (BadLocationException ex) {

        warning(ex.toString());

        return -1;

      }

    }

    String key = "";

    try { key = m_docFind.getText(0, m_docFind.getLength()); }

    catch (BadLocationException ex) {}

    if (key.length()==0) {

      warning("Please enter the target to search");

      return -1;

    }

    if (!m_modelCase.isSelected()) {

      m_searchData = m_searchData.toLowerCase();

      key = key.toLowerCase();

    }

    if (m_modelWord.isSelected()) {

      for (int k=0; k<Utils.WORD_SEPARATORS.length; k++) {

        if (key.indexOf(Utils.WORD_SEPARATORS[k]) >= 0) {

          warning("The text target contains an illegal "+

            "character \'"+Utils.WORD_SEPARATORS[k]+"\'");

          return -1;

        }

      }

    }

    String replacement = "";

    if (doReplace) {

      try {

        replacement = m_docReplace.getText(0,

          m_docReplace.getLength());

      } catch (BadLocationException ex) {}

    }

    int xStart = -1;

    int xFinish = -1;

    while (true)

    {

      if (m_searchUp)

        xStart = m_searchData.lastIndexOf(key, pos-1);

      else

        xStart = m_searchData.indexOf(key, pos-m_searchIndex);

      if (xStart < 0) {

        if (showWarnings)

          warning("Text not found");

        return 0;

      }

      xFinish = xStart+key.length();

      if (m_modelWord.isSelected()) {

        boolean s1 = xStart>0;

        boolean b1 = s1 && !Utils.isSeparator(m_searchData.charAt(

          xStart-1));

        boolean s2 = xFinish<m_searchData.length();

        boolean b2 = s2 && !Utils.isSeparator(m_searchData.charAt(

          xFinish));

        if (b1 || b2)    // Not a whole word

        {

          if (m_searchUp && s1)    // Can continue up

          {

            pos = xStart;

            continue;

          }

          if (!m_searchUp && s2)    // Can continue down

          {

            pos = xFinish;

            continue;

          }

          // Found, but not a whole word, and we cannot continue

          if (showWarnings)

            warning("Text not found");

          return 0;

        }

      }

      break;

    }

    if (!m_searchUp) {

      xStart += m_searchIndex;

      xFinish += m_searchIndex;

    }

    if (doReplace) {

      m_owner.setSelection(xStart, xFinish, m_searchUp);

      monitor.replaceSelection(replacement);

      m_owner.setSelection(xStart, xStart+replacement.length(),

        m_searchUp);

      m_searchIndex = -1;

    }

    else

      m_owner.setSelection(xStart, xFinish, m_searchUp);

    return 1;

  }

  protected void warning(String message) {

    JOptionPane.showMessageDialog(m_owner,

      message, "Warning", JOptionPane.INFORMATION_MESSAGE);

  }

}

class Utils

{

  public static final char[] WORD_SEPARATORS = {' ', '\t', '\n',

    '\r', '\f', '.', ',', ':', '-', '(', ')', '[', ']', '{',

    '}', '<', '>', '/', '|', '\\', '\'', '\"'};

  public static boolean isSeparator(char ch) {

    for (int k=0; k<WORD_SEPARATORS.length; k++)

      if (ch == WORD_SEPARATORS[k])

        return true;

    return false;

  }

}

Understanding the Code

Class WordProcessor

This class now imports the dl package (constructed and discussed in chapter 4) to use our DialogLayout manager. WordProcessor also declares one new instance variable:

FindDialog m_findDialog: custom dialog for finding and replacing a selected region of text.

Two new menu items titled "Find..." and "Replace...," are added to the "Edit" menu. These items are activated with keyboard accelerators Ctrl+F and Ctrl+H respectively. When pressed, both items create an instance of FindDialog (if m_findDialog is null) or activate the existing instance, and the dialog is then displayed. The only difference between the two is that the "Find..." menu item activates the 0-indexed tabbed pane tab, and the "Replace..." menu item activates the tab at index 1.

Three new public methods have been added to this class to make access to our text pane component, and related objects, easier from external classes. The getDocument() method retrieves the text pane's current document instance, and the getTextPane() method retrieves the text pane itself. The  setSelection() method selects a portion of text between given start and end positions, and positions the caret at the beginning or end of the selection, depending on the value of the moveUp boolean parameter. The coordinates of such a selection are then stored in the m_xStart and m_xFinish instance variables (recall that these variables always hold the coordinates of the current text selection and are used to restore this selection when our text pane regains the focus).

Class FindDialog

This class is a modal, JDialog sub-class encapsulating our find and replace functionality. It contains a tabbed pane with two tabs, "Find" and "Replace." Among unique controls, both also contain several common controls: checkboxs for "Whole words only" and "Match case," radio button for "Search up" and  "Search down," and a text field for the text to "Find." What we need to is a set of controls which are common across both pages. To simplify this task we create two components and use the same model for each. This guarantees that consistency will be maintained for us, without the need for any maintenance or state checks.

FindDialog maintains the following instance variables:

WordProcessor m_owner: an explicit reference to our WordProcessor parent application frame.

JTabbedPane m_tb: the tabbed pane containing the find and replace pages.

JTextField m_txtFind1: used to enter the string to find.

JTextField m_txtFind2: used to enter the string to replace.

Document m_docFind: a shared data model for the "Find" text fields.

Document m_docReplace: a data model for the "Replace" text field.

ButtonModel m_modelWord: a shared data model for the "Whole words only" checkboxes.

ButtonModel m_modelCase: a shared data model for the "Match case" checkboxes.

ButtonModel m_modelUp: a shared data model for the "Search up" radio buttons.

ButtonModel m_modelDown: a shared data model for the "Search down" radio buttons.

int m_searchIndex: position in the document to start searching from.

boolean m_searchUp: a search direction flag.

String m_searchData: string to search for.

The FindDialog constructor creates a super-class non-modal dialog instance titled "Find and Replace." The main tabbed pane, m_tb, is created, and JPanel p1 (the main container of the "Find" tab) receives  the m_txtFind1 text field along with a "Find what:" label. This text field is used to enter the target string to be searched for. Note that the Document instance associated with this textbox is stored in the m_docFind instance variable (which will be used to facilitate sharing between another text field).

Note: In a more sophisticated implementation one might use editable comboboxes with memory in place of text fields, similar to those discussed in the final examples of chapter 9.

Two checkboxes titled "Whole words only" and "Match case," and two radio buttons titled "Search up" and "Search down" (initially selected) are placed at the bottom of the p1 panel. These components are surrounded by a titled "Options" border. Two JButtons titled "Find Next" and "Close" are placed at the right side of the panel. The first button calls our findNext() method (see below) when pressed. The second button hides the dialog. Finally the p1 panel is added to m_tb with a tab title of "Find."

JPanel p2 (the main container of the "Replace" tab) receives the m_txtFind2 text field along with a "Find what:" label. It als receives another pair labeled "Replace:". An instance of our custom layout manager, DialogLayout (discussed in chapter 4), is used to lay out these text fields and corresponding labels without involving any intermediate containers. The same layout is used in the "Find" panel. We also synchronize the preferred size of the two panels to avoid movement of the mimicked components when a new page is activated.

Note that the m_docFind data object is set as the document for the m_txtFind2 text field. This ensures consistency between the two different "Find" text fields in the two tabbed panels.

Two checkboxes and two radio buttons are placed at the bottom of the panel to control the replacement options. They have identical meaning and representation as the corresponding four controls in the "Find" panel, and to ensure consistency between them, the data models are shared between each 'identical' component.

Three JButtons titled "Replace," "Replace All," and "Close" are placed at the right side of the panel. The "Replace" button makes a single call to our findNext() method (discussed below) when pressed. The "Replace All" button is associated with an actionPerformed() method which repeatedly invokes findNext() to perform replacement until it returns -1 to signal an error, or 0 to signal that no more replacements can be made. If an error occurs this method returns, the actionPerformed() method simple returns (since an error will be properly reported to the user by the findNext() method). Otherwise the number of replacements made is reported to the user in a JOptionPane message dialog. The "Close" button hides the dialog. Finally the p2 panel is added to the m_tb tabbed pane with a tab title of "Replace."

Since this is a non-modal dialog, the user can freely switch to the main application frame and return back to the dialog while each remains visible (a typical find-and-replace feature). Once the user leaves the dialog he/she can modify the document's content, or move the caret position. To account for this, we add a WindowListener to the dialog whose windowActivated() method sets m_searchIndex to -1. This way, the next time findNext() is called (see below) the search data will be re-initialized, allowing the search to continue as expected, corresponding to the new caret position and document content.

The setSelectedIndex() method activates a page with the given index and makes this dialog visible. This method is intended mostly for use externally by our app when it wants to display this dialog with a specific tab selected.

The findNext() method is responsible for performing the actual find and replace operations. It takes two arguments:

boolean doReplace: if true, find and replace, otherwise just find.

boolean showWarnings: if true, display a message dialog if target text cannot be found, otherwise do not display a message.

findNext() returns an int result with the following meaning:

-1: an error has occurred.

0: the target text cannot be found.

1: a find or find and replace was completed successfully.

The m_searchIndex == -1 condition specified that the text to be searched through must be re-calculated. In this case we store the portion of text from the beginning of the document to the current caret position if we are searching up, or between the current caret position and the end of the document if we are searching down. This text is stored in the m_searchData instance variable. The current caret position is stored in the m_searchIndex variable.

Note: This solution may not be adequate for large documents. However, a more sophisticated solution would take us too far from the primary goal of this example.

Figure 20.11 Usage of instance variables for searching up and down through document text.

<<file figure20-11.gif>>

The text to search for is retrieved from the m_docFind shared Document. If the case-insensitive option is selected, both the m_searchData text and the text to search for are converted into lower case. If the "Whole words only" option is selected, we check whether the text to search for contains any separator characters defined in our Util utilities class (see below).

Note: If a given String is already completely in lower or upper case, the toLowerCase() (or toUpperCase()) method returns the original String without creating a new object.

After this, if the doReplace parameter is true, we retrieve the replacement text from our m_docReplace Document. At this point we're ready to actually perform a search. We take advantage of existing String functionality to accomplish this:

   if (m_searchUp)

     xStart = m_searchData.lastIndexOf(key, pos-1);

   else

     xStart = m_searchData.indexOf(key, pos-m_searchIndex);

If we are seaching up, we search for the last occurrence of the target string from the current caret position. Otherwise we search for the first occurrence of the target string from the current caret position. If the target string is not found, we cannot continue the search, and a warning is displayed if the showWarnings parameter is true.

This simple scheme is complicated considerably if the "Whole words only" option is selected. In this case we need to verify whether symbols on the left and on the right of a matching region pf text are either word separators defined in our Utils class, or the string lies at the end of the data being searched. If these conditions are not satisfied, we attempt to continue searching, unless the end of the search data is reached.

In any case, if we locate an acceptable match, we select the located text. If the replace option is selected, we replace this selected region with the specified replacement text and then select the new replacement text. In this latter case we also set m_searchIndex to -1 to force the m_searchData variable to be updated. This is necessary for continued searching because the data being searched most likely changes after each replace. The location of the caret also usually changes.

Class Utils

This class provides a simple static utility method and an array of chars representing word separator characters. The isSeparator() method simply checks whether a given character belongs to the static WORD_SEPARATORS char array.

Running the Code

Open an existing RTF file and use the "Edit" menu, or the appropriate keyboard accelerator, to bring up the "Find and Replace" dialog with the "Find" tab selected. Enter some text to search for, select some search options, and press the "Find Next" button. If your target text is found, the matching region will be highlighted in the base document. Press this button again to find subsequent entries (if any). Verify that the "Whole words only" and "Match case" options function as discussed above. Change focus to the main application window and modify the document and/or change the caret position. Return to the "Find and Replace" dialog and note that the search continues as expected.

Select the "Replace" tab and verify that the state of all search options, including the search target string, are preserved from the "Find" tab (and vice versa when switching back). Enter a replacement string and verify that the "Replace" and "Replace All" buttons work as expected.



[ Return to Swing (Book) ]


Top 10 read Java Articles
 Get free "1000 Java Tips eBook"

 Java Calendar and Date: good to know facts and code examples

 Array vs ArrayList vs LinkedList vs Vector: an excellent overview and examples

 How can I convert any Java Object into byte array? And byte array to file object

 The Java Lesson 1: What is Java?

 How do I compare two dates and times, date between dates, time between times and

 Maven vs Ant or Ant vs Maven?

 How to open, read, write, close file(s) in Java? Examples on move, rename and de

 Java Array

 Java: JLabel font and color


[ More in News Section ]
Java Lessons

The Java Lesson 1:
What is Java?
The Java Lesson 2:
Anatomy of a simple Java program
The Java Lesson 3:
Identifiers and primitive data types
The Java Lesson 4:
Variables, constants, and literals
The Java Lesson 5:
Arithmetic operations, conversions, and casts
The Java Lesson 6:
Boolean expressions and operations
The Java Lesson 7:
Bitwise operations
The Java Lesson 8:
Flow control with if and else
The Java Lesson 9:
switch statements
The Java Lesson 10:
for, while, and do-while statements
The Java Lesson 11:
Using break and continue
The Java Lesson 12:
Class methods and how they are called
The Java Lesson 13:
Using the Math class
The Java Lesson 14:
Creating and calling custom class methods
The Java Lesson 15:
Overloading class methods
The Java Lesson 16:
An introduction to objects and object references
The Java Lesson 17:
The String class
The Java Lesson 18:
The StringBuffer class
The Java Lesson 19:
Initializing and processing arrays of primitives
The Java Lesson 20:
Initializing and processing arrays of objects
The Java Lesson 23:
Inheritance and overriding inherited methods
The Java Lesson 24:
abstract classes and polymorphism
The Java Lesson 25:
Interfaces, instanceof, and object conversion and casting
The Java Lesson 26:
Introduction to graphical programming and the java.awt packa
The Java Lesson 27:
The Component class
The Java Lesson 28:
Containers and simple layout managers
The Java Lesson 29:
The Color and Font classes
The Java Lesson 30:
Drawing geometric shapes
The Java Lesson 31:
Choice, List, and Checkbox controls
The Java Lesson 32:
Using the Scrollbar graphical control
The Java Lesson 33:
Menus and submenus
The Java Lesson 34:
An introduction to applets and the Applet class
The Java Lesson 35:
Essential HTML to launch an applet and pass it parameters
The Java Lesson 36:
Mouse event processing
Java Lesson 37:
Menus and submenus
Java Lesson 38:
The WindowListener interface and the WindowAdapter class
Java Lesson 39:
An introduction to GridBagLayout
Java Lesson 40:
An introduction to the Java Collections API
Java Lesson 41:
Exception handling with try, catch, and finally blocks
Java Lesson 42:
Claiming and throwing exceptions
Java Lesson 43:
Multithreading, the Thread class, and the Runnable interface
Java Lesson 44:
An introduction to I/O and the File and FileDialog classes
Java Lesson 45:
Low-level and high-level stream classes
Java Lesson 46:
Using the RandomAccessFile class
Java Lessons by
Joh Huhtala: Update

Latest articles
 Java Profiler JProbe to Resolve Performance Problems Faster

 SSL with GlassFish v2, page 5

 SSL with GlassFish v2, page 4

 SSL with GlassFish v2, page 3

 SSL with GlassFish v2, page 2

 The Java Lesson 2: Anatomy of a simple Java program, page 2

 New site about Java for robots and robotics: both software and hardware.

 Exceptions -III: What's an exception and why do I care?

 Exceptions -II: What's an exception and why do I care?

 Exceptions: What's an exception and why do I care?

 Double your Java code quality in 10 minutes, here is receipt

 Murach's Java Servlets and JSP

 How to get ascii code from a char in Java?

 Can we just try without catch? Yes!

 Make Tomcat page load faster

 Make your Tomcat More secure - limit network address for certain IP addresses

 New Java book online starts now here...

 Implementing RESTful Web Services in Java

 Firefox trimming from 1 GB to 40 Mb with many tabs opened

 SSL with GlassFish v2

 My request to replublish Tech Tips

 Search JavaFAQ.nu site here

 New Advanced Installer for Java 6.0 brings XML updates and imports 3rd party MSI

 EJB programming restrictions

 Maven vs Ant or Ant vs Maven?

 Why Java does not use default value which it should?

 How to unsign signed bytes in Java - your guide is here

 The Java Lesson 3: Identifiers and primitive data types. Page 2

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 4

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 3


[ More in News Section ]


Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy