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 13. (The basics) Progress Bars, Sliders, and Scroll Bars. Easy for reading, Click here!

Custom Search
Swing Chapter 13. (The basics) Progress Bars, Sliders, and Scroll Bars. Easy for reading, Click here!

[ Return to Swing (Book) ]

Page: 4/5 



Previous Page Previous Page (3/5) - Next Page (5/5) Next Page
Subpages: 1. JBounded-range components overview 
2.
Basic JScrollBar example 
3.
JSlider date chooser 
4. JSliders in a JPEG image editor 
5. JProgressBar in an FTP client application 

13.4  JSliders in a JPEG image editor

Java 2 ships with a special package, com.sun.image.codec.jpeg, providing a set of classes and interfaces for working with JPEG images (created at least in part by Eastman Kodak Company). Although this package is not a part of Swing, it can be very useful in Swing-based applications. By reducing image quality (which is actually a result of compression), required storage space can be decreased. Using reduced quality JPEGs in web pages increases response time (by decreasing download time), and our editor application developed here allows us to load an existing JPEG, modify its quality, and then save the result. JSliders are used for the main editing components.

Note: JPEG stands for Joint Photographic Experts Group. It is a popular graphical format allowing compression of images up to 10 or 20 times.

Before deciding to use functionality in this package, you should know that, even though this package is shipped with Java 2, "... the classes in the com.sun.image.codec.jpeg package are not part of the core Java APIs. They are a part of Sun's JDK and JRE distributions. Although other licensees may choose to distribute these classes, developers cannot depend on their availability in non-Sun implementations.  We expect that equivalent functionality will eventually be available in a core API or standard extension."

13.4.1 The JPEGDecodeParam interface com.sun.image.codec.jpeg

abstract interface com.sun.image.codec.jpeg.JPEGDecodeParam

This interface encapsulates parameters used to control the decoding of a JPEG image. It provides a rich set of getXX() and isXX() accessor methods. Instances contain information about how to decode a JPEG inpout stream, and are created automatically by JPEGImageDecoder (see below) if none is specified when an image is decoded. A JPEGImageDecoder's associated JPEGDecoderParam can be obtained with its getJPEGDecodeParam() method.

13.4.2  The JPEGEncodeParam interface

abstract interface com.sun.image.codec.jpeg.JPEGEncodeParam

This interface encapsulates parameters used to control the encoding of a JPEG image stream. It provides a rich set of getXX() and setXX() accessor methods. Instances contain information about how to encode a JPEG to an output stream, and a default instance will be created atomatically by JPEGImageEncoder (see below) if none is specified when an image is encoded. A JPEGImageEncoder's associated JPEGEncodeParam can be obtained with its getJPEGEncodeParam() method, or one of its overriden getDefaultJPEGEncodeParam() methods.

Particularly relevant to this example are JPEGEncodeParam's xDensity, yDensity, and quality properties, which all can be assigned using typical setXX() methods. xDensity and yDensity represent horizontal and vertical pixel density, which depends on JPEGEncoderParam's current pixel density setting. The pixel density setting is controlled with JPEGEncodeParam's setDensityUnit() method and can be, for instance, DENSITY_UNIT_DOTS_INCH, which means pixel density will be interpreted as pixels per inch. The quality property is specified as a float within the range 0.0 to 1.0, where 1.0 means perfect quality. In general: 0.75 means high quality, 0.5 means medium quality, and 0.25 means low quality.

13.4.3  The JPEGImageDecoder interface

abstract interface com.sun.image.codec.jpeg.JPEGImageDecoder

This interface describes an object used to decode a JPEG data stream into an image. We invoke method decodeAsBufferedImage() to perform the actual decoding into a BufferedImage instance, or decodeAsRaster() to perform decoding into a Raster instance.  An instance of this interface can be obtained with one of the JPEGCodec.createJPEGDecoder() methods, which takes the delivering data InputStream as parameter. JPEGImageDecoder performs decoding according to its associated JPEGDecodeParam, and a default instance will br provided for is we do not specify one.

13.4.4  The JPEGImageEncoder interface

abstract interface com.sun.image.codec.jpeg.JPEGImageEncoder

This interface describes an object used to encode an image into a JPEG data stream. We invoke the overloaded encode() method to perform the actual encoding. Instances of this interface can be obtained with one of the JPEGCodec.createJPEGEncoder() methods, which takes an OutputStream to output data to as parameter. JPEGImageEncoder performs encoding according to its associated JPEGImageEncoder, and a default instance will br provided for is we do not specify one.

13.4.5  JPEGCodec

class com.sun.image.codec.jpeg.JPEGCodec

This class contains a collection of static methods used to create JPEG encoders and decoders. Particularly useful are the overloaded createJPEGDecoder() and createJPEGEncoder() methods which take an InputStream and OutputStream, respectively, as parameter (along with an optional JPEGDecodeParam or JPEGEncodeParam instance).

Figure 13.6 JPEGEditor showing a high-quality image of Earth (using JSliders with "isFilled client property).

<<file figure13-6.gif>>

Figure 13.7 JPEGEditor showing a reduced quality image of Earth.

<<file figure13-7.gif>>

The Code: JPEGEditor.java

see \Chapter13\4

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

import java.util.*;

import java.io.*;

import javax.swing.*;

import javax.swing.border.*;

import javax.swing.event.*;

import javax.swing.filechooser.*;

import com.sun.image.codec.jpeg.*;

public class JPEGEditor extends JFrame

{

  public final static Dimension VERTICAL_RIGID_SIZE

    = new Dimension(1,3);

  public final static Dimension HORIZONTAL_RIGID_SIZE

    = new Dimension(3,1);

  protected File m_currentDir = new File(".");

  protected File m_currentFile = null;

  protected JFileChooser m_chooser;

  protected JPEGPanel m_panel;

  protected JSlider m_slHorzDensity;

  protected JSlider m_slVertDensity;

  protected JSlider m_slQuality;

  protected BufferedImage m_bi1, m_bi2;

  public JPEGEditor() {

    super("JPEG Editor");

    setSize(600, 400);

    m_chooser = new JFileChooser();

    SimpleFilter filter = new SimpleFilter("jpg",

      "JPEG Image Files");

    m_chooser.setFileFilter(filter);

    m_chooser.setCurrentDirectory(m_currentDir);

    m_panel = new JPEGPanel();

    JScrollPane ps = new JScrollPane(m_panel,

      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

      JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

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

    JPanel p, p1;

    m_slVertDensity = new JSlider(JSlider.VERTICAL,

      100, 500, 300);

    m_slVertDensity.setExtent(50);

    m_slVertDensity.setPaintLabels(true);

    m_slVertDensity.setMajorTickSpacing(100);

    m_slVertDensity.setMinorTickSpacing(50);

    m_slVertDensity.setPaintTicks(true);

    m_slVertDensity.putClientProperty(

      "JSlider.isFilled", Boolean.TRUE);

    p = new JPanel();

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

      "Vert. dens."));

    p.add(Box.createRigidArea(HORIZONTAL_RIGID_SIZE));

    p.add(m_slVertDensity);

    p.add(Box.createRigidArea(HORIZONTAL_RIGID_SIZE));

    getContentPane().add(p, BorderLayout.EAST);

    m_slHorzDensity = new JSlider(JSlider.HORIZONTAL,

      100, 500, 300);

    m_slHorzDensity.setExtent(50);

    m_slHorzDensity.setPaintLabels(true);

    m_slHorzDensity.setMajorTickSpacing(100);

    m_slHorzDensity.setMinorTickSpacing(50);

    m_slHorzDensity.setPaintTicks(true);

    m_slHorzDensity.putClientProperty(

      "JSlider.isFilled", Boolean.TRUE);

    p = new JPanel();

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

      "Horizontal density"));

    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    p.add(Box.createRigidArea(VERTICAL_RIGID_SIZE));

    p.add(m_slHorzDensity);

    p.add(Box.createRigidArea(VERTICAL_RIGID_SIZE));

    p1 = new JPanel();

    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    p1.add(p);

    m_slQuality = new JSlider(JSlider.HORIZONTAL,

      0, 100, 100);

    Hashtable labels = new Hashtable(6);

    for (float q = 0; q <= 1.0; q += 0.2)

      labels.put(new Integer((int)(q*100)),

      new JLabel("" + q, JLabel.CENTER ));

    m_slQuality.setLabelTable(labels);

    m_slQuality.setExtent(10);

    m_slQuality.setPaintLabels(true);

    m_slQuality.setMinorTickSpacing(10);

    m_slQuality.setPaintTicks(true);

    m_slQuality.putClientProperty(

      "JSlider.isFilled", Boolean.TRUE);

    p = new JPanel();

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

      "Quality"));

    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    p.add(Box.createRigidArea(VERTICAL_RIGID_SIZE));

    p.add(m_slQuality);

    p.add(Box.createRigidArea(VERTICAL_RIGID_SIZE));

    p1.add(p);

    JButton btApply = new JButton("Apply");

    ActionListener lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        apply();

      }

    };

    btApply.addActionListener(lst);

    p1.add(btApply);

    JButton btReset = new JButton("Reset");

    lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        reset();

      }

    };

    btReset.addActionListener(lst);

    p1.add(btReset);

    getContentPane().add(p1, BorderLayout.SOUTH);

    setJMenuBar(createMenuBar());

    WindowListener wndCloser = new WindowAdapter() {

      public void windowClosing(WindowEvent e) {

        System.exit(0);

      }

    };

    addWindowListener(wndCloser);

    setVisible(true);

  }

  protected JMenuBar createMenuBar() {

    JMenuBar menuBar = new JMenuBar();

    JMenu mFile = new JMenu("File");

    mFile.setMnemonic('f');

    JMenuItem mItem = new JMenuItem("Open...");

    mItem.setMnemonic('o');

    ActionListener lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) { 

        if (m_chooser.showOpenDialog(JPEGEditor.this) !=

          JFileChooser.APPROVE_OPTION)

            return;

        m_currentDir = m_chooser.getCurrentDirectory();

        File fChoosen = m_chooser.getSelectedFile();

        openFile(fChoosen);

      }

    };

    mItem.addActionListener(lst);

    mFile.add(mItem);

    mItem = new JMenuItem("Save");

    mItem.setMnemonic('s');

    lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        saveFile(m_currentFile);

      }

    };

    mItem.addActionListener(lst);

    mFile.add(mItem);

    mItem = new JMenuItem("Save As...");

    mItem.setMnemonic('a');

    lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        m_chooser.setSelectedFile(m_currentFile);

        if (m_chooser.showSaveDialog(JPEGEditor.this) !=

          JFileChooser.APPROVE_OPTION)

        return;

        m_currentDir = m_chooser.getCurrentDirectory();

        File fChoosen = m_chooser.getSelectedFile();

        if (fChoosen!=null && fChoosen.exists()) {

          String message = "File " + fChoosen.getName()+

            " already exists. Override?";

          int result = JOptionPane.showConfirmDialog(

            JPEGEditor.this, message, getTitle(),

            JOptionPane.YES_NO_OPTION);

          if (result != JOptionPane.YES_OPTION)

            return;

        }

        setCurrentFile(fChoosen);

        saveFile(fChoosen);

      }

    };

    mItem.addActionListener(lst);

    mFile.add(mItem);

    mFile.addSeparator();

    mItem = new JMenuItem("Exit");

    mItem.setMnemonic('x');

    lst = new ActionListener() {

      public void actionPerformed(ActionEvent e) {

        System.exit(0);

      }

    };

    mItem.addActionListener(lst);

    mFile.add(mItem);

    menuBar.add(mFile);

    return menuBar;

  }

  protected void setCurrentFile(File file) {

    if (file != null) {

      m_currentFile = file;

      setTitle("JPEG Editor ["+file.getName()+"]");

    }

  }

  protected void openFile(final File file) {

    if (file == null || !file.exists())

      return;

    setCurrentFile(file);

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    Thread runner = new Thread() {

      public void run() {

        try {

          FileInputStream in = new FileInputStream(file);

          JPEGImageDecoder decoder =

            JPEGCodec.createJPEGDecoder(in);

          m_bi1 = decoder.decodeAsBufferedImage();

          m_bi2 = null;

          in.close();

          SwingUtilities.invokeLater( new Runnable() {

            public void run() { reset(); }

          });

        }

        catch (Exception ex) {

          ex.printStackTrace();

          System.err.println("openFile: "+ex.toString());

        }

        setCursor(Cursor.getPredefinedCursor(

          Cursor.DEFAULT_CURSOR));

      }

    };

    runner.start();

  }

  protected void saveFile(final File file) {

    if (file == null || m_panel.getBufferedImage() == null)

      return;

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    Thread runner = new Thread() {

      public void run() {

        try {

          FileOutputStream out = new FileOutputStream(file);

          JPEGImageEncoder encoder =

            JPEGCodec.createJPEGEncoder(out);

          encoder.encode(m_panel.getBufferedImage());

          out.close();

        }

        catch (Exception ex) {

          ex.printStackTrace();

          System.err.println("apply: "+ex.toString());

        }

        setCursor(Cursor.getPredefinedCursor(

          Cursor.DEFAULT_CURSOR));

      }

    };

    runner.start();

  }

  protected void apply() {

    if (m_bi1 == null)

      return;

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    Thread runner = new Thread() {

      public void run() {

        try {

          ByteArrayOutputStream out = new ByteArrayOutputStream();

          JPEGImageEncoder encoder =

            JPEGCodec.createJPEGEncoder(out);

          JPEGEncodeParam param =

            encoder.getDefaultJPEGEncodeParam(m_bi1);

          float quality = m_slQuality.getValue()/100.0f;

          param.setQuality(quality, false);

          param.setDensityUnit(

            JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);

          int xDensity = m_slHorzDensity.getValue();

          param.setXDensity(xDensity);

          int yDensity = m_slVertDensity.getValue();

          param.setYDensity(yDensity);

          encoder.setJPEGEncodeParam(param);

          encoder.encode(m_bi1);

          ByteArrayInputStream in = new ByteArrayInputStream(

            out.toByteArray());

          JPEGImageDecoder decoder =

            JPEGCodec.createJPEGDecoder(in);

          final BufferedImage bi2 = decoder.decodeAsBufferedImage();

          SwingUtilities.invokeLater( new Runnable() {

            public void run() {

              m_panel.setBufferedImage(bi2);

            }

          });

        }

        catch (Exception ex) {

          ex.printStackTrace();

          System.err.println("apply: "+ex.toString());

        }

        setCursor(Cursor.getPredefinedCursor(

          Cursor.DEFAULT_CURSOR));

      }

    };

    runner.start();

  }

  protected void reset() {

    if (m_bi1 != null) {

      m_panel.setBufferedImage(m_bi1);

      m_slQuality.setValue(100);

      m_slHorzDensity.setValue(300);

      m_slVertDensity.setValue(300);

    }

  }

  public static void main(String argv[]) {

    new JPEGEditor();

  }

}

class JPEGPanel extends JPanel

{

  protected BufferedImage m_bi = null;

  public JPEGPanel() {}

  public void setBufferedImage(BufferedImage bi) {

    if (bi == null)

      return;

    m_bi = bi;

    Dimension d = new Dimension(m_bi.getWidth(this),

      m_bi.getHeight(this));

    setPreferredSize(d);

    revalidate();

    repaint();

  }

  public void paintComponent(Graphics g) {

    super.paintComponent(g);

    Dimension d = getSize();

    g.setColor(getBackground());

    g.fillRect(0, 0, d.width, d.height);

    if (m_bi != null)

      g.drawImage(m_bi, 0, 0, this);

  }

  public BufferedImage getBufferedImage() {

    return m_bi;

  }

}

//class SimpleFilter taken from chapter 14

Understanding the Code

Class JPEGEditor

Class variables:

Dimension VERTICAL_RIGID_SIZE: size of rigid area used for vertical spacing.

Dimension HORIZONTAL_RIGID_SIZE: size of rigid area used for horizontal spacing.

Instance variables:

File m_currentDir: current directory navigated to by our JFileChooser.

File m_currentFile: JPEG image file currently in our editing environment.

JFileChooser m_chooser: file chooser used for loading and saving JPEGs.

JPEGPanel m_panel: custom component used to display JPEGs.

JSlider m_slHorzDensity: slider to choose horizontal pixel density.

JSlider m_slVertDensity: slider to choose vertical pixel density.

JSlider m_slQuality: slider to choose image quality.

BufferedImage m_bi1: original image.

BufferedImage m_bi2: modified image.

JPEGEditor's constructor starts by instantiating our JFileChooser and applying a SimpleFilter (see chapter 14) file filter to it, in order to restrict file selection to JPEG images (files with a ".jpg" extension). creates and initializes the GUI components for this example. Custom panel m_panel is used to display a JPEG image (see the JPEGPanel class below). It is added to a JScrollPane to provide scrolling capabilities. Three sliders are used to select JPEGEncodeParam properties as described above: xDensity, yDensity, and quality. Each is surrounded by a TitledBorder with an appropriate title. Similar to the previous example, RigidAreas are used to ensure proper spacing between the slider and the border. Note that each slider makes use of the Metal L&F client property "JSlider.isFilled" with value Boolean.TRUE to force the lower portion of each slider track to be filled.

Note that the m_slQuality slider must represent values from 0 to 1.0. We scale this interval to [0, 100], but display annotation labels 0.0, 0.2, 0.4,...,1.0 stored in Hashtable labels. The selected image quality value is the slider's value divided by 100. Also note the usage of setExtent() for each slider in this example. Recall that the value of the extent property is used when the slider has focus and the user presses the PgUp or PgDn key to increment or decrement the slider's value respectively.

An "Apply" button is created and assigned an ActionListener to retrieve current slider settings and apply them to current JPEG image by calling our custom apply() method (because of the large amount of work the apply method performs, it does not make sense to do this on-the-fly by listening for slider change events). A "Reset" button  reverts any changes and returns the image to its original state by calling our custom reset() method. Finally a JMenuBar is created with our createMenuBar() method.

The createMenuBar() method creates and returns a JMenuBar containing one menu titled "File," which, in turn, contains four menu items: "Open...," "Save," "Save As...," and "Exit." Each item receives its own ActionListener.

The "Open..." menu item invokes our JFileChooser for selecting a JPEG image file. After a successful selection the current directory is stored in our m_currentDir variable for future use, and our custom openFile() method is invoked to load the image into our environment. The "Save" menu item invokes our custom saveFile() method to save the image currently in our environment. The "Save As..." menu item instructs JFileChooser to prompt the user for a new name, and possibly location, to save the current image file to. This code is fairly similar to the code for the "Open..." menu, except that showSaveDialog() is used instead of showOpenDialog(). If the selected file already exists, a request for confirmation is invoked uwing JOptionPane.showConfirmDialog() (interestingly, this is not a standard feature of JFileChooser--see chapter 14 for more about JOptionPane and JFileChooser). Finally our saveFile() method is invoked to save the current image as the selected file. The "Exit" menu item calls System.exit(0) to quit this application.

The setCurrentFile() method stores a reference to the newly opened file in m_currentFile. This method also modifies the frame's title to display file name. It is called whenever the "Open..." and "Save As..." menu items are invoked.

The openFile() method opens a given File corresponding to a stored JPEG image. First it checks whether or not the selected file exists. If so, a new thread is created to execute all remaining code in this method to avoid clogging up the event-dispatching thread. A FileInputStream is opened and a JPEGImageDecoder is created for the given file. Then a call to decodeAsBufferedImage() retrieves a BufferedImage from the JPEGImageDecoder and stores it in our m_bi1 variable. The file stream is closed and our image is passed to JPEGPanel by calling the reset() method (see below). Note that because our reset method directly modifies the state of Swing components, we place this call in a Runnable and send it to the event-dispatching queue with SwingUtilities.invokeLater() (see chapter 2 for more about invokeLater()).

The saveFile() method saves the current image into the given File. In a separate thread, a FileOutputStream is opened and a JPEGImageEncoder is created corresponding to this File. Then a call to the JPEGImageEncoder's encode() method saves the current image (retrieved by our JPEGPanel's getBufferedImage() method) to the opened stream.

The apply() method applies the current slider settings to the current image. In a separate thread, this method creates a ByteArrayOutputStream to stream the operations in memory. Then a JPEGImageEncoder is created for this stream, and a JPEGEncodeParam is retrieved corresponding to the original image, m_bi1 (which is assigned in openFile()). Three property values are retrieved from our sliders and sent to a JPEGEncodeParam object via setXX() methods: quality, xDensity and yDensity (note that quality is converted to a float through division by 100.0f). Then this JPEGEncodeParam object is assigned to our JPEGImageEncoder, and the encode() method is used to perform the actual encoding of the m_bi1 image. Next a new image is retrieved from this encoder by first retrieving a ByteArrayInputStream from our ByteArrayOutputStream using its toByteArray() method. A JPEGImageDecoder is created for this stream, and the decodeAsBufferedImage() method retrieves a BufferedImage instance. Finally, in a Runnable sent to SwingUtilities.invokeLater(), this image is assigned to our image panel for display with JPEGPanel's setBufferedImage() method.

The reset() method, as you might guess from its name, resets the current image to its original state (the state it was in when opened) and resets the slider values.

Class JPEGPanel

JPEGPanel extends JPanel and provides a placeholder for JPEG images. It declares a single instance variable:

BufferedImage m_bi: holds the current JPEG.

Method setBufferedImage() assigns the given image to m_bi, and changes this panel's preferred size to the size of that image. The panel is then revalidated and repainted to display the new image properly.

Note: We learned in chapter 2 that when a revalidate() request is invoked on a component, all ancestors below the first ancestor whose validateRoot property is true get validated. JRootPane, JScrollPane, and JTextField are the only Swing components with a true validateRoot property by default. Thus, calling revalidate() on our JPEGPanel will result in validation of the JScrollPane it is contained in within our JPEGEditor application. This results in proper layout and display of JPEGPanel which would not occur by simply calling repaint().

The paintComponent() method clears the background and draws the current image (if any). The  getBufferedImage() method simply returns the most recent image associated with this panel.

Running the Code

Figure 13.5 shows JPEGEditor displaying a high-quality image of Earth. Applying our sliders to reduce the quality, and clicking the "Apply" button, we produce the image shown in Figure 13.6. By saving this image as a new file, we obtain a representation occupying much less disk space than the original. A balance between quality and size is a decision that often needs to be made when space or latency issues are important.

UI Guideline : Component Selection

This example provides some tricky problems for the designer. The nature of the calculation means that instant feedback is not possible. However, the User needs to see what the result of a choice would mean. This has been solved by the introduction of the "Apply" button. This is justifiable in a case such as this due to the complex and time consuming nature of the effect of the selection. It is not otherwise recommended.

The introduction of the shaded area on the Sliders gives a clear indication that an amount or quantity rather than an exact, discrete value is being selected and the amount is a percentage of the bounded whole. This adds to the visual affordance of the component and aids the viewer in understanding what is happening.



[ 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