Swing better than Awt?

C

Chris Uppal

Richard said:
Ah, but many do! Speaking as one who came away with a bruised/broken
coccyx after jumping off Richmond Bridge two summers ago (the day before
it reached 100F)

Eek !

then there's that Viles disease, hacked up bodies in suitcases, numerous
discharges from Iselworth treatment works, and the seemingly endless
detritus that most of London seems to deposit in it, and only an idiot
would jump in! That's alcohol for ya :-(


Richmond's about 25 miles downstream from me as the crow flies -- or about 40
as
the corpse floats ;-) So I daresay I'm responsible for some of the detritus...

Anyway WRT Swing -vs- AWT, as a beginner I've been using AWT 'cos I
thought it was a simpler yet still functional interface. Is that wrong?

I'd say that if you /can/ use Swing instead of raw AWT (and most people can),
then Swing's to be preferred. The simplicity of AWT is mainly just from stuff
that's missing, rather than because it has an inherently neater API.

-- chris
 
R

Richard Maher

Hi Chris, et al

Chris Uppal said:
I'd say that if you /can/ use Swing instead of raw AWT (and most people can),
then Swing's to be preferred. The simplicity of AWT is mainly just from stuff
that's missing, rather than because it has an inherently neater API.

Even though I /can't/ do Swing, I'll make a point of looking up Sun's
tutorial on the matter and giving it a go. (The fact that I "can't do" Java,
HTML, JavaScript, or CSS hasn't stopped me so far; how hard can it be? : -)
Actually it's all looking shit-hot at the moment and I'm quite pleased with
the results of this functionality demo/proof-of-concept I've been working
on!)

But before launching into Swing there is one niggle or possible
spanner-in-the-works I'd like to quiz you about, and that is "footprint"
both in terms of memory and bandwidth of a Swing evoking class. In my case
I'm using an Applet that does little more user interaction than pop-up a
couple of dialog boxes before handing control over to the web browser and
html, and find AWT to be a stream-lined gazelle-like creature (albeit
three-legged) and fear Swing could be more like an elephant. Are my fears
ill-founded? Are all the class libraries in the JVM anyway so don't have to
be sent over the network? Will my Class and JAR files be roughly the same
size? Is relative resource consumption (or body mass index) an issue?
Richmond's about 25 miles downstream from me as the crow flies -- or about 40
as
the corpse floats ;-) So I daresay I'm responsible for some of the
detritus...

Yes, I thought that was your Christmas tree I saw floating down with the
others each year. (Not to mention the black rubbish bags that people would
leave out on the tow-path only to have the high-tide take them away :-( Why
"The Royal Borough of Richmond Upon Thames" had yet to discover wheely-bins
is beyond me.) All that aside, you live in a nice part of the world! I miss
the Daffs, Crocuses, and cherry-blossoms this time of the year! The drive
through Richmond park to take the kids to school was also pleasant, as was
driving out through Surrey/Sussex. Henley/Marlow obviously worth a lunch.
Still, it was swnowing there recently, wasn't it? As much as the kids used
to love tobogganing down to Petersham gate, it's almost April and still 30C
here so cop that! :)

Cheers Richard Maher

PS. I bet you that if I knew what I was doing I wouldn't find the fact that
there's only NSEW and Center such a limitation :)

PPS. If I was holding a series of say employee photographs/images as blobs
in a database, can anyone tell me how I would get one of them up into a
web-browser without first having to export it to a .jpeg/.bmp/.gif file? I
must have missed something? I know http servers/browsers are optimized to
have seperate threads for uploading images but nonetheless, what's the
alternative? Can I pass an BufferedImage back from an applet to Javascript?
(And then what would it do with it without a SRC="#something"?)
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Richard said:
But before launching into Swing there is one niggle or possible
spanner-in-the-works I'd like to quiz you about, and that is "footprint"
both in terms of memory and bandwidth of a Swing evoking class. In my case
I'm using an Applet that does little more user interaction than pop-up a
couple of dialog boxes before handing control over to the web browser and
html, and find AWT to be a stream-lined gazelle-like creature (albeit
three-legged) and fear Swing could be more like an elephant. Are my fears
ill-founded? Are all the class libraries in the JVM anyway so don't have to
be sent over the network? Will my Class and JAR files be roughly the same
size? Is relative resource consumption (or body mass index) an issue?

The Swing classes has been part of Java since version 1.2.

Your code may actually shrink a little bit in size because
you may replace some of your code with builtin Swing functionality.

