[2069] in java-interest
Returned mail: User unknown
daemon@ATHENA.MIT.EDU (Mail Delivery Subsystem)
Fri Sep 22 17:24:21 1995
Date: Fri, 22 Sep 95 13:37:27 EDT
From: Mailer-Daemon@IConNet.COM (Mail Delivery Subsystem)
To: <java-interest@java.sun.com>
----- Transcript of session follows -----
Connected to nextec.iconnet.com:
>>> RCPT To:<sharmolin@nextec>
<<< 550 <sharmolin@nextec>... User unknown
550 sharmolin@nextec... User unknown
----- Unsent message follows -----
Return-Path: <java-interest@java.sun.com>
Received: by overlord.IConNet.COM (4.1/SMI-4.1)
id AA00937; Fri, 22 Sep 95 13:37:27 EDT
Received: from nextec.iconnet.com(199.173.161.199) by overlord.IConNet.COM via smap (V1.3)
id sma000935; Fri Sep 22 13:36:59 1995
Received: from overlord.IConNet.COM by nextec. (5.x/SMI-SVR4)
id AA00772; Fri, 22 Sep 1995 13:40:04 -0400
Received: by overlord.IConNet.COM (4.1/SMI-4.1)
id AA00932; Fri, 22 Sep 95 13:36:57 EDT
Received: from mail.iconnet.com(199.173.161.113) by overlord.IConNet.COM via smap (V1.3)
id sma000930; Fri Sep 22 13:36:35 1995
Received: from cc:Mail by mail.IConNet.COM
id AA811803166; Fri, 22 Sep 95 13:52:40 EST
Date: Fri, 22 Sep 95 13:52:40 EST
From: java-interest@java.sun.com
Encoding: 647 Text
Message-Id: <9508228118.AA811803166@mail.IConNet.COM>
To: java-interest-digest@java.sun.com
Subject: java-interest-digest V1 #181
Received: by ccmail from java.sun.com
From owner-java-interest-digest@java.sun.com
X-Envelope-From: owner-java-interest-digest@java.sun.com
Received: (from majordom@localhost) by java.sun.com (8.6.12/8.6.12) id XAA28638
for java-interest-digest-outgoing; Thu, 21 Sep 1995 23:30:06 -0700
Date: Thu, 21 Sep 1995 23:30:06 -0700
Message-Id: <199509220630.XAA28638@java.sun.com>
From: owner-java-interest-digest@java.sun.com
To: java-interest-digest@java.sun.com
Subject: java-interest-digest V1 #181
Reply-To: java-interest@java.sun.com
Errors-To: owner-java-interest-digest@java.sun.com
Precedence: bulk
X-Info: To unsubscribe, send 'unsubscribe' to
java-interest-digest-request@java.sun.com
java-interest-digest Friday, 22 September 1995 Volume 01 : Number 181
In this issue:
Re: Fn ptrs & ... callbacks!?
Re: Displaying a Gif...
Setting Boundaries (was Re: JDK Question)
Re: Displaying a Gif...
thread.sleep and java.lang.InterruptedException
Re: new Image classes
Re: [Q] protocol of an object
Re: Displaying a Gif...
Re: throws declataration in Java/beta
----------------------------------------------------------------------
From: sw@tiac.net (Steve Witham)
Date: Thu, 21 Sep 1995 22:38:21 -0400
Subject: Re: Fn ptrs & ... callbacks!?
>From: jpayne@starwave.com (Jonathan Payne)
>Subject: Re: method/fn ptrs?
>
>Could you imagine implementing emacs-style keymaps in Java? You'd
>have to implement a KeyAction subclass for each command you want to
>bind to a key. And each one of those subclasses would probably make a
>call to another object that implements all that commands, since they
>would probably rather be all together.
So? What's your point? :-)
>It's also a problem for handling callbacks from GUI controls.
I thought Java got rid of callbacks by having threads...didn't it?
Callbacks are just a dumb, inside-out way to implement threads.
Why try to immitate them in a language that has real threads?
--Steve
Windows '95--Why 1995 will be like 1984.
------------------------------
From: Mentor <mentor@io.org>
Date: Fri, 22 Sep 1995 00:06:41 -0400 (EDT)
Subject: Re: Displaying a Gif...
On Thu, 21 Sep 1995, Karl Asha wrote:
> Would anyone care to show some sample code to simply display a gif
> in a -standalone- java program. Not an applet.
It's simpler than you'd think: First, you set up a window (there's code in the
archives from rizzoti.sven@ch.swissbank.com which tells how). Then, you haul
in the image with one of the following:
String nice_image = "http://www.io.org/~mentor/images/moose.gif";
// one way:
Object o = (new URL(nice_image)).getContent();
// second way:
GifImage i = new GifImage(nice_image);
// third way (more complex, but more general):
URL url = new URL(nice_image);
InputStream in = url.openStreamInteractively();
Object o = url.getContent(in, null);
Cheers,
David Forster
Mentor Software Solutions
<a href="http://www.io.org/~mentor">Mentor Software Solutions</a>
------------------------------
From: James C Deikun <jcdst10+@pitt.edu>
Date: Thu, 21 Sep 1995 20:35:05 -0400 (EDT)
Subject: Setting Boundaries (was Re: JDK Question)
On Mon, 18 Sep 1995, Arthur van Hoff wrote:
> The mandatory networking classes are in java.net. We've got some
> additional classess that we've put in sun.net.* to avoid name
> clashes with other software vendors.
>
> We are in control of what is part of the java.* classes that
> are available in every Java environment. As time goes on we
> will add more functionality in a controlled and upward compatible
> manner.
Speaking of that, I've wondered this since the JDK came out:
Should all this stuff really be required for every Java implementation,
or just every HotJava implementation?
Yeah, some of this stuff is awfully nice, but it sure puts a lot of
weight on the head of the implementor. (Not that this is any surprise
considering the involvement of large corporations here.) I really can't
see why for some purposes a simple implementation containing only files
and text i/o wouldn't suffice. For example, if one were producing a
super-optimized Java runtime for use on dedicated compute servers, I don't
see what the use of being burdened with writing awt classes would be.
Indeed, in contexts like that it would be good for user classes to
*expect* a more restricted environment. After all, on a machine in
Maine, opening up X windows wouldn't be particularly useful to me here in
Pittsburgh, even if they were redirected properly to my X server. (Hey, can
you say "slow"?)
- --
James "e unix pluribus" Deikun
------------------------------
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
Date: Thu, 21 Sep 1995 17:08:51 -0700
Subject: Re: Displaying a Gif...
> Would anyone care to show some sample code to simply display a gif
> in a -standalone- java program. Not an applet.
Unfortunately the standard Java packages do not contain the helper classes
that you need to do this, nor do they contain factory-style APIs to
instantiate the sun-specific classes you need. Only the Applet class
with its AppletContext and AppletStub contain the necessary environment
to get these classes instantiated for you in a portable way.
This is an oversight...
For now, you will have to instantiate one of:
new sun.awt.image.FileImageSource(String filename);
new sun.awt.image.URLImageSource(String href);
new sun.awt.image.URLImageSource(URL u);
which will give you an object that implements "ImageProducer". From that
you can use:
Toolkit.getDefaultToolkit().createImage(ImageProducer ip);
Since this requires you to refer to a class in a sun-specific package
directly, this won't be portable.
...jim
------------------------------
From: Janet.Coursey@Central.Sun.COM (Janet Coursey)
Date: Thu, 21 Sep 95 18:03:40 -0600
Subject: thread.sleep and java.lang.InterruptedException
In the JDK prebeta1 , I get this compiler error:
javac Foo.java
Foo.java:11: Warning: Exception java.lang.InterruptedException must be caught,
or it must be
declared in throws clause of this method.
thread.sleep(150);
^
for this source file called Foo.java ----
import java.lang.Thread;
import java.lang.InterruptedException;
public class Foo extends Object implements Runnable {
private Thread thread;
public void run()
// throws java.lang.InterruptedException
{
thread.sleep(150);
}
} // class Foo
But when I do what it suggests I get this compiler error:
javac Foo.java
Foo.java:8: Invalid exception class java.lang.InterruptedException in throws
clause. The
exception must be a subclass of an exception thrown by void run() from
interface
java.lang.Runnable.
public void run()
^
for this source---
import java.lang.Thread;
import java.lang.InterruptedException;
public class Foo extends Object implements Runnable {
private Thread thread;
public void run()
throws java.lang.InterruptedException
{
thread.sleep(150);
}
} // class Foo
Now in the JDKprebeta1, java/lang/Runnable.java,
the run() method does NOT declare any throws. So how can I possibly achieve the
compiler's
recommendation to "The exception must be a subclass of an exception thrown by
void run() from
interface java.lang.Runnable"?
[The run() body will actually do some work if i get past this problem; this was
the smallest code to
recreate the situation.]
Thanks in advance,
Janet
------------------------------
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
Date: Thu, 21 Sep 1995 17:02:37 -0700
Subject: Re: new Image classes
- ----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 68
> I'm tyring to convert my applets from alpha3 to beta, but I'm stuck on how
> to replace my use of DIBitmaps. I just want to get at the raw data of an
> image - I don't want to filter it or produce a new image, I just want to know
> the pixel value at a given coordinate. Can anyone show me a simple way of
> doing this?
There is no direct API for doing this since we don't necessarily have the
pixels for the image loaded into memory at any given time for two reasons:
1) We wanted to have the image data loaded asynchronously so
that Applets wouldn't get stuck waiting for image data to
come over the network while we were busy trying to layout
or paint the document (busy running their init() method when
we had other things to get done). This philosophy was carried
out to the extreme to the point that we don't provide any
synchronous methods to get information about an Image...
2) We may not have enough unfragmented memory laying around to
store all of the pixels for the image. Many of you may remember
that the Alpha 3 browser often failed to load large images
after running for a while since the heap could get fragmented
and there wouldn't be enough contiguous space to put the
array of pixels - thus pixel data is now only ever delivered
piecemeal and should be digested, put to use, and then dropped
on the floor (the image loaders save the data in special pixel
buffers that use "Ref" objects which allow asynchronous
reclamation of the space that they use and will avoid having
to refetch the image if their pixel buffer hasn't been freed,
so Applet programmers should not hold onto the image data
themselves if at all possible).
The idea behind the ImageFilter objects was that if you filter an
image, then you should filter it as the data is delivered rather than
to grab a buffer of pixels for the image, modify the pixels, and then
turn around and make a new image from that buffer. This doesn't work
when you need to filter lots of large images. The beta version of the
Sun home page now loads much more frequently in a lot less memory since
the ImageMap applet now uses dynamic filters rather than getDIBitmap
and createImage to make its button highlight areas...
For those cases when you need to query the contents of an image for
other purposes, then all you need to do is to create an object which
implements the ImageConsumer interface and attach it to the image's
ImageProducer. The ImageConsumer object will then have the image's
data fed to it asynchronously - when it gets what it wants, it can then
remove itself and return the information.
I wrote an example of this kind of class, which is attached below. To
use it you would write:
int[] pix = new int[w * h];
PixelGrabber pg = new PixelGrabber(img.getSource(),
x, y, w, h,
pix, 0, w);
pg.grabPixels();
When that method returns, the pix array will contain the data for the
specified subrectangle of the image in the default RGB format (see
ColorModel.getRGBdefault()). Note that since the grabPixels method
can take an arbitrarily large amount of time to complete, you should
not call it during any of an applet's methods that may be called by
a system thread (such as init(), paint(), or update()). Instead, call
it from a helper thread you create to do asynchronous setup.
Hope this helps!
...jim
- ----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: PixelGrabber.java
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 144
import java.util.Hashtable;
import java.awt.image.ImageProducer;
import java.awt.image.ImageConsumer;
import java.awt.image.ColorModel;
public class PixelGrabber implements ImageConsumer {
ImageProducer producer;
int dstX;
int dstY;
int dstW;
int dstH;
int[] pixelbuf;
int dstOff;
int dstScan;
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h,
int[] pix, int off, int scansize) {
producer = ip;
dstX = x;
dstY = y;
dstW = w;
dstH = h;
dstOff = off;
dstScan = scansize;
pixelbuf = pix;
}
public synchronized void grabPixels() throws InterruptedException {
producer.startProduction(this);
wait();
}
public void setDimensions(int width, int height) {
return;
}
public void setHints(int hints) {
return;
}
public void setProperties(Hashtable props) {
return;
}
public void setColorModel(ColorModel model) {
return;
}
public void setPixels(int srcX, int srcY, int srcW, int srcH,
ColorModel model,
byte pixels[], int srcOff, int srcScan) {
if (srcY < dstY) {
int diff = dstY - srcY;
if (diff >= srcH) {
return;
}
srcOff += srcScan * diff;
srcY += diff;
srcH -= diff;
}
if (srcY + srcH > dstY + dstH) {
srcH = (dstY + dstH) - srcY;
if (srcH <= 0) {
return;
}
}
if (srcX < dstX) {
int diff = dstX - srcX;
if (diff >= srcW) {
return;
}
srcOff += diff;
srcX += diff;
srcW -= diff;
}
if (srcX + srcW > dstX + dstW) {
srcW = (dstX + dstW) - srcX;
if (srcW <= 0) {
return;
}
}
int dstOff = this.dstOff + (srcY - dstY) * dstW + (srcX - dstX);
int dstRem = dstScan - srcW;
int srcRem = srcScan - srcW;
for (int h = srcH; h > 0; h--) {
for (int w = srcW; w > 0; w--) {
pixelbuf[dstOff++] = model.getRGB(pixels[srcOff++] & 0xff);
}
srcOff += srcRem;
dstOff += dstRem;
}
}
public void setPixels(int srcX, int srcY, int srcW, int srcH,
ColorModel model,
int pixels[], int srcOff, int srcScan) {
if (srcY < dstY) {
int diff = dstY - srcY;
if (diff >= srcH) {
return;
}
srcOff += srcScan * diff;
srcY += diff;
srcH -= diff;
}
if (srcY + srcH > dstY + dstH) {
srcH = (dstY + dstH) - srcY;
if (srcH <= 0) {
return;
}
}
if (srcX < dstX) {
int diff = dstX - srcX;
if (diff >= srcW) {
return;
}
srcOff += diff;
srcX += diff;
srcW -= diff;
}
if (srcX + srcW > dstX + dstW) {
srcW = (dstX + dstW) - srcX;
if (srcW <= 0) {
return;
}
}
int dstOff = (srcY - dstY) * dstW + (srcX - dstX);
int dstRem = dstScan - dstW;
int srcRem = srcScan - srcW;
for (int h = srcH; h > 0; h--) {
for (int w = srcW; w > 0; w--) {
pixelbuf[dstOff++] = model.getRGB(pixels[srcOff++]);
}
srcOff += srcRem;
dstOff += dstRem;
}
}
public synchronized void imageComplete(int flags) {
notifyAll();
}
}
------------------------------
From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
Date: Thu, 21 Sep 1995 13:44:32 -0700
Subject: Re: [Q] protocol of an object
There is no way to do this with the current Java API, unless you are either
willing to use the debugger API or write your own native method. The
problem with using the debugger API is that your app will be difficult to
distribute, since non-developers will be rarely running it. We also
purposely made it easy to delete the debugger entirely (get rid of the
agent shared library and the classes in sun/tools/debug and
sun/tools/ttydebug), for those customers who don't want to distribute it.
You therefore can't count on it being installed, unless you stay on your
own machine.
If you want to write a native method, check out oobj.h -- with a class
object, it's a simple matter to browse its methodtable.
Tom
> From daemon@java Thu Sep 21 00:01:35 1995
> To: java-interest@java.Eng.Sun.COM
> Subject: [Q] protocol of an object
> Cc: neudeca@ch.swissbank.com
> X-Info: To unsubscribe, send 'unsubscribe' to
java-interest-request@java.sun.com
>
> Hi ....
>
> I'm writing on a thesis about travelling objects [8-O], and I was
> thinking about using Java for implementing a prototype...
>
> Now I need a method that delivers dynamically (and at runtime)
> all public methods of an object.
>
> I already did try ObjectScope, but it didn't work.
>
> Any ideas ???
>
> Thanks, Arthy
> -
> Note to Sun employees: this is an EXTERNAL mailing list!
> Info: send 'help' to java-interest-request@java.sun.com
>
------------------------------
From: Karen.Sielski@Eng.Sun.COM (Karen L. Sielski)
Date: Thu, 21 Sep 1995 13:17:34 -0700
Subject: Re: Displaying a Gif...
Try this:
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
import sun.awt.image.URLImageSource;
public class Test extends Frame {
public Test() {
super("ImageTest");
//http bug so use file protocol instead
// String gifURL = "http://sunprowww.eng/~karens/images/Duke.gif";
String gifURL = "file:///home/karens/public_html/images/Duke.gif";
add("center", new ImageCanvas(gifURL));
reshape(0, 0, 300, 200);
show();
}
public static void main(String args[]) {
new Test();
}
}
class ImageCanvas extends Canvas {
Image image;
public ImageCanvas(String imageFile) {
image = (Image)Toolkit.getDefaultToolkit().createImage(
new URLImageSource(imageFile));
reshape(0, 0, 50, 50);
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, 50, 50, this);
}
}
Karen L. Sielski e-mail: karen.sielski@Eng.Sun.COM
SunSoft voice: (415) 786-9005
2550 Garcia Avenue UMPK16-305 FAX: (415)
Mountain View, CA 94043-1100
. From daemon@java Thu Sep 21 12:57 PDT 1995
. From: Karl Asha <karl@one.net>
. To: "'java-interest@java.sun.com'" <java-interest@java>
. Subject: Displaying a Gif...
. Date: Thu, 21 Sep 1995 15:34:21 -0700
. Mime-Version: 1.0
. Content-Transfer-Encoding: 7bit
. X-Info: To unsubscribe, send 'unsubscribe' to
java-interest-request@java.sun.com
.
. Would anyone care to show some sample code to simply display a gif
. in a -standalone- java program. Not an applet.
.
. Cheers.
. Karl
. karl@one.net
.
. -
. Note to Sun employees: this is an EXTERNAL mailing list!
. Info: send 'help' to java-interest-request@java.sun.com
------------------------------
From: arnold@cocolat.East.Sun.COM (Ken Arnold - Sun Labs)
Date: Thu, 21 Sep 1995 18:46:16 -0400
Subject: Re: throws declataration in Java/beta
>But if I can't sleep in the Run method (as the mail below suggests),
>which is something you very commonly want to do, then I think
>something is horribly broken.
As the words on the front of the HHGTTG say:
DON'T PANIC
A method cannot throw an exception type not declared in its throws
clause. This is good. You now know which exceptions can be thrown by
a method.
Obviously this means that an overridden method cannot throw something
not in its the original method, since that would give you a method that
threw something not expected by the invoker who only knew the object as
its supertype. This is good. You still know which exceptions can be
thrown by a method, whether it gets overridden in an extended class or
not.
If a method invokes another method that throws an exception, there are
two cases:
(1) That method is compatible with the calling method's throws clause.
Everying is cool; the calling method can catch or not catch the
exception.
(2) That method is not compatible with the calling method's throws
clause. Everything isn't cool, because if that exception isn't
caught, the calling method could pass through an exception it isn't
supposed to throw. So the calling method must catch that
exception.
Now, let us look at Thread.run(), which throws nothing. Of *course*
you can invoke Thread.sleep(), even though Thread.sleep() throws
InterruptedException. The rule is that you have to *catch* it so it
doesn't leak through to the invoker of run().
Now, you can argue that run() should have a "throws
InterruptedException", but then you have to ask what it means to
"interrupt" run(). What interrupting sleep() means is well known.
Ken Arnold
------------------------------
End of java-interest-digest V1 #181
***********************************
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com