Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
jmDesktop - 12 May 2008 14:43 GMT
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.
Knute Johnson - 12 May 2008 16:45 GMT
> 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);
    }
}

Signature

Knute Johnson
email s/nospam/linux/

Andrew Thompson - 16 May 2008 02:06 GMT
On May 13, 1:45 am, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
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
jmDesktop - 16 May 2008 03:25 GMT
> On May 13, 1:45 am, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 23 lines]
> 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.
Arne Vajhøj - 16 May 2008 03:37 GMT
>> On May 13, 1:45 am, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
>> wrote:
[quoted text clipped - 21 lines]
> 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
Roedy Green - 12 May 2008 18:47 GMT
On Mon, 12 May 2008 06:43:23 -0700 (PDT), jmDesktop
<needin4mation@gmail.com> 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.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Arne Vajhøj - 12 May 2008 23:56 GMT
> 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
Roedy Green - 13 May 2008 11:19 GMT
>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.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.