Swing apps do tend to use some memory. But would not consider it
a problem on any PC that is not completely outdated.
PPS. If I was holding a series of say employee photographs/images as blobs
in a database, can anyone tell me how I would get one of them up into a
web-browser without first having to export it to a .jpeg/.bmp/.gif file? I
must have missed something? I know http servers/browsers are optimized to
have seperate threads for uploading images but nonetheless, what's the
alternative? Can I pass an BufferedImage back from an applet to Javascript?
(And then what would it do with it without a SRC="#something"?)

You can do a IMG tag with SRC pointing to a server side script that
sends the image from the database to the browser with the correct
content type.

Or you can use an applet that retrieves the images via socket
and displays it within the applet.

Arne
 
L

Lew

You can do a IMG tag with SRC pointing to a server side script that
sends the image from the database to the browser with the correct
content type.

Or you can use an applet that retrieves the images via socket
and displays it within the applet.

If you are running a servlet engine you can have a servlet stream the image,
and use that servlet as the img tag's src.

I recently implemented such a thing after googling around for some code.

-- Lew
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Richard said:
This is very important to me. Are you really saying "can" or "as far as I
know you used to be able to"? Are you referring to Microsoft's
implementation of Data Source Objects in Internet Explorer or something
else? The reason that I am so sceptical is that I asked the following
question xposted here and c.l.javascript a while back: -

I am referring to showing the image within the applet.

Then it is 100% Java and has nothing to do with browser and JavaScript.

Yes. It is possible.

Arne
 
R

Richard Maher

Hi Arne,

Thanks for the reply.

Arne Vajhøj said:
Or you can use an applet that retrieves the images via socket
and displays it within the applet.

This is very important to me. Are you really saying "can" or "as far as I
know you used to be able to"? Are you referring to Microsoft's
implementation of Data Source Objects in Internet Explorer or something
else? The reason that I am so sceptical is that I asked the following
question xposted here and c.l.javascript a while back: -

----- Original Message -----
From: "Richard Maher" <[email protected]>
Newsgroups: comp.lang.java.programmer,comp.lang.javascript
Sent: Saturday, March 10, 2007 9:24 AM
Subject: Applet as DSO in Browser example? MSIE only?
Hi,

Recently on the web I came across documentation discussing Data Source
Objects (DSO) in relation to browser and html functionality (in particular
the ability to declare a Java applet as a data source that can be used with
any or the HTML tags that take the src="" attribute). I find it interesting
and potentially *very* useful and would like to know more, so if anyone can
answer any of the following questions that would be great: -

1) Do you have an example of an Applet functioning as an applet to something
like a <Table> that I can see?

2) Is this a MicrosoftIE-only feature? I can't find it in other html tag
reference sites. (I'm using w3schools as a sort of yardstick; is that less
than optimal?) What do other browsers do? Is Microsoft deprecating this
along with other Java stuff?

3) I've searched in c.l.j.p/c.l.javascript and the only references to DSOs
appear to be server based (or data sources other than Applet) I'm guessing
they're entirely different beasts; is that correct?

4) Anyone ever passed a BufferedImage over to Javascript for display on a
web page? (I know it'd be single threaded and all those little .GIFs and
.JPEGs are designed for parallel http webservers, but think of a blob in a
database that has an employee photo of geological survey or something. . ..)

Thanks for any help!

Regards Richard Maher

PS. I am already passing result set <options>s back to a <select> list quite
happily; it's the tighter integration between the html tags and my socket
that I'm striving for here.

One of the places I've been looking: -
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/datasources.asp

.. . .and the only answer I got was: -
[
The reference to Java applet on
MSDN is a bit mysterious to me. I guess for IE 4/5 Microsoft allowed
to use their JVM for bridging to the needed ActiveX, so people could
use either <object> or <applet> depending on personal preferences. In
either case it is definitely in relation to the Microsoft own JVM
which is not provided any more. It has nothing to do with Sun plugin.
]

It would be great if you could still do this! Do you (or anyone) have an
example?

