When writing applet do you start out as an application or applet?

Discussion in 'Java' started by jmDesktop, May 12, 2008.

  1. jmDesktop

    jmDesktop Guest

    If you are creating an application that is going to be run in an
    applet, do you start out creating a regular application an moving it
    to an applet or just creating it as an applet, beginning to end. Size
    of project is moderat to large. Thanks.
     
    jmDesktop, May 12, 2008
    #1
    1. Advertising

  2. jmDesktop wrote:
    > If you are creating an application that is going to be run in an
    > applet, do you start out creating a regular application an moving it
    > to an applet or just creating it as an applet, beginning to end. Size
    > of project is moderat to large. Thanks.


    It depends on a lot of things. If my program is only going to be an
    Applet, I create it as an Applet. Often if my program can be contained
    in a Panel or drawn on a Canvas, I extend that component and can either
    add it to an Applet or an application. See the simple example below of
    test.java which extends Canvas and draws a blue oval in a yellow
    background. The test1.java is an Applet and will display the test
    class. test2.java is an application and will also display the test class.

    import java.awt.*;

    public class test extends Canvas {
    public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();
    g.setColor(Color.YELLOW);
    g.fillRect(0,0,w,h);
    g.setColor(Color.BLUE);
    g.fillOval(w/4,h/4,w/2,h/2);
    }
    }


    import java.awt.*;
    import java.applet.*;

    public class test1 extends Applet {
    public void init() {
    test t = new test();
    t.setPreferredSize(new Dimension(400,300));
    add(t);
    }
    }

    <html>
    <head>
    </head>
    <body>
    <applet code="test1.class" width="640" height="480">
    </applet>
    </body>
    </html>

    import java.awt.*;
    import java.awt.event.*;

    public class test2 {
    public static void main(String[] args) {
    final Frame f = new Frame("test2");
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    f.dispose();
    }
    });

    test t = new test();
    t.setPreferredSize(new Dimension(400,300));

    f.add(t,BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
    }
    }

    Sometimes you can make a hybrid that is both an Applet and an
    application. The following code can be run as an Applet or as an
    application. The Applet is a handy component, it extends Container and
    Panel and can be used for anything that those components can be used for.

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    public class test3 extends Applet {
    public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();
    g.setColor(Color.BLUE);
    g.fillRect(0,0,w,h);
    g.setColor(Color.YELLOW);
    g.fillOval(w/4,h/4,w/2,h/2);
    }

    public static void main(String[] args) {
    final Frame f = new Frame("test3");
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    f.dispose();
    }
    });

    test3 t3 = new test3();
    t3.setPreferredSize(new Dimension(400,300));
    f.add(t3,BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
    }
    }


    --

    Knute Johnson
    email s/nospam/linux/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
     
    Knute Johnson, May 12, 2008
    #2
    1. Advertising

  3. jmDesktop

    Roedy Green Guest

    On Mon, 12 May 2008 06:43:23 -0700 (PDT), jmDesktop
    <> wrote, quoted or indirectly quoted someone
    who said :

    >If you are creating an application that is going to be run in an
    >applet, do you start out creating a regular application an moving it
    >to an applet or just creating it as an applet, beginning to end. Size
    >of project is moderat to large. Thanks.


    start as an Applet. See http://mindprod.com/jgloss/applet.html
    for how to turn it into a hybrid.

    Most of my Applets are hybrids. See http://mindprod.com/products.html
    and all come with source.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, May 12, 2008
    #3
  4. jmDesktop

    Arne Vajhøj Guest

    jmDesktop wrote:
    > If you are creating an application that is going to be run in an
    > applet, do you start out creating a regular application an moving it
    > to an applet or just creating it as an applet, beginning to end. Size
    > of project is moderat to large.


    For size > small I would find it very tempting to develop and
    test classes in app context and then move it into applet context
    later.

    Arne
     
    Arne Vajhøj, May 12, 2008
    #4
  5. jmDesktop

    Roedy Green Guest

    On Mon, 12 May 2008 18:56:34 -0400, Arne Vajhøj <>
    wrote, quoted or indirectly quoted someone who said :

    >For size > small I would find it very tempting to develop and
    >test classes in app context and then move it into applet context
    >later.


    It is easier to debug an application than an Applet. I debug my
    hybrids as applications. However, the structure is Applet plus a main
    method to let them also behave as applications.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, May 13, 2008
    #5
  6. On May 13, 1:45 am, Knute Johnson <>
    wrote:
    > jmDesktop wrote:
    > > If you are creating an application that is going to be run in an
    > >applet, do you start out creating a regular application an moving it
    > > to anappletor just creating it as an applet, beginning to end.  Size
    > > of project is moderat to large.  Thanks.

    >
    > It depends on a lot of things.  


    I only had time to glance at what Knute said,
    but I think I basically agree with his take
    on it.

    For trivial things - direct to applet, for
    anything beyond that, hybrid.

    This project sounds like it should be an hybrid.

    Is there a particular reason the app. is not
    being launched using webstart? The maintenance
    costs of a JWS app. will be lower in the long
    run.

    --
    Andrew T.
    PhySci.org
     
    Andrew Thompson, May 16, 2008
    #6
  7. jmDesktop

    jmDesktop Guest

    On May 15, 9:06 pm, Andrew Thompson <> wrote:
    > On May 13, 1:45 am, Knute Johnson <>
    > wrote:
    >
    > > jmDesktop wrote:
    > > > If you are creating an application that is going to be run in an
    > > >applet, do you start out creating a regular application an moving it
    > > > to anappletor just creating it as an applet, beginning to end.  Size
    > > > of project is moderat to large.  Thanks.

    >
    > > It depends on a lot of things.  

    >
    > I only had time to glance at what Knute said,
    > but I think I basically agree with his take
    > on it.
    >
    > For trivial things - direct to applet, for
    > anything beyond that, hybrid.
    >
    > This project sounds like it should be an hybrid.
    >
    > Is there a particular reason the app. is not
    > being launched using webstart?  The maintenance
    > costs of a JWS app. will be lower in the long
    > run.
    >
    > --
    > Andrew T.
    > PhySci.org


    Well, I hadn't even heard of webstart until now. My main problem is,
    after I figure this part out, is how do I connect my applet (or
    webstart?) to the server. it's an internet app, but I need more than
    just a servlet, jsp. It's for a game. Thanks.
     
    jmDesktop, May 16, 2008
    #7
  8. jmDesktop

    Arne Vajhøj Guest

    jmDesktop wrote:
    > On May 15, 9:06 pm, Andrew Thompson <> wrote:
    >> On May 13, 1:45 am, Knute Johnson <>
    >> wrote:
    >>> jmDesktop wrote:
    >>>> If you are creating an application that is going to be run in an
    >>>> applet, do you start out creating a regular application an moving it
    >>>> to anappletor just creating it as an applet, beginning to end. Size
    >>>> of project is moderat to large. Thanks.
    >>> It depends on a lot of things.

    >> I only had time to glance at what Knute said,
    >> but I think I basically agree with his take
    >> on it.
    >>
    >> For trivial things - direct to applet, for
    >> anything beyond that, hybrid.
    >>
    >> This project sounds like it should be an hybrid.
    >>
    >> Is there a particular reason the app. is not
    >> being launched using webstart? The maintenance
    >> costs of a JWS app. will be lower in the long
    >> run.

    >
    > Well, I hadn't even heard of webstart until now. My main problem is,
    > after I figure this part out, is how do I connect my applet (or
    > webstart?) to the server. it's an internet app, but I need more than
    > just a servlet, jsp. It's for a game. Thanks.


    Your applet will be allowed to connect to the same server it was
    fetched from.

    HTTP or plain socket as you want.

    Arne
     
    Arne Vajhøj, May 16, 2008
    #8
    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. Doris Cox
    Replies:
    0
    Views:
    562
    Doris Cox
    Dec 2, 2003
  2. Dennis
    Replies:
    0
    Views:
    706
    Dennis
    Dec 2, 2003
  3. Miguel Dias Moura
    Replies:
    1
    Views:
    422
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 1, 2004
  4. M
    Replies:
    3
    Views:
    417
    Roedy Green
    Jun 2, 2004
  5. albert kao
    Replies:
    3
    Views:
    2,094
    Arne Vajhøj
    Feb 2, 2011
Loading...

Share This Page