? ? ? How Do I... ? ? ?
HOME RESOURCES JOBS JAVA STORE
New Topic Forums, just installed July 3! Post questions and answers for others to see immediately. Post your questions now!
In reponse to many requests, we have returned to our "frameless" How-Do-I layout.
If you prefer the version with frames, click here!
  • Post Java programming questions
  • Examine answers to questions
  • Submit your own answers - answers are posted with appropriate credit.
Welcome to the How-Do-I section of The Java Developer. This site is intended as a no-nonsense resource for Java programmers to share information about Java. All areas of Java development will be covered, focusing on real-world applications of the language. It is intended for developers and programmers of all levels. As such, it is your resource, and needs your input.

We hope the site is useful to you, and encourage any comments you may have regarding its operation or content! The Java Developer is updated almost daily, in order to provide quick response to input. Items containing new information are labeled NEW or NEWEST. Check Sun's bug list for tool-related problems. Security Policies.

QuickChat QuickChat

QuickChat is a lightweight text-only Java chat room, for quick and easy interaction.

How Do I?
Questions! Answers!

Categories

Search
(The full text of all answers is searched)

Please enter up to 10 words to search for:
(case insensitive)


Questions

or

Digital Focus reserves the right to edit, reproduce or distribute any material submitted
(just like any magazine editor!)


Popular Questions By Category... (Questions in bold have answers)

Threads and Multiprocessing

? How can you use threads for background processing?
? How can you efficiently synchronize two threads,
if one thread depends on the other for data or tasks, but the processing time of at least one thread is indeterminate? (Hint: is a synchronized queue the answer?)
? Can one thread interfere with another?
? How can I keep track of thread execution time?
? How do I set up a PipedInputStream and PipedOutputStream to an external process?
? How can I get threads to communicate with each other?
"I would like some notifcation to the main thread, that the slave has done something so that the main thread can do something else."
? How do I wake up a suspended thread? Can I wake a sleeping thread?
? How do I spawn an external program in Java, pass parameters to it, and return to your Java program?
? How do I get two Java Applets to load at the same time?
? How do I asynchronously send information or requests to a server program, and at the
same time listen for responses, without getting deadlocked?
Threads & Multiprocessing Topic Forum


Communications

? How can you make two applications communicate on two different machines,
using an http server to facilitate?
? Does the Java JDK for NT support NETBEUI on a standalone system,
or does one need to be running TCP/IP?
? How does one create a UDP ServerSocket? Send and receive a datagram?
? How do I obtain htons()/ntohs() translation, service-to-portnum mapping, and make ioctl calls?
? How do I get the IP address of the user viewing the page/applet right now?
? How do I establish two way communication between the two applets
running on two different machines?
? How do I get the IP address of the http server which served an applet?
? How do I get an application listening on a socket, receive incoming data and echo it back to the sender?
? How do I open an FTP session in Java?
Communications Topic Forum


Unicode and ASCII