Hold on, I've just re-read what your post actually says and not what I
wanted it to say "displays it within the applet." :-( I assume that means
as opposed to displaying it within the browser?

Cheers Richard Maher
 
R

Richard Maher

Hi (again) Arne,

On second thoughts, this might not be so bad if I knew what I was doing.

Would it be fair to say that I could embed an Applet <Object> tag within a
<DIV> or an <IFrame> and then have complete flexibility in positioning,
size, style of whatever the applet paints "within" the browser? I'm guessing
<object> attributes such as height and width can be manipulated with DOM
like any other; is that right? This is beginning to sound pretty sexy!

I don't know enough about graphics and how paint() works, and I'm struggling
to disassociate the Applet code from its html tag presence; Does anyone have
a small example of this in progress? (Yes, I will do more RTFMing :)

What if two tags call the same applet; does init() get called twice? Two
instances of the applet of just one? two pannels,frames,canvasses and just
one applet?

What if there are three Applets active in the frameset; How can they invoke
each others methods without having been aware of each other at compile-time?
Given the (at least by default) single-threading of browser-applet
interaction, can I share the one socket connection between the three? Is
there global memory/references?

I've got a JavaScript DOM (getElementById) identifier that lets JS lnow when
I'm calling a given applet's methods but surely this handle/object-instance
would be of little use in telling applet[2] about the existance of applet[1]
(and its methods)?

I think this is getting into that dynamic activation stuff that you told me
about (and I didn't understand :) the first time - Sorry. An example would
really, really help here though.

Let's start small - "An example of an Applet painting and Image in a
browser" any takers? websites?

Cheers Richard Maher

Richard Maher said:
Hi Arne,

Thanks for the reply.

Arne Vajhøj said:
Or you can use an applet that retrieves the images via socket
and displays it within the applet.

This is very important to me. Are you really saying "can" or "as far as I
know you used to be able to"? Are you referring to Microsoft's
implementation of Data Source Objects in Internet Explorer or something
else? The reason that I am so sceptical is that I asked the following
question xposted here and c.l.javascript a while back: -

----- Original Message -----
From: "Richard Maher" <[email protected]>
Newsgroups: comp.lang.java.programmer,comp.lang.javascript
Sent: Saturday, March 10, 2007 9:24 AM
Subject: Applet as DSO in Browser example? MSIE only?
Hi,

Recently on the web I came across documentation discussing Data Source
Objects (DSO) in relation to browser and html functionality (in particular
the ability to declare a Java applet as a data source that can be used with
any or the HTML tags that take the src="" attribute). I find it interesting
and potentially *very* useful and would like to know more, so if anyone can
answer any of the following questions that would be great: -

1) Do you have an example of an Applet functioning as an applet to something
like a <Table> that I can see?

2) Is this a MicrosoftIE-only feature? I can't find it in other html tag
reference sites. (I'm using w3schools as a sort of yardstick; is that less
than optimal?) What do other browsers do? Is Microsoft deprecating this
along with other Java stuff?

3) I've searched in c.l.j.p/c.l.javascript and the only references to DSOs
appear to be server based (or data sources other than Applet) I'm guessing
they're entirely different beasts; is that correct?

4) Anyone ever passed a BufferedImage over to Javascript for display on a
web page? (I know it'd be single threaded and all those little .GIFs and
.JPEGs are designed for parallel http webservers, but think of a blob in a
database that has an employee photo of geological survey or something. . .)

Thanks for any help!

Regards Richard Maher

PS. I am already passing result set <options>s back to a <select> list quite
happily; it's the tighter integration between the html tags and my socket
that I'm striving for here.

One of the places I've been looking: -
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/datasources.asp
. . .and the only answer I got was: -
[
The reference to Java applet on
MSDN is a bit mysterious to me. I guess for IE 4/5 Microsoft allowed
to use their JVM for bridging to the needed ActiveX, so people could
use either <object> or <applet> depending on personal preferences. In
either case it is definitely in relation to the Microsoft own JVM
which is not provided any more. It has nothing to do with Sun plugin.
]

It would be great if you could still do this! Do you (or anyone) have an
example?

Hold on, I've just re-read what your post actually says and not what I
wanted it to say "displays it within the applet." :-( I assume that means
as opposed to displaying it within the browser?

Cheers Richard Maher

have
to

The Swing classes has been part of Java since version 1.2.

Your code may actually shrink a little bit in size because
you may replace some of your code with builtin Swing functionality.

Swing apps do tend to use some memory. But would not consider it
a problem on any PC that is not completely outdated.


You can do a IMG tag with SRC pointing to a server side script that
sends the image from the database to the browser with the correct
content type.

Or you can use an applet that retrieves the images via socket
and displays it within the applet.

Arne
 
R

Richard Maher

Hi Lew,

Thanks for the reply.

Lew said:
If you are running a servlet engine you can have a servlet stream the image,
and use that servlet as the img tag's src.

Is the magic in the URL? Can I see the whole <img> tag? Or does the http
request not change and it's the server that let's you specify a DSO other
than a file to satisfy the GET?

Cheers Richard Maher
 
R

Richard Maher

Hi Arne,

Arne Vajhøj said:
I am referring to showing the image within the applet.

Then it is 100% Java and has nothing to do with browser and JavaScript.

Yes. It is possible.

OK, so I stream the image off my socket and form a BufferedImage and then,
having implemented/overriden/the-correct-terminology the paint(graphics g)
method, I can g.drawImage(myBufferedImage) to output it to applet-reserved
pixels in the browser. Am I getting warm? You couldn't throw in a few more
dots to join up couldya?

I am honestly not being lazy, If you knew how much floundering I've had to
do with other stuff (lying on my back, wee flippers flailing madly in the
air) then sheer compassion, nay pity, would compel you to deliver a
full-blown working example :) Anyway, I'm on this full-time now (it's only
money :) but I really want to ramp-up my lightweight, full-throttle
applet-uploader so people won't need to install some whale of a webserver
just to gain access to this stuff.

