For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2006 > easy question about applet









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author easy question about applet
giulia.sim@tiscali.it

2006-07-24, 4:00 am

Hi all
I wrote yesterday my first applet

MyApplet extends javax.swing.JApplet
..=2E.
etc

It contains a JTextArea and a JButton. When the user clicks the button,
the sentence 'hello word!' appears in the text area... I and _inside_
NetBeans it works!

well, netbeans makes a file 'MyApplet.html' in the BUILD directory.
but if I try to launch the file using a browser [i.e. without netbeans
], the following error appears:


java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown
Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


Documentation said:
//cite
if some problem appears, e.g. you get error starting like this:
java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
then make sure the Swing Extension Library is on the main project's
classpath (go to the project properties) and rebuild the project.

// end cite

the Swing Extension Library is present.... what is the problem??


If I use another kind of applet [1] it works _outside_ netbeans..

Thanks for any hint!

(and sorry for my bad English)

[please save my life!!!]



[1] IT WORKS


<applet code=3D"applet002.MyApplet.class" width=3D"400" height=3D"300" >
TEST</applet>

MyApplet extends java.applet.Applet {

/** Initialization method that will be called after the applet is
loaded
* into the browser.
*/
public void init() {
// TODO start asynchronous download of heavy resources
}

public void paint(Graphics g){
Graphics2D g2=3D (Graphics2D)g;
g2.drawString("HELLO",20,20);


---------------------
[2]

ribadisco che l'applet funziona dall'interno di netbeans, e una applet
pi=F9 semplice
..=2E MyApplet extends java.applet.Applet { ...
funziona anche da browser.

..=2E..ma non funziona...

[2] l'orrenda presenza

Andrew Thompson

2006-07-24, 4:00 am

giulia.sim@tiscali.it wrote:
> Hi all
> I wrote yesterday my first applet


How many command line and frame
based applications have you written?

Applets are not good for beginners, because they
are a lot harder to debug and deploy than CLI
or frame based applciations.

> MyApplet extends javax.swing.JApplet


Swing requires Java 1.2+.

While this *might* not be relevant, it sometimes is
(especially with applets).

> ...
> etc
>
> It contains a JTextArea and a JButton. When the user clicks the button,
> the sentence 'hello word!' appears in the text area... I and _inside_
> NetBeans it works!


Beginners are better off using a simpler editor like
TextPad. A powerful IDE hides a lot of the details
that you need to understand in order to do anything
outside of the IDE.

> well, netbeans makes a file 'MyApplet.html' in the BUILD directory.
> but if I try to launch the file using a browser


Like as in Internet Explorer for Windows, for instance?

Are are you perhaps referring to any of the fine HTML
user agents such as ..the Mozilla family, Opera, Safari,
Lynx..?

It is usually best to be specific about the browser
make and version as well as the java version installed
in the browser (which may not be the same one as
netbeans uses).

>...[i.e. without netbeans
> ], the following error appears:
>
>
> java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group


> Documentation said:


What documentation? Netbeans?

Use the Java core Java documentation (the JavaDocs)
along with the Java tutorial and you will be better off.*

> //cite
> if some problem appears, e.g. you get error starting like this:
> java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
> then make sure the Swing Extension Library is on the main project's
> classpath


The 'main project' in this case as the applet,
whose classpath is set in the applet element.

> the Swing Extension Library is present.... what is the problem??

.....
> <applet code="applet002.MyApplet.class" width="400" height="300" >
> TEST</applet>


No it is not.

To add the Swing Extension Library to the class path
of this applet, and assuming the class was in a jar
called 'xtn.jar' in the same directory as the applet, you
might write..

<applet
code="applet002.MyApplet.class"
archive="xtn.jar"
width="400" height="300" >
TEST
</applet>

* For applets, you might start here..
<http://java.sun.com/docs/books/tuto...loyment/applet/>
a bit of digging through that and an external link with
a couple more clicks leads to..
<http://www.w3.org/TR/1999/REC-html4...tml#edef-APPLET>
...and the W3 description of the applet element (that
is deprecated in HTML 4.01).

Take my advice and leave the applets aside for the moment,
and those custom layouts as well. The Sun layout tutorial
will leave you well placed to lay out your GUI without using
layouts from extension libraries.

HTH

Andrew T.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com