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

Discussion in 'Java' started by steveh44, May 4, 2011.

  1. steveh44

    steveh44 Guest

    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
    steveh44, May 4, 2011
    #1
    1. Advertising

  2. On 05/04/2011 02:34 PM, steveh44 wrote:
    > 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

    --

    Knute Johnson
    s/knute/nospam/
    Knute Johnson, May 5, 2011
    #2
    1. Advertising

  3. steveh44

    Lew Guest

    steveh44 wrote:
    > 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.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 5, 2011
    #3
  4. In article <h%kwp.57959$>,
    Knute Johnson <> wrote:

    [...]
    > 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>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, May 5, 2011
    #4
  5. steveh44

    markspace Guest

    On 5/5/2011 9:16 AM, John B. Matthews wrote:
    >
    > 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).
    markspace, May 5, 2011
    #5
  6. In article <ipun5u$2v1$>, markspace <-@.> wrote:

    > On 5/5/2011 9:16 AM, John B. Matthews wrote:
    > >
    > > 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).


    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.

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, May 5, 2011
    #6
  7. steveh44

    Lew Guest

    Lew, May 5, 2011
    #7
  8. steveh44

    Tom Anderson Guest

    Re: O/T: Awesome vocabulary (Was: should I use java.awt.* only oralso use javax.swing in applets?)

    On Thu, 5 May 2011, Lew wrote:

    > John B. Matthews wrote:
    >> Related bugs are notoriously protean and difficult to reproduce;

    > ^^^^^^^
    >> diligence is the only defense.

    >
    > Awesome vocabulary!


    See also:

    http://en.wikipedia.org/wiki/Amoeba_proteus

    tom

    --
    Men? Women? Give me a colossal death robot any day!
    Tom Anderson, May 5, 2011
    #8
  9. steveh44

    Jim Janney Guest

    Jim Janney, May 6, 2011
    #9
  10. steveh44

    Roedy Green Guest

    On Wed, 4 May 2011 14:34:58 -0700 (PDT), steveh44
    <> wrote, quoted or indirectly quoted someone who
    said :

    >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.
    Roedy Green, May 6, 2011
    #10
  11. steveh44

    markspace Guest

    On 5/5/2011 2:20 PM, John B. Matthews wrote:

    > 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().



    Yes, and getText() as well. It's a pity, because they just broke a
    bunch of code, and from what I could see it would not have taken much to
    fix getText() so that it was in fact thread safe.

    <http://download.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#getText%28%29>
    markspace, May 6, 2011
    #11
  12. On May 5, 7:34 am, steveh44 <> wrote:
    > ..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.).

    ----------------------------------------------------------

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

    --
    Andrew Thompson
    http://pscode.org/
    Andrew Thompson, May 6, 2011
    #12
  13. On 06/05/2011 12:25, Andrew Thompson allegedly wrote:
    > 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.

    --
    DF.
    An escaped convict once said to me:
    "Alcatraz is the place to be"
    Daniele Futtorovic, May 6, 2011
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jochen Opp

    java.awt or javax.swing

    Jochen Opp, Sep 23, 2003, in forum: Java
    Replies:
    1
    Views:
    577
    Roedy Green
    Sep 23, 2003
  2. mkrause
    Replies:
    0
    Views:
    658
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,749
    lizard
    Jan 30, 2006
  4. S.T
    Replies:
    2
    Views:
    563
  5. african brewer
    Replies:
    2
    Views:
    654
    markspace
    Aug 10, 2009
Loading...

Share This Page