Listing 4: xyURLConnection.java
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
/*
//the createURLStreamHandler method returns a protocol handler
//in this case the xy protocol handler
class PersonalStreamHandlerFactory implements URLStreamHandlerFactory {
public URLStreamHandler createURLStreamHandler(String protocol) {
if (protocol.equalsIgnoreCase("xy"))
{
//return new sun.net.www.protocol.xy.Handler();
return new Handler();
}
else
return null;
}
}
*/
class drawIMGph extends Frame{
Image IMG;
public drawIMGph(String title)
{
super(title);
}
public void init(MemoryImageSource mis)
{
IMG=createImage(mis);
setSize(IMG.getWidth(this)+50,IMG.getHeight(this)+50);
setVisible(true);
}
public void paint(Graphics g)
{
g.drawImage(IMG,45,40,this);
}
}
class TestProtocolHandler{
public static void main(String argv[]) throws Exception{
//setting "manualy" the xy protocol handler
//URL.setURLStreamHandlerFactory(new PersonalStreamHandlerFactory());
//as you can see the URL is specific to the xy protocol handler
URL url=new URL("xy:X//localhost/image.xy");
//getting the resource content
MemoryImageSource mis=(MemoryImageSource)url.getContent();
drawIMGph t=new drawIMGph("Protocol Handler");
t.init(mis);
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|