Signed applet strange behaviour

L

Lukasz

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?
 
A

Andrew Thompson

Lukasz said:
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.
 
L

Lukasz

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.
 
L

Lukasz

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.
 
L

Lukasz

Lukasz napisal(a):
Lukasz napisal(a):
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?
 
A

Andrew Thompson

Lukasz said:
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.
 
A

Andrew Thompson

Lukasz said:
Lukasz 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
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.
 
T

Thomas Fritsch

Lukasz said:
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.
 
L

Lukasz

Thomas Fritsch napisal(a):
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.

Thank You guys for help. Now it is OK.
 
A

Andrew Thompson

Lukasz said:
Thomas Fritsch napisal(a): ....
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.
 
A

Andrew Thompson

Lukasz said:
Thomas Fritsch napisal(a): ....
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top