|
Java Examplets
Compiled
by Rodelio P. Barcenas
javax.accessibility
The Quintessential Accessible Object
Setting an Accessible Name for an Image
Button
Setting a Description for Image Icons
Setting a Mnemomic for Buttons
Setting a Mnemonic for a Menu
Associating a Label with a Component
Setting a Keyboard Accelerator for a
Menu Item
java.applet
The Quintessential Applet
Getting an Applet Parameter
Making the Browser Visit a URL
Showing a Message in the Browser's Status
Bar
Loading and Playing Audio in an Applet
Loading and Playing Audio in an Application
Loading and Painting an Image in an Applet
Animating an Array of Images in an Applet
java.awt
The Quintessential Drawing Program
Drawing Basic Shapes
Filling Basic Shapes
Loading an Image
Drawing an Image
Scaling, Shearing, Translating, and Rotating
a Drawn Image
Drawing Simple Text
Drawing Rotated Text
Getting the Dimensions of Text
Drawing Anti-Aliased Text and Graphics
Drawing with Alpha
Setting the Clipping Area with a Shape
Changing the Thickness of the Stroking
Pen
Creating a Shape from a Stroked Shape
Stroking or Filling a Shape
Stroking or Filling with a Color
Stroking or Filling with a Gradient Color
Stroking or Filling with a Texture
Animating an Array of Images in an Application
Setting a Component's Cursor
java.awt.datatransfer
Retrieving Text from the System Clipboard
Placing Text on the System Clipboard
java.awt.dnd
Making a Component a Drop Target
Handling a Drop Event
java.awt.event
Handling Action Events
Handling Key Presses
Handling Mouse Clicks
Handling Mouse Motion
Detecting Double and Triple Clicks
Handling Focus Changes
java.awt.font
Drawing a Paragraph of Text
Getting the Shape from the Outline of
Text
Drawing Text with Mixed Styles
java.awt.geom
Creating a Shape with Lines and Curves
Creating Basic Shapes
Combining Shapes
Scaling, Shearing, Translating, and Rotating
a Shape
java.util.zip
Compressing a File
Decompressing a File
Listing the Contents of a ZIP File
Calculating the Checksum of a Byte Array
java.util.jar
Retrieving the Manifest of a JAR File
java.sql
Connecting to a Database
Creating a Database Table
Entering a New Row into a Database Table
Getting All Rows from a Database Table
Getting Particular Rows from a Database
Table
Updating a Row of Data in a Database
Table
Using a Prepared SQL Statement
java.util
Creating a Set
Creating a List
Creating a Hash Table
Truncating a List
Converting a Collection to an Array
Converting an Array to a Collection
Implementing a Queue
Implementing a Stack
Iterating the Elements of a Collection
Sorting an Array
Finding an Element in a Sorted Array
Finding an Element in a Sorted List
Inserting an Element into a Sorted List
Generating a Random Number
Breaking a String into Words
Reading Properties from a Properties
File
Creating Date Object From a Particular
Date
Parsing a Date Using a Pattern
Reading and Writing a Properties File
Getting and Setting Properties
Scheduling a Timer Task to Run at a
Certain Time
Scheduling a Timer Task to Run Repeatedly
java.io
Constructing a Path
Reading Text from Standard Input
Reading Text from a File
Writing to a File
Creating a Directory
Appending to a File
Deleting a File
Deleting a Directory
Creating a Temporary File
Using a Random Access File
Listing the File System Roots
Setting File Modification Time
Serializing an Object
Deserializing an Object
Traversing a Directory
Reading UTF-8 Encoded Data
Writing UTF-8 Encoded Data
Reading ISO Latin-1 Encoded Data
Writing ISO Latin-1 Encoded Data
java.awt.image
Converting an Image to a Buffered Image
Getting Pixels from a Buffered Image
Getting a Sub-Image of an Image
Creating and Drawing on a Buffered Image
Scaling, Shearing, Translating, and Rotating
an Image
Converting a Color Image to Gray
Blurring an Image
Sharpening an Image
Embossing an Image
java.text
Formatting and Parsing a Locale-specific
Number
Formatting and Parsing Locale-specific
Currency
Formatting and Parsing a Locale-specific
Percentage
Formatting and Parsing a Locale-specific
Date
Formatting and Parsing Locale-specific
Time
Formatting and Parsing a Locale-specific
Date and Time
Determining the Type of a Character
Comparing Strings in a Locale-independent
Way
Determining the Character Boundaries
in a Unicode String
Determining the Word Boundaries in a
Unicode String
Determining the Sentence Boundaries
in a Unicode String
Determining Potential Line Breaks in
a Unicode String
java.beans
The Quintessential Bean
Implementing a Bound Property
Implementing a Constrained Property
Instantiating a Bean
Handling a Property Change Event
Handling a Vetoable Property Change Event
java.math
Operating With Big Integer Values
Operating With Big Decimal Values
Setting the Decimal Place of a Big Decimal
Value
java.net
Creating a URL
Parsing a URL
Reading Text from a URL
Calling a CGI Using POST Method
Resolving a Hostname
Creating a Client Socket
Creating a Server Socket
Reading Text from a Socket
Writing Text to a Socket
Sending a Datagram
Receiving a Datagram
Joining a Multicast Group
Receiving from a Multicast Group
Sending to a Multicast Group
java.awt.print
The Quintessential Printing Program
Getting the Dimensions of a Printed Page
Setting the Orientation of a Printed
Page
Printing Pages with Different Formats
Displaying the Page Format Dialog
Displaying the Print Dialog
java.lang.ref
Holding onto an Object Until Memory
Becomes Low
Determining When an Object Is No Longer
Used
Determining When an Object Is About
to be Reclaimed
java.lang.reflect
Getting a Class Object
Getting the Modifiers of a Class Object
Getting the Interfaces of a Class Object
Getting the Methods of a Class Object
Getting a Constructor of a Class Object
Creating an Object Using a Constructor
Object
Getting the Field Objects of a Class
Object
Getting and Setting the Value of a Field
Invoking a Method Using a Method Object
Getting the Modifiers of a Member Object
Getting the Name of a Class or Member
Object
Determining if an Object Is an Array
Determining the Dimensions of an Array
Getting the Component Type of an Array
Creating an Array
Expanding an Array
Getting and Setting the Value of an
Element in an Array
Overriding Default Access
Creating a Proxy Object
java.rmi
Starting Up the RMI Registry
Defining and Exporting a Remote Object
Looking Up a Remote Object and Invoking
a Method
Passing Parameters to a Remote Method
Returning Values from a Remote Method
Throwing an Exception from a Remote
Method
javax.sound.sampled
Loading and Playing Sampled Audio
Determining the File Format of a Sampled
Audio File
Determining the Encoding of a Sampled
Audio File
Determining the Duration of a Sampled
Audio File
Playing Streaming Sampled Audio
Continuously Playing a Sampled Audio
File
Determining the Position of a Sampled
Audio Player
Determining When a Sampled Audio Player
has Finished Playing
Controlling the Volume of Playing Sampled
Audio
javax.sound.midi
Loading and Playing Midi Audio
Determining the File Format of a MIdi
Audio File
Determining the Duration of a Midi Audio
File
Playing Streaming Midi Audio
Determining the Position of a Midi Sequencer
Determining When a Midi Audio Player
has Finished Playing
Controlling the Volume of Playing Midi
Audio
java.security
Creating a New Key Pair and Self-signed
Certificate
Creating and Signing a JAR File
Creating a New Policy File
Managing Policy Files
Creating a Keyed Digest Using MD5
Getting a Certificate from a Keystore
Checking Read/Write Permission for
a Directory
Checking if One Permission Implies Another
Creating a Secure Random Number
javax.swing
The Quintessential Swing User Interface
Centering a Frame on the Screen
Exiting an Application When a Frame
Is Closed
Creating a Button
Creating a Checkbox Button
Creating a Color Chooser Dialog
Creating a ComboBox
Creating Image Radio Buttons
Retrieving the Selected Button in a
Group
Firing Item Events
Creating a File Chooser Dialog
Displaying Only Directories in a File
Chooser Dialog
Creating an Internal Frame
Creating a List Component
Creating a Scrolling List Component
Setting the Selection Mode of a List
Component
Creating a Menu Bar, Menu, and Menu
Item
Separating Menu Items in a Menu
Creating a Popup Menu
Creating a Progess Bar
Creating Radio Buttons
Creating a Scroll Pane
Creating a Slider
Creating a Split Pane
Creating a Tabbed Pane
Creating a Text Field
Creating a Password Text Field
Creating a Table
Creating a Text Area
Displaying Simple HTML Files
Creating a Toolbar
Creating a Borderless Window
Showing a Dialog Box
Creating Key Strokes and Binding Them
to Actions
Adding an InputMap to a Component
Setting a Tool Tip
Laying Out Components in a Row or Column
Separating Components in a Row or Column
Laying Out Components in a Flow (Left-to-Right,
Top-to-Bottom)
Laying Out Components in a Grid
Laying Out Components Using Absolute
Coordinates
Setting a Border
Adding a Title to a Border
Creating a Compound Border
Determining the Available Look and Feels
Setting the Look and Feel
Painting the Background of a Container
with an Image Pattern
javax.swing.event
Handling Hyperlink Events
Handling Changes to a List Component
javax.swing.filechooser
Adding a Filter to a File Chooser Dialog
javax.swing.tree
Creating a Tree
Handling Selection Events in a Tree
Component
javax.swing.text
Inserting Styled Text in a Text Pane
Inserting an Image into a Text Pane
Inserting a Component into a Text Pane
javax.swing.undo
Adding Undo and Redo to a Text Component
java.lang
The Quintessential Java Application
Exiting a Java Program
The Quintessential Thread
Making an Object Cloneable
Constructing a String
Getting a Substring from a String
Searching a String
Replacing Characters in a String
Replacing Substrings in a String
Converting a String to Upper or Lower
Case
Converting a String to a Number
Shifting Elements in an Array
Copying Elements from One Array to Another
Retrieving the SuperClass of an Object
Getting the Package of an Object
Implementing a Work Queue
Executes a Command
Reading Output from a Command
Sending Input to a Command
Pausing
Getting the Current Time
Getting the Value of a System Property
Setting the Value of a System Property
Using a Thread-local Variable
Loading Native Code
Converting Unicode to UTF-8
Converting UTF-8 to Unicode
Determining a Character's Unicode Block
javax.naming
Creating an Initial Context to the Naming
Service
Looking Up an Object From the Naming
Service
Listing a Context in the Naming Service
Adding, Replacing, Removing, and Renaming
a Binding in the Naming Service
Creating and Destroying a Subcontext
in the Naming Service
Getting an Object's Fully Qualified
Name
Using a URL as a Name to the Initial
Context
Parsing a Composite Name
Parsing a Compound Name
javax.naming.directory
Creating an Initial Context to a Directory
Reading an Object's Attributes from
the Directory
Modifying an Object's Attributes in
the Directory
Creating an Directory Entry
Adding a Binding with Attributes to
the Directory
Performing a Basic Directory Search
Searching the Directory By Using a Search
Filter
Searching a Subtree in the Directory
Cancelling a Directory Search
Getting an Object's Schema from the
Directory
Getting an Attribute's Schema from the
Directory
Authenticating to the Directory
javax.naming.event
Registering for Namespace Changes in
the Directory
Registering for Object Changes in the
Directory
javax.naming.ldap
Setting LDAP Connection Request Controls
Setting LDAP Context Request Controls
Getting LDAP Response Controls
Performing an LDAP ``Extended'' Operation
javax.rmi
Starting the Name Server
Defining and Exporting a Portable Remote
Object
Looking Up a Portable Remote Object
and Invoking a Method
|