This discussion is archived
3 Replies Latest reply: Aug 12, 2010 9:33 PM by DarrylBurke RSS

My  Applet Jar file doesn't work !!

843804 Newbie
Currently Being Moderated
.

hello ,

I have written this java applet :


import java.awt.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

public class test4 extends Applet implements ActionListener{

     private static final long serialVersionUID = 1L;
     private JButton B1 =new JButton("Forward ");
     private JButton B2 =new JButton("Backward");
     private JButton B3 =new JButton("Left");
     private JButton B4 =new JButton("Right");
private JPanel P1 = new JPanel();
private JPanel P2 = new JPanel();
private JPanel P3 = new JPanel();
private JPanel P4 = new JPanel();
private JPanel P5 = new JPanel();
private JPanel P6 = new JPanel();
private JLabel L3 = new JLabel(" ");
private JLabel L4 = new JLabel(" ");
private JLabel L5 = new JLabel(" ");
private JLabel L6 = new JLabel(" ");
private JLabel L7 = new JLabel(" ");
JSplitPane sppSplitPane0 = new JSplitPane( );

     
     public test4()
     {
          
          JFrame.setDefaultLookAndFeelDecorated(true);
          sppSplitPane0.setDividerLocation( 250 );
          
          
          
          P3.add(L4);
          P3.add(B1);
          P3.add(L5);
          
          P5.add(B3);
          P5.add(L3);
          P5.add(B4);
          
          P4.add(L6);
          P4.add(B2);
P4.add(L7);


          
          P1.setLayout(new BorderLayout());
          P1.add("North",P3);
          P1.add("Center",P5);
          P1.add("South",P4);
          P2.setLayout(new BorderLayout());
          P2.add("North" , P1);
          
          B1.addActionListener(this);
          B2.addActionListener(this);
          B3.addActionListener(this);
          B4.addActionListener(this);
          
          sppSplitPane0.setLeftComponent(P2);
          sppSplitPane0.setRightComponent(P6);
          

     }
     
     
     public void actionPerformed(ActionEvent e) {
          try {
               if (e.getSource() == B4) {
          URL myNewURL = new URL("http://amera/cgi-bin/test.cgi?R");
          System.out.println("URL = " + myNewURL);


          getAppletContext().showDocument(myNewURL,"blank");
          }
               else
                    if (e.getSource() == B3) {
                    URL myNewURL = new URL("http://amera/cgi-bin/test.cgi?L");
                    System.out.println("URL = " + myNewURL);

                    getAppletContext().showDocument(myNewURL,"blank");
               }
                    else
                         if (e.getSource() == B2) {
                         URL myNewURL = new URL("http://amera/cgi-bin/test.cgi?B");
                         System.out.println("URL = " + myNewURL);

                         
                         getAppletContext().showDocument(myNewURL,"blank");
                    }
                         else {
                              URL myNewURL = new URL("http://amera/cgi-bin/test.cgi?F");
                              System.out.println("URL = " + myNewURL);

                         
                         getAppletContext().showDocument(myNewURL,"blank");
          }
          
          

          } catch (Exception err) {
          System.err.println("Error!\n" + err);
          showStatus("Error, look in Java Console for details!");
          }

     }


     public static void main(String[] args) {
     
          test t=new test();
          JFrame frame =new JFrame();
          frame.add(t.sppSplitPane0);
          frame.setSize(1100,700);
          frame.setVisible(true);
     }

}

i made a jar file :

i created a file and named it MANIFEST.MF .i wrote inside it :
Main-Class: test

Then i placed it in a folder with the test.class .I created jar file using command line.
I entered the test.class path and then wrote this command :
jar cvfm myjar.jar MANIFEST.MF *.class

Then the jar file "myjar.jar" is created .
it's executed but this function "public void actionPerformed(ActionEvent e) " won't wrok.
i keep pressing the buttons but nothing is happening !!

please help me .


.

Edited by: Amera on Dec 27, 2009 2:51 PM
  • 1. Re: My  Applet Jar file doesn't work !!
    793415 Pro
    Currently Being Moderated
    Welcome to the Sun forums.

    Subject: My Applet Jar file doesn't work !! .

    1) Note that one '!' denotes exclamation, whereas 2 or more often denotes a dweeb.
    2) Since you are on your first post, I will point out that applets are an advanced topic, and should not be attempted by newbies.
    3) "doesn't work" is very vague. It is likely to produce a reply like "maybe the applet is lazy - try flogging it".
    Amera wrote:
    ..I have written this java applet :
    When posting code, code snippets, HTML/XML or input/output, please use the code tags. The code tags help retain the formatting and indentation of the sample. To use the code tags, select the sample and click the CODE button.

    Also note that the most preferred form of code is an SSCCE *(<- link).* In an SSCCE, your would remove all but one button (if the actionPerformed fails with 6 or 7 buttons, trim it down to fail with just one or two.
    i made a jar file :
    So does the applet work before you make the Jar file? Your post so far suggests the Jar file is the problem.
    i created a file and named it MANIFEST.MF .i wrote inside it :
    Main-Class: test

    Then i placed it in a folder with the test.class .I created jar file using command line.
    I entered the test.class path and then wrote this command :
    jar cvfm myjar.jar MANIFEST.MF *.class

    Then the jar file "myjar.jar" is created .
    it's executed but this function "public void actionPerformed(ActionEvent e) " won't wrok.
    i keep pressing the buttons but nothing is happening !!
    So you get 'no output in the console & no effect in the applet'?

    What is the URL where I can see your applet failing?

    As an aside, since Sun does not guarantee that applet clients will act on the showDocument command, even if it does not work, it would not be a 'bug'.

    Edited by: AndrewThompson64 on Dec 28, 2009 11:18 AM
  • 2. Re: My  Applet Jar file doesn't work !!
    843804 Newbie
    Currently Being Moderated
    doesnt work at all or doesnt work in browser window i also cant get my jar to launch in a website but it works fine standalone. looks like you may want to avoid coding absolute paths in url's your localhost name probly wont be found on the real internet so you should look into that as source of whil its failing.
  • 3. Re: My  Applet Jar file doesn't work !!
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Missinglenk, please don't post in threads that are long dead and don't hijack another poster's thread. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

    I'm locking this thread now.

    db