should I use java.awt.* only or also use javax.swing in applets?

S

steveh44

folks,

newbie here.

I am learning applets. should one stick to java.awt.* and only extend
Applet or go for Japplet instead and pull in swing?

When I looked at some applets, most seem to be based on Applet, not
JApplet.

Basically I am asking, if I want to make sure my applet run best and
on most browser, should I just stick to awt and not include any swing
stuff? I know if I extend JApplet I can still use awt classes and
methods if I want to.

cheers
steve
 
K

Knute Johnson

folks,

newbie here.

I am learning applets. should one stick to java.awt.* and only extend
Applet or go for Japplet instead and pull in swing?

When I looked at some applets, most seem to be based on Applet, not
JApplet.

Basically I am asking, if I want to make sure my applet run best and
on most browser, should I just stick to awt and not include any swing
stuff? I know if I extend JApplet I can still use awt classes and
methods if I want to.

cheers
steve

Don't hesitate to use JApplet and Swing components. If a computer will
run an AWT Applet it will run a JApplet. Remember though that just like
a Swing application, a JApplet must construct the GUI on the Event
Dispatch Thread. There is a discussion of that on Sun's tutorial website.

You can see a JApplet game here;

http://rabbitbrush.frazmtn.com/asteroids.html
 
L

Lew

steveh44 said:
folks,

newbie here.

I am learning applets. should one stick to java.awt.* and only extend
Applet or go for Japplet instead and pull in swing?

When I looked at some applets, most seem to be based on Applet, not
JApplet.

Basically I am asking, if I want to make sure my applet run best and
on most browser, should I just stick to awt and not include any swing
stuff? I know if I extend JApplet I can still use awt classes and
methods if I want to.

Speaking only from my own personal preference, I find the Swing world more
hospitable. I don't know that it makes a real difference from a deployment
perspective either way, but Swing components are rather more internal to the
Java campus. AWT components more explicitly involve platform resources.

I realize that I'm hideously over-generalizing, but I intend to convey the
summary and taste of my bias rather than to describe the details.

In any event (haha), the Swing programming model is fairly clean and opens up
nicely to a lot of the libraries that handle graphics, printing, transforms,
whatever.

The real benefit is its event-driven mechanism and the model-view-controller
(MVC) perspective.

Naturally there are java.awt... libraries involved in Swing programming.
We're really only comparing the component model parts here.
 
J

John B. Matthews

[...]
Don't hesitate to use JApplet and Swing components. If a computer
will run an AWT Applet it will run a JApplet. Remember though that
just like a Swing application, a JApplet must construct the GUI on
the Event Dispatch Thread. There is a discussion of that on Sun's
tutorial website.

You can see a JApplet game here;

http://rabbitbrush.frazmtn.com/asteroids.html

Somehow I'd previously overlooked the need to construct the GUI on the
EDT for JApplets. Thanks for the reminder!

<http://download.oracle.com/javase/tutorial/deployment/applet/getStarted.html>

I've updated this old chestnut, accordingly:

<https://sites.google.com/site/drjohnbmatthews/subway>
 
M

markspace

Somehow I'd previously overlooked the need to construct the GUI on the
EDT for JApplets. Thanks for the reminder!


Don't forget this applies to all calls to your JApplet that you didn't
initiate yourself. For example, init(), start(), stop() and destroy():
you definitely should access any UI component they interact with on
the EDT. This includes destroying UI components and shutting down, not
just creating the GUI.

Also, don't forget thatany other JComponent method could be called by
JavaScript, or in fact JavaScript could call any public method at all
that your applet declares. If you're being really defensive, you might
want to override all public methods that access the GUI or are not
thread safe, and verify you are in fact being called on the EDT (or do
whatever else is needed to assure/detect thread safety).
 
J

John B. Matthews

Don't forget this applies to all calls to your JApplet that you
didn't initiate yourself. For example, init(), start(), stop() and
destroy(): you definitely should access any UI component they
interact with on the EDT. This includes destroying UI components and
shutting down, not just creating the GUI.

Also, don't forget thatany other JComponent method could be called by
JavaScript, or in fact JavaScript could call any public method at all
that your applet declares. If you're being really defensive, you
might want to override all public methods that access the GUI or are
not thread safe, and verify you are in fact being called on the EDT
(or do whatever else is needed to assure/detect thread safety).

I'll have to throw in an "amen" and note that the forthcoming version 7
appears to have quietly deprecated the thread-safety of several methods,
including JTextArea's append().

<http://download.oracle.com/javase/6/docs/api/javax/swing/JTextArea>

Related bugs are notoriously protean and difficult to reproduce;
diligence is the only defense.
 
R

Roedy Green

I am learning applets. should one stick to java.awt.* and only extend
Applet or go for Japplet instead and pull in swing?

When I looked at some applets, most seem to be based on Applet, not
JApplet.

It is pretty easy once you learn AWT to flip to Swing. Basically
Swing just gives you more things to tweak, but it ads some subtle
complications like doing all your GUI work on a single thread, and the
insanity of contentPanes.

When Java first came out, Applet were the rage. Microsoft made war on
them, and hence you see them much less now, though you can use Swing
just as well in Applets/JApplets. That is why you see Swing less, you
just see fewer new Applets all round. Sun has countered with Java
Webstart which I think is a great idea. It is fairly simply to
implement. It handles keeping customers up to date. MS can't bugger
with it easily.

see http://mindprod.com/jgloss/awt.html
http://mindprod.com/jgloss/swing.html
http://mindprod.com/jgloss/javawebstart.html

Applets are fun. They are like being a kid. You can put your art work
on the refrigerator of the Internet. But they are more difficult than
plain apps. I write hybrids. I debug as an app and then when all is
working run as an Applet.
http://mindprod.com/jgloss/applet.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
Politicians complain that Kindles and iBooks are killing jobs by
destroying the paper book industry. I see it that they have create a way
to produce books for less than a third the cost without destroying forests
and emitting greenhouse gases in the process. They have created wealth.
They are encouraging literacy and cutting the costs of education.
 
M

markspace

A

Andrew Thompson

..When I looked at some applets, most seem to be based on Applet, not
JApplet.

Most applet examples were written in the 1990s when the MSVM
plagued browsers. We have come up with an MSVMicide in the mean
time.
Basically I am asking, if I want to make sure my applet run best and
on most browser, should I just stick to awt and not include any swing
stuff?

No. Applets (by which I mean both java.awt.Applet &
javax.swing.JApplet)
will always experience little quirks when appearing in this or that
micro-version of 'name your favorite UA here'.

If you program the code as a JApplet, you are likely to get lots of
help when something goes wrong. If you ask about an Applet, people
will either ignore the post (mostly because they've forgotten how AWT
components work) or advise you to update to a JApplet.
..I know if I extend JApplet I can still use awt classes and
methods if I want to.

Be very wary of mixing Swing & AWT. Java 7 promises to provide
effortless mixing of Swing & AWT. Otherwise expect problems with
any floating Swing GUI element that overlaps an AWT component (e.g.
menus, combo boxes, tool tips etc.).
 
D

Daniele Futtorovic

BTW - G'day to all the regulars! It seems like an eon since I last
delved into usenet.

Hi Andrew! Nice to see you around. Still hanging off in the SUN forum?
How's it going there since big oh took over?

PS: your sig separator lacks a trailing space.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top