I personnaly know of no application that needs to show a photo from an
applet in a browser; if someone shows me then all I'm gonna do is let other
people know about it as a "How To". So if anyone has the time/inclination
for this then I'm sure many, including myself would be grateful. Web
reference?

Cheers Richard Maher

PS. I presume the Browser calls paint() and if the image is changed then
repaint() needs to be called? But isn't repaint under the
component.container.window.frame.blah hierachy of classes and Graphics
somewhere else? See how much I need that example :)
 
L

Lew

Richard said:
Is the magic in the URL? Can I see the whole <img> tag? Or does the http
request not change and it's the server that let's you specify a DSO other
than a file to satisfy the GET?

Did you try googling for this information? That's how I learned it.

Your servlet has a URL just like any servlet. The img tag takes a URL. Let's
say you call your web app "foo" and have your image servlet mapped to
"Display", looking for a parameter "name".

<img src="Display?name=myimage.jpg" />

Your Display servlet would have lines its doGet() something like

byte [] image = getImageBytes();
OutputStream os = response.getOutputStream();
os.write( image );
os.flush();

-- Lew

"Google is way bigger then Viacom. They've even got their own verb!"
- The Daily Show, 2007-03-22
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Richard said:
OK, so I stream the image off my socket and form a BufferedImage and then,
having implemented/overriden/the-correct-terminology the paint(graphics g)
method, I can g.drawImage(myBufferedImage) to output it to applet-reserved
pixels in the browser. Am I getting warm? You couldn't throw in a few more
dots to join up couldya?

That is it.

http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html#images
http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#applet

has an example (it reads the image bytes from the jar file instead
of the socket, but I assume you have the bytes).

OK - it is also Swing. Searching for an AWT example finds:

http://www.realapplets.com/tutorial/ImageExample.html
http://www.dgp.toronto.edu/~mjmcguff/learn/java/08-painting/

It must have been done a gazillion times.

Arne
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Richard said:
Would it be fair to say that I could embed an Applet <Object> tag within a
<DIV> or an <IFrame> and then have complete flexibility in positioning,
size, style of whatever the applet paints "within" the browser? I'm guessing
<object> attributes such as height and width can be manipulated with DOM
like any other; is that right? This is beginning to sound pretty sexy!

I am not a JavaScript guy, but I think that it will be possible.
What if two tags call the same applet; does init() get called twice? Two
instances of the applet of just one? two pannels,frames,canvasses and just
one applet?

Good question.

I would assume that it is called once per instance.
What if there are three Applets active in the frameset; How can they invoke
each others methods without having been aware of each other at compile-time?
Given the (at least by default) single-threading of browser-applet
interaction, can I share the one socket connection between the three? Is
there global memory/references?

If I read:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6506118

correctly then it is supposed to run in same JVM and same classloader
(but there is a bug in 1.6).

And if that is the case you can share static fields and singleton
objects.

Have you considered using one instance of the applet with
some panels (maybe tabbed panels) ?

Let's start small - "An example of an Applet painting and Image in a
browser" any takers? websites?

I posted some links in previous post.

The super simple (hello world style) is available at:
http://www.vajhoej.dk/arne/eksperten/applet_image/

Arne
 
S

SSMelaNB

What about making copy/paste functional? My understanding is that it
is more difficult to do in swing.
 
A

Andrew Thompson

What about making copy/paste functional? My understanding is that it
is more difficult to do in swing.

Why would you say that? Some AWT components
implemented Ctrl^c copy and Ctrl^v paste
automatically (dependant on the underlying OS),
but it was inconsistently supported.

Early Swing components did not at first implement
this copy paste functionality (as far as I vaguely
recall), but now they do. As such, it would be
more reliable for modern VM's.

OTOH, copy/paste functionality implemented in
code is equally as easy (or difficult, depending
on how you look at it) in either Swing or AWT.
It is the exact same classes for both.

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top