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 / August 2006

Tip: Looking for answers? Try searching our database.

Signed applet strange behaviour

Thread view: 
Lukasz - 10 Aug 2006 15:27 GMT
I wrote this small test applet (ignore combination of applet and
japplet components):

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.*;
import javax.swing.*;
import javax.swing.border.*;
/*
<APPLET CODE="Test.class" WIDTH="980" HEIGHT="500">
</APPLET>
*/

public class Test extends Applet implements ActionListener {

JFrame ramka;
JButton push, back, frame, cancel;
Choice lista;
TextField pole;
JTextField pole2;

public void init() {

setLayout(null);
push = new JButton("Push");
push.addActionListener(this);
push.setBounds(20, 20, 90, 25);
add(push);

back = new JButton("Back");
back.addActionListener(this);
back.setBounds(20, 20, 90, 25);

frame = new JButton("Ramka");
frame.addActionListener(this);
frame.setBounds(20, 60, 90, 25);

cancel = new JButton("Cancel");
cancel.addActionListener(this);
cancel.setBounds(20, 20, 90, 25);

ramka = new JFrame();
ramka.setSize(400,450);
ramka.setLocation(500,200);
ramka.setDefaultLookAndFeelDecorated(true);
ramka.setLayout(null);

pole = new TextField("pole");
pole.setSize(200, 25);
pole.setLocation(10, 50);

pole2 = new JTextField("pole2");
pole2.setSize(200, 25);
pole.setLocation(10, 100);

lista = new Choice();
lista.setLocation(10,240);
lista.setSize(300,20);
lista.addItemListener(
 new ItemListener() {
    public void itemStateChanged(ItemEvent evt2){
   }
 }
);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == push) {
 removeAll();
 repaint();
 add(back);
 add(frame);
} else if (e.getSource() == back) {
 removeAll();
 repaint();
 add(push);
} else if (e.getSource() == frame) {
 ramka.getContentPane().add(cancel);
 ramka.getContentPane().add(pole);
 ramka.getContentPane().add(pole2);
 ramka.getContentPane().add(lista);
 ramka.setVisible(true);
} else if (e.getSource() == cancel) {
 ramka.setVisible(false);
}
}
}

The problem is that, when this applet is unsigned, and I start it
through this html file:
<HTML>
<HEAD></HEAD>
<BODY>
<CENTER><APPLET ALIGN=Center
CODE="Test.class"
WIDTH="980"
HEIGHT="500"

</APPLET></CENTER>
</BODY>
</HTML>

everything works fine and without any problems.
But when I sign it, and put in the html file line ARCHIVE="Test.jar" ,
the applet won't even initiate.
I can go around that by putting:
lista = new Choice();
lista.setLocation(10,240);
lista.setSize(300,20);
lista.addItemListener(
 new ItemListener() {
    public void itemStateChanged(ItemEvent evt2){
   }
 }
);

into == frame) { part. Then applet starts, but while pressing frame
button, nothing happens, the JFrame does not show up. I noticed this
problem in some other places in my applet, and problem occures with
Choice lists.

In my opinion an effect of signing an applet should be only releasing
it from sand box, I don't know what to do about it now, to make it work
properly.
Any ideas?
Andrew Thompson - 11 Aug 2006 01:50 GMT
> I wrote this small test applet (ignore combination of applet and
> japplet components):

Why?  Note several things:
a) I (and most Usenet users) do not take kindly to being told
what to do.
b) If you had prefixed 'ignore combination' with 'you can..', it
reduces a Command to a Suggesion.
c) Combining Swing and AWT is a recipe for disaster unless
you know when you can ignore the restriction, to the point
that you can *argue the design decision*.
Can you *justify* mixing Swing and AWT?

....
> everything works fine and without any problems.
> But when I sign it, and put in the html file line ARCHIVE="Test.jar" ,

Where is your HTML for the archive applet call?

> the applet won't even initiate.
..
> In my opinion an effect of signing an applet should be only releasing
> it from sand box,

Got it in one (so long as the user agrees, of course).

>..I don't know what to do about it now, to make it work
> properly.
> Any ideas?

I do not have time to reconstruct this series
of codes and HTML into working/breaking applets,
especially not with code signing.

I suggest you give us the *URL* of the two pages
involved in your applet SSCCE
<http://www.physci.org/codes/sscce/>
note particularly this section that mentions applets..
<http://www.physci.org/codes/sscce/#eg>.

If I get a chance, I will have a look over them.

Andrew T.
Lukasz - 11 Aug 2006 09:16 GMT
Here are the URL's:

http://sao.wszia.edu.pl/~s9904/applets/Signed1/test.html - this is not
working signed applet
http://sao.wszia.edu.pl/~s9904/applets/Signed1/testSigned1.rar - source
code, html, class and jar file

