Signed applet strange behaviour

Discussion in 'Java' started by Lukasz, Aug 10, 2006.

  1. Lukasz

    Lukasz Guest

    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?
     
    Lukasz, Aug 10, 2006
    #1
    1. Advertising

  2. Lukasz wrote:
    > 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.
     
    Andrew Thompson, Aug 11, 2006
    #2
    1. Advertising

  3. Lukasz

    Lukasz Guest

    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, Aug 11, 2006
    #3
  4. Lukasz

    Lukasz Guest

    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, Aug 11, 2006
    #4
  5. Lukasz

    Lukasz Guest

    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?
     
    Lukasz, Aug 11, 2006
    #5
  6. Lukasz wrote:
    > 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.
     
    Andrew Thompson, Aug 11, 2006
    #6
  7. Lukasz wrote:
    > 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?


    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.
     
    Andrew Thompson, Aug 11, 2006
    #7
  8. Lukasz wrote:
    > 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.

    --
    Thomas
     
    Thomas Fritsch, Aug 11, 2006
    #8
  9. Lukasz

    Lukasz Guest

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


    Thank You guys for help. Now it is OK.
     
    Lukasz, Aug 11, 2006
    #9
  10. Lukasz wrote:
    > Thomas Fritsch napisal(a):
    > > Lukasz wrote:
    > > > 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.

    ....
    > 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, Aug 11, 2006
    #10
  11. Lukasz wrote:
    > Thomas Fritsch napisal(a):
    > > Lukasz wrote:
    > > > 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.

    ....
    > 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, Aug 11, 2006
    #11
    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. Chris Berg
    Replies:
    2
    Views:
    471
    Chris Berg
    Oct 31, 2005
  2. Trung Chinh Nguyen
    Replies:
    5
    Views:
    461
    Trung Chinh Nguyen
    Jul 30, 2006
  3. kyrpa83
    Replies:
    1
    Views:
    627
    kyrpa83
    Oct 17, 2007
  4. Qu0ll
    Replies:
    28
    Views:
    749
    Qu0ll
    Nov 15, 2007
  5. Rob1bureau
    Replies:
    1
    Views:
    814
    joris
    Feb 27, 2010
Loading...

Share This Page