(For information on the Unicode standard, see http://www.stonehand.com/unicode.html)
? How can you read and write unicode? Ascii?
? How can you read and write binary data?
? How can I have my applet display different languages, (e.g. Chinese , Japanese...)
using the fonts at the client side?
Unicode and Ascii Topic Forum


Exceptions

? How can you handle an exception within a method,
but still allow any calling methods to subsequently handle the exception as well?
? How can you define range exceptions that protect all of your code?
Exceptions Topic Forum


Java Language

? How can you pass a parameter by reference?
? How do I make an array of classes in Java?
? How do I accomplish the equivalent of the C++ sizeof operator?
? How do I compare the value of two String's (or other objects)?
"The expression (string1 == string2) does not seem to work!"
? How do I create my own packages?
? How do I ask a Java object to list its member variables and/or methods?
Java Language Topic Forum


Data Structures and Algorithms

? How can you create a linked list?
? How can you create a general purpose (extensible) object type that can belong to multiple lists?
? How can you build a B-tree?
? How can you perform a bubble sort? A quick sort?
? How can you implement a stack?
? How can you implement a queue?
? How do I implement a dot product for an array of numbers?
? How do I parse doubles from a String?
Data Structures and Algorithms Topic Forum


Files and File I/O

? How do you create and access an index-sequential file?
? How do I read from a file on a server? Check if a file exists?
? How do I write to a file on a server?
? In a Java application running in the interpreter, how do I change directories on the local drive?
Files and File IO Topic Forum


Applications

? How can you build a simple (extensible) spreadsheet class?
? How can you build a simple (extensible) text editor?
? How can you create a simple query form?
? How can you create an order-processing transaction form?
? How do I recognize regular expressions?
? How do I make a moving banner?
With fast-forward, rewind, and stop features?
? How do I parse a complex ASCII text file?
? How do I make an application send email? Receive email?
? How do you implement drag and drop between the file system and an applet?
? How do you print to a printer with Java and within an applet?
? How can I create an inline (i.e. within browser window) GUI (with Menubar, scrollbar etc) in a java applet?
Applications Topic Forum


Memory Management

? How do you recover from out-of-memory without using more memory?
? What is the proper way to check memory availability?
? How do you allocate stack space and heap space for your application?
Can these be dynamically changed? Can you define exceptions that enlarge them when necessary?
? How do I know if my application design "outruns" the built-in garbage collection?
Memory Management Topic Forum


Event Processing

? How can you capture keyboard events?
? What is the framework of the basic event-driven application?
? How do you post an event?
? How can you define an event and respond to it?
? What is the deliverEvent() method for? How is it different from postEvent()?
? How can a Component instance notify an enclosing Container
that it has received and handled an event, such as a button press?
? How do I force an Event to be sent immediately to an applet, even (especially) when there are
other cpu-intensive applets running?
? What is the order in which events are passed to handleEvent(), action(), and the component-specific
event methods such as keyDown()?
Event Processing Topic Forum


GUI Components and Techniques

  • Buttons and Checkboxes
  • Choices and Lists
  • Windows, Dialogs, Frames
  • Menus, Keyboard Accelerators
  • Labels
  • Scrollbars
  • Text Components
  • Fonts
  • Layout Managers and Panels
  • Canvases, Techniques, Other
  • GUI Components and Techniques Miscelaneous Topic Forum


    Buttons and Checkboxes

    ? How can you display buttons and execute methods within the buttons?

    Choices and Lists

    ? How do I avoid display flicker when updating the contents of a Choice object?
    ? How do you delete an item from a Choice list? (Is there a workaround?)
    ? How do I trap the event where an item is selected from a List or Choice object?
    Choices and Lists Topic Forum


    Windows, Dialogs, Frames

    ? How can you make a floating dialog box?
    ? How can I create a frame within a frame?
    ? How do I customise/modify the behaviour of a FileDialog?
    ? How can I change the icon of my application using the method setIconImage()?
    ? How do I change the mouse icon when the mouse goes from one component to another?
    ? How do I make a scrollable canvas?
    ? How do I get the width of the visible area of a browser frame?
    ? How can the current "System Metrics" information be obtained, such as border thickness,
    height of the title/caption area, etc?
    ? How do I tell when a window has been resized?
    Windows, Dialogs and Frames Topic Forum


    Menus, Keyboard Accelerators

    ? How do I create a popup menu?
    ? How do you open a menu from within an app. (without the user using the mouse)?
    ? How can you effectively create CTRL and ALT hotkey setups?
    ? How do I modify the behavior of the items on the 'system menu', such as Maximize?
    Menus, Keyboard Accelerators Topic Forum


    Labels

    ? How do I change the color of a Label?

    Scrollbars

    ? How do I change the page increment in a scrolbar?

    Text Components

    ? How do you create a scrollable list of text items
    where each item has a different background color?
    ? How can I determine if a TextArea or TextField has been modified?
    ? How do I display right justified values such as integers?
    ? How do I make an automaticly scrollable window (like the Motif one)?
    ? How do I specify floating point number formats (ie: number of digits, etc) when printing strings
    and/or setting text. Is there anything like the C printf statement?
    ? How do I manually position the cursor within a TextField component?
    Text Components Topic Forum


    Fonts

    ? How do I get and use the list of installed fonts using getFontList()?

    Layout Managers and Panels

    ? How do I create my own resizable components that are correctly laid out with the typical layout managers
    (such as BorderLayout)? Apparently providing a minimumsize() method is not sufficient.
    ? How do I use GridLayout?
    ? How do I use BorderLayout?
    ? How do I use GridBagLayout?
    ? How do I use CardLayout?
    ? How do I modify the behavior or policies of a layout manager, e.g the inset used?
    ? How do I override a layout manager's arrangement of components and place the components manually?
    Layout Managers and Panels Topic Forum


    Canvases, Techniques, Other

    (See also 2-D/3-D Graphics, VRML, and Simulation for graphics-related issues)
    ? How can you detect a mouse movement or click?
    ? How can you set/detect focus?
    ? What is the framework of the basic window/mouse application?
    ? How can you redefine the appearance of a button? A window border?
    ? How can you provide support for pen or tablet input?
    ? How do you extend the environment to handle a new device type?
    ? In an applet, how do I display a sub-portion of an image
    and use scrollbars to scroll that sub-portion around in the larger image?
    ? What exactly is the interaction between repaint() and update()/paint()?
    How do I indicate that only certain parts of my display need to be updated?
    ? What is the purpose of the atw.peer class tree?
    ? How do I test whether a mouse click is within a certain part of an image?
    ? How do I get the size of the display?
    ? How do I force a repaint of one component from another, when both belong to the same container?
    Canvases, Techniques, Other Topic Forum


    Images and Multimedia

    Images Files, Sound Files, Video Files, Techniques
    ? How can I display a GIF or JPEG-image coming from a byte[]-buffer?
    ? How do I load an Image into a standalone Java application
    panel (i.e. one that does not have a base URL)?
    ? How do I read and write a GIF file?
    ? How do I save the contents of a panel as a .GIF file?
    ? How do I use the multi-frame feature in ImageObserver to update a changing image?
    ? How do I load an Image from a GIF/JPEG and have it NOT DITHERED when displayed on an 8-bit display?
    ? How can my applet inherit the background color of the HTML page that it is on?
    ? How can an applet set it's background color to "transparent" so that it can display text over a background
    image specified in the HTML BODY tag?
    ? How do I make Java use the palette from a GIF or JPEG obtained with getImage(), instead of
    converting it to the default palette?
    ? How can you play a .au (audio) file?
    ? How can you play a .wav (audio) file?
    ? How can you play a .midi file?
    ? How can you play a .mov (movie) file?
    ? How can you play a .mpeg file?
    ? How many sound channels do I have in Java?
    ? How does one (use Toolkit.sync() to?) flush the buffer of things to be drawn and hence
    bring the display up to date?
    ? How do I play a .avi file?
    ? How do I get an applet to sleep until an image has loaded?
    ? How does the ImageObserver work with an Image to get the width of an Image?
    ? How do I know when an image has been loaded? Displayed?
    ? How do I use the FilteredImageSource? How do I create a filter for an image?
    ? How do I load an image in a Netscape Java applet? (Toolkit.getImage() doesn't work.)
    Images and Multimedia Topic Forum
    Moderated by Richard Wray


    2-D/3-D Graphics, VRML, and Simulation

    ? How can you display text on the screen?
    ? How can you draw a line?
    ? How can you fill a region?
    ? How can you display an image on the screen?
    ? How can you clip a (rectangular and other) region?
    ? How can you drag an image around the screen?
    ? How can you retrieve the regions that need updating from a Graphic object when paint() is called?
    ? How can you display CMYK colors?
    ? How can I draw offscreen using double-buffering?
    ? How does one get and set individual pixels in an Image?
    ? How do I draw a dithered or a stippled polygon, rectangle etc.?
    ? How can I avoid flicker by displaying a background graphic once,
    and then just modifying the foreground in response to events?
    ? How do I change the size of the "pen" when drawing lines?
    ? Given a screen image, how does one "copybits" a polygonal region from one place in the applet window
    to another?
    ? How do you draw in only one of the A/R/G/B-channels of an image?
    ? How do I rotate images along different directions as the time changes?
    ? How can you scroll an image across the screen without leaving a trail or having to
    re-draw the enture background each time (sprite animation)?
    ? How do I resize a GIF when using getImage and then drawImage?
    ? How do I get the size a text string will be onscreen?
    ? How do I do (quick) bitmap style collision detection? (For interactive animations.)
    ? How do I generate a simple VRML scene from Java?
    2-D/3-D Graphics, VRML, and Simulation Topic Forum


    Native Application Interfaces & Databases

    ? How can you access an ACCESS database?
    ? How can you access a SYBASE database?
    ? How can you access an ORACLE database?
    ? How do I interface to a C++ class from Java?
    ? How do I call a native method from within an applet (not just from a stand-alone Java application)?
    ? How do I call a Java method from within a native method?
    ? How do I impliment the syslog functionality in java?
    ? How do I use C++ class libraries to bind with java script?
    ? How do I access an Ingress database from Java?
    ? How do I access an ObjectStore database from Java?
    ? How do I pass an array object (or a 2-D array object) from Java to C?
    How do I fill in a Java array object's elements in C?
    Native Application Interfaces and Databases Topic Forum


    Platform-Specific

    ? How can you call a Windows DLL?
    ? How can you access the Windows paste buffer?
    ? How can you grab the HWND handle for the browser you are using
    so that you can display information in the client region using a native method in JAVA?
    ? How do I create a standalone native program (binary) that invokes the Java interpreter?
    ? How do I communicate with a serial port on PC?
    Platform-Specific Topic Forum


    Environment, Virtual Machine, Class Loaders

    ? How can I execute an operating system command from a Java application?
    (e.g. the "dir" or "ls" command)
    ? How do I load and instantiate a class under program control?
    ? How can a new SecurityManager be used to set different security policies for an application?
    ? How do I get the CLASSPATH variable (and other system variables)?
    Environment, Virtual Machine, Class Loaders Topic Forum


    Browsers, OLE, DDE, SDI, CCI, NEO...

    ? How do I have my applet send the browser to a new location?
    ? How do I send an http server a request for an object,
    and have it pass the content back to the browser to process it like an html (or any other kind of) page?
    ? How can applets on the same page communicate?
    ? How do I retrieve an HTML page and extract (parse) out only the data I need to use?
    ? How do I design an applet to run in both a browser and as a standalone application?
    ? How do I specify an applet that resides on a remote machine?
    ? How do I display HTML generated by an applet?
    ? How do I keep an applet running as the user moves away from
    the page that launched my applet?
    ? What information can I get about the current applet context?
    How do I get the current location of the browser?
    ? How do I get the current HTML content? the Bookmarks the user saved? the Go list? the current browser font?
    ? How would one go about writing the specialized classes necessary in
    Java to support reading and writing Annotation files such as Mosaic creates?
    ? How do I get Netscape2.0 on a PC to go to a page that does have Java applet on it and
    Netscape2.0 on a Mac witch does not have java to stay on the fisrt page?
    ? How can I programmatically access an applet from JavaScript within the
    Netscape Navigator browser?
    ? How do I show a document in one Netscape frame under the control of an applet
    running in another frame? and do this reapeatedly?
    ? How do you make an applet that only runs in the background, i.e. has no area on
    the HTML page to paint?
    ? How do I display the contents of a remote location defined by a URL within a container of an applet?
    ? How do I interface with DDE?
    ? html#BR_17"> How do I cause the browser to load a new applet, based on information obtained in the current applet?
    ? How do I get the URL of documents showing in other Netscape frames?
    ? How do I update an applet in a static Netscape frame when I load new content
    into another (dynamic) Netwscape frame? "For example, I would like a scrolling banner in one frame to announce the content that is displayed in another frame."
    ? How do I access username/password-protected URLs on an HTTP server?
    (i.e. how do I actually send the username and password to the server?)
    ? How do I create a frame without the warning window at the bottom?
    Browsers Topic Forum
    Moderated by Mike Shoffner


    CGI, Servers

    ? How can I get a server's CGI script to send information to an applet?
    ? How can I send an image over the net
    using the Socket, InputStream and OutputStream commands ?
    ? How can an applet call a CGI script that is expecting a POST method?
    ? How do I open a connection to a file on a server for reading and writing?
    ? How do I retrieve an html page which is on an http server using authentication?
    ? How can Java be used to simulate HTML form submission?
    ? How can I write a server-side CGI program in Java for handling a POST?
    ? How do I implement a basic HTTP Server in Java?
    ? How do I implement an image map with Java?
    ? How can an applet call a CGI script that is expecting a POST method AND
    display a returned HTML document in the browser?
    CGI, Servers Topic Forum


    This site is sponsored by Digital Focus, Inc., Falls Church, Vtalfocus.com">