http://sao.wszia.edu.pl/~s9904/applets/signed2/test.html - partly
working signed version
http://sao.wszia.edu.pl/~s9904/applets/signed2/testSigned2.rar - source
code, html. class, jar

http://sao.wszia.edu.pl/~s9904/applets/unsigned/test.html - unsigned
version (I don't know why  the JFrame does not shows up when this
applet is on a server, when I run it from my hdd, it works)

http://sao.wszia.edu.pl/~s9904/applets/unsigned/TestNotSigned.rar -
source code, html, etc.
Lukasz - 11 Aug 2006 09:40 GMT
Lukasz napisal(a):
> Here are the URL's:

Even if I make this applet an applet without any JApplet components,
the problem remains. Choice component in the frame is messing all,
without it everything works fine.
Lukasz - 11 Aug 2006 11:10 GMT
Lukasz napisal(a):
> Lukasz napisal(a):
> > Here are the URL's:
> >
> Even if I make this applet an applet without any JApplet components,
> the problem remains. Choice component in the frame is messing all,
> without it everything works fine.

I found that my ItemListener is causing all the problems. After
removing it applet works as it should, but then I have no action when
an element of the Choice is choosen. How can I add this listener to
make everything work?
Andrew Thompson - 11 Aug 2006 11:23 GMT
> Lukasz napisal(a):
> > Lukasz napisal(a):
[quoted text clipped - 8 lines]
> an element of the Choice is choosen. How can I add this listener to
> make everything work?

Your item listener becomes an 'inner class' with the
name 'Test$1.class'.  The Test$1.class (as well as
any other inner inner classes) need to be included
in the Jar file.

Andrew T.
Thomas Fritsch - 11 Aug 2006 11:45 GMT
> I found that my ItemListener is causing all the problems. After
> removing it applet works as it should, but then I have no action when
> an element of the Choice is choosen. How can I add this listener to
> make everything work?

You are referring to this lines in your Test.java:
 lista.addItemListener(
  new ItemListener() {
    public void itemStateChanged(ItemEvent evt2){
    }
  }
 );       
By using 'new ItemListener() {...}' you tell the compiler to create an
anonymous inner class, contained in file Test$1.class. Because you
missed to include this Test$1.class file in your Test.jar (as Andrew has
already pointed to you), it failed. So fix that first.

Signature

Thomas

Lukasz - 11 Aug 2006 12:27 GMT
Thomas Fritsch napisal(a):
> > I found that my ItemListener is causing all the problems. After
> > removing it applet works as it should, but then I have no action when
[quoted text clipped - 12 lines]
> missed to include this Test$1.class file in your Test.jar (as Andrew has
> already pointed to you), it failed. So fix that first.

Thank You guys for help. Now it is OK.
Andrew Thompson - 11 Aug 2006 12:45 GMT
> Thomas Fritsch napisal(a):
> > > I found that my ItemListener is causing all the problems. After
[quoted text clipped - 13 lines]
> > missed to include this Test$1.class file in your Test.jar (as Andrew has
> > already pointed to you), it failed. So fix that first.
...
> Thank You guys for help. Now it is OK.

Glad you got it working.  :-)

..and also glad Thomas happened by.   It was an
*anonymous* inner class.  I had the vague feeling
I was forgetting something, when I described it..   ;-)

Andrew T.
Andrew Thompson - 11 Aug 2006 12:47 GMT
> Thomas Fritsch napisal(a):
> > > I found that my ItemListener is causing all the problems. After
[quoted text clipped - 13 lines]
> > missed to include this Test$1.class file in your Test.jar (as Andrew has
> > already pointed to you), it failed. So fix that first.
...
> Thank You guys for help. Now it is OK.

Glad you got it working.  :-)

..and also glad Thomas happened by.   It was an
*anonymous* inner class.  I had the vague feeling
I was forgetting something, when I described it..   ;-)

Andrew T.
Andrew Thompson - 11 Aug 2006 11:20 GMT
> Here are the URL's:
>
> http://sao.wszia.edu.pl/~s9904/applets/Signed1/test.html - this is not
> working signed applet

Did you check the Java console?  I am getting...

java.lang.NoClassDefFoundError: Test$1
    at Test.init(Test.java:58)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

..on that applet.

The missing class seems a problem that must be fixed.

(Note that I 'refused' to accept the signed code, but
unless you are doing some very clever classloading
that depends on trusted code, the Test$1.class needs
to be inside the Test.jar - it sure is not there)

BTW - that was mostly an excellent example of the problem,
but I was unable to open the RAR files.  It would be better to
just Zip or Jar them..

HTH

Andrew T.


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.