devxlogo

The Latest

Hiding VBScript and JavaScript from Old Browsers

Web page “graceful degradation” means making new capabilities invisible to older browsers that don’t support them. Many authors hide VBScript or JavaScript code inside an HTML comment so that older

Preventing Undefined JavaScript Function Errors

You can define JavaScript functions anywhere in an HTML file, however, the best place to define them is in the HTML header (between the and tags). If a JavaScript function

Checking for an Uncaught Exception

A thrown exception is considered caught, when its corresponding handler has been entered (or, in case such a handler cannot be found, when unexpected() function has been invoked). Sometimes you

Getting Table Cell Background Colors to Display

Some browsers do not display a table cell’s background color unless the cell contains some HTML content. It is often handy to use table cell background colors to “paint” a

STL Iterators are not Necessarily Pointers

Most implementations of STL (Standard Template Library) use pointers as the underlying representation of iterators. However, an iterator doesn’t have to be a pointer, and there’s a good reason for

A Workaround for Namespace-less Compilers

Since namespaces are relatively new in C++, some compilers do not support this feature yet. To workaround this lack of support, you can use struct holding static member functions: struct

Invoke “Open With …” Dialog Box

When launching a data file with the ShellExecute() function, Windows tries to find the associated application and open the data file with this application. But what happens if no association

SSTab vs. Option Buttons

Although VB’s SSTab control behaves as if each tab page is a container, it actually uses a single container for all tab pages. This can cause unexpected behavior if you

Deleting an Array Element

Conventional wisdom suggests that to delete an array element, you must move up all the subsequent elements to close the “gap” left by the deleted item. However, if the sequence

Use setTooltipText to Display Entire Title

A nice feature of programs like Netscape’s newsreader is the ability to display the entire title of an article even though only part of it fits in the list box

Use Object.equals(), not ==, for Logical Comparison

One of the most common gotchas for beginning Java programmers involves comparing Objects, especially Strings, with the == operator. Every Object in Java has a unique location in the Java

Beginning Swing-Based Applications

When you begin all Swing-based applications, you must set the look and feel and add a WindowListener so that when a user clicks on the exit box, the program exits.

Using JToggleButtons Inside the JToolBar

JToggleButtons work well when you want buttons that stay down or up inside the JToolBar. You can also make them behave like Radio buttons (only one button down at a

Playing a Sound Automatically Using META Tags

If you want to play a sound when someone visits your Web page, an effective, simple, browser-independent approach is to insert a META refresh tag that loads the sound file.

Suppress Trailing Zeros on Output

The format string “%f” in printf() call displays trailing zeros of its argument: float num = 1.33; printf( “%f”, num); // output: 1.330000 To get rid of the trailing zeros,

Absolute Layout Manager

Question: Do you know of any LayoutManager that would allow me to lay out components exactly where I want them, or any other way of doing so? Answer: There is

Converting IP Address Formats

Question: Is there a Java equivalent class or method for the Unix Internet address manipulation routines like inet_ntoa()? Answer: Java does not have direct analogs for the inet functions that

RMI method invocation

Question: I want my RMI server application to populate a java.awt.List with data on the client with a method invocation. What’s the best way to do this? Answer: When writing

JTable Headers

Question: I would like to add an icon to the header of a column of a JTable indicating the direction the column is currently sorted. Answer: It can be pretty

Installing Own Colormap

Question: How can I make my Java application install its own colormap? Answer: The ability to allow a Java application to install its own colormap is not supported by the

HTML File to Download CAB File

Question: I have a CAB file produced by Wise Installation System 7.0 that contains an application setup.exe. I need to create an HTML file that will download the CAB file.

Function Try Blocks

A function try block is a function whose body consists of a try block with its associated handlers (catch-statements). A function try block is probably most often used in a

Exception Specifications are Checked at Run Time

A function can specify explicitly what type of exception it may throw. An exception specification, however, is not checked at compile time, but rather at run time: class X {};int

Square Buttons in the JToolBar

When placing JButtons in the JToolBar, use gif icons that are 25 x 25 pixels. Then create a ToolButton class that sets the insets to zero so that the buttons

Alternative Java Coding Environment

For quick Java development, consider using MicroEdge’s Visual SlickEdit (http://www.slickedit.com) instead of an IDE. It recognizes and highlights Java keywords and inserts braces and indents code correctly. To make it

Alpha to Integer Conversion

C and C++ programmers are accustomed to using the atoi() function to convert strings to numeric integer values. Although Java doesn’t have an atoi() method, it provides the same capability