?
Solved

How do I turn my existing Java code into an applet?

Posted on 2003-03-15
54
Medium Priority
?
271 Views
Last Modified: 2013-11-23
I have a number of Java classes that run a GUI from one main class.  How do i go about turning my application into an applet???

what classes do I need to change and how should I go about changing them?  any advice would be great?
0
Comment
Question by:need_help_pls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 26
  • 25
  • +1
54 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 8142874
You just need to make sure that your previous code doesn't violate applet security restrictions mainly. see http://java.sun.com/sfaq/

If you are not opening any files, sockets or that kind of thing, you should be OK.
0
 

Author Comment

by:need_help_pls
ID: 8142898
my application does open files...  will that cause major problems??? just read access to the files though...??
0
 

Author Comment

by:need_help_pls
ID: 8142910
how can I go about running the application as an applet though??  if all was well?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 8142922
You'll have to recode the way it does that. They will have to be in the applet's codebase too, i.e. you can't wander outside that applet's own location in the directory tree.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8142930
(that is without signing or modification to the security policy)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8142935
>>how can I go about running the application as an applet though??  

In a browser or appletviewer
0
 

Author Comment

by:need_help_pls
ID: 8143042
>>how can I go about running the application as an applet though??  

In a browser or appletviewer


---- but is there some modification that I need to make to my existing code for this to be feasible?? when I view some exsiting applet code that i have seen, they all seem to run this init() method - what is this about?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8143070
Yes, broadly speaking, you can see init() as being equivalent to your application's constructor and main() to the applet's start() method.
0
 

Author Comment

by:need_help_pls
ID: 8167440
ok im not having much success with this... i have created my applet and running it from a basic html page but this is what i get:
my gui appears but opens as a separate application, i.e. as if i had run it independently... it is not part of the html page?!? - i assumed it would be

also, my application no longer works... for example i have a textfield that when input is entered and the user hits return, the text is supposed to be processed by the application and changes made to them gui but nothing happens and i do not get any errors either?!?!??!  HELP
0
 

Author Comment

by:need_help_pls
ID: 8167525
i have probably gone wrong, but i basically just wrote my main method again within the init()
eg:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/** A class that allows testing of interpreter, its GUI and the GUIs controller
 * (listener).
 * @author
 */

public class InterpreterMain extends JApplet
{
     public void init(){
          Interpreter interpreter = new Interpreter();
          InterpreterController controller = new InterpreterController();
          InterpreterGUI gui = new InterpreterGUI(controller);
          controller.setInterpreter(interpreter);
          controller.setGUI(gui);


        /* GUIs are simply subclasses of JPanel, so we add the GUI
           to a JFrame and make the JFrame visible.
        */

          JFrame frm = new JFrame("JIN - Java Interpreter for Novice Programmers");
          Container contentPane = frm.getContentPane();
          contentPane.add(gui);

          JMenuBar menuBar = new JMenuBar();
          JMenu fileMenu = gui.makeMenu();
          menuBar.add(fileMenu);
          frm.setJMenuBar(menuBar);

          frm.addWindowListener(new WindowAdapter()
               {  public void windowClosing(WindowEvent we)
                  {  System.exit(0);
                  }
               });

          frm.pack();
          frm.setSize(700, 550);
          //frm.setSize(900, 600);
          frm.setVisible(true);

     }
     public static void main(String[] args)
     {
          /* Create interpreter, interpreter GUI and controller
          */

          Interpreter interpreter = new Interpreter();
          InterpreterController controller = new InterpreterController();
          InterpreterGUI gui = new InterpreterGUI(controller);
          controller.setInterpreter(interpreter);
          controller.setGUI(gui);


        /* GUIs are simply subclasses of JPanel, so we add the GUI
           to a JFrame and make the JFrame visible.
        */

          JFrame frm = new JFrame("JIN - Java Interpreter for Novice Programmers");
          Container contentPane = frm.getContentPane();
          contentPane.add(gui);

          JMenuBar menuBar = new JMenuBar();
          JMenu fileMenu = gui.makeMenu();
          menuBar.add(fileMenu);
          frm.setJMenuBar(menuBar);

          frm.addWindowListener(new WindowAdapter()
               {  public void windowClosing(WindowEvent we)
                  {  System.exit(0);
                  }
               });

          frm.pack();
          frm.setSize(700, 550);
          //frm.setSize(900, 600);
          frm.setVisible(true);

     }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8173294
>>opens as a separate application, i.e. as if i had run it independently... it is not part of the html page?!? - i assumed it would be


No. You use a frame, so it'll look like an application.

As far as the operation of the GUI is concerned, i can't comment on the problems there as the processing code doesn't appear in your post.
0
 

Author Comment

by:need_help_pls
ID: 8174663
so to make the application just appear on the webpage i should not create a JFrame just add the components to the applet??  should this be done in init() or my main method of InterpreterMain??

The operation of the GUI works perfectly when run as a standard Java application that is why I didnt post the code... when I run it in a browser it doesnt work at all - when i run it in an applet viewwer it works perfectly also... its just that i need it to be able to be displayed in a browser window, i assume the problem stems from the fact that i open files for reading in my application and have not made any allowances for this when using the browser but i am not sure what allowances i need to make?
0
 

Author Comment

by:need_help_pls
ID: 8174749
so to make the application just appear on the webpage i should not create a JFrame just add the components to the applet??  should this be done in init() or my main method of InterpreterMain??

The operation of the GUI works perfectly when run as a standard Java application that is why I didnt post the code... when I run it in a browser it doesnt work at all - when i run it in an applet viewwer it works perfectly also... its just that i need it to be able to be displayed in a browser window, i assume the problem stems from the fact that i open files for reading in my application and have not made any allowances for this when using the browser but i am not sure what allowances i need to make?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8180841
>>just add the components to the applet??  should this be done in init()

Yes and yes. AFAIK JApplet uses a BorderLayout by default so just treat your applet like the JFrame

>>
i assume the problem stems from the fact that i open files for reading in my application and have not made any allowances for this when using the browser
>>

Exactly what i would have guessed. The workaround here is
a. Instead of File, create a URL to the resoruce you want to read and get an input stream on it to read it.
b. Make sure the resource is in your applet's codebase
0
 

Author Comment

by:need_help_pls
ID: 8181731
Sorry - yet another problem:

what do i do for the following...  i need to open a html file, which again works fine in the application, but not in the applet???

here is the code i am using currently:

     /**
      * Creates the help Panel
      *
      * @return thePanel ... the panel to be created
      */
     public JPanel createHelp()
     {
          JPanel thePanel = new JPanel();
          thePanel.setBorder(BorderFactory.createTitledBorder("Help"));

          ImageIcon back = new ImageIcon("back.jpg");
          JButton backBtn = new JButton(back);
          helpLbl = new JLabel(HELP_SELECT);

          try
          {
               ep = new JEditorPane("http://student.cs.ucc.ie/03/ekc1/projectHelp/test.html");
               ep.setPreferredSize(new Dimension(375,350));
               //ep.setPage(FILENAME);
          }
          catch (IOException ioe)
          {
               System.out.println(ioe.getMessage());
          }
          ep.setEditable(false);
          ep.addHyperlinkListener(new HyperlinkListener()
               {
                  public void hyperlinkUpdate(HyperlinkEvent he)
                  {
                       if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                       {
                            JEditorPane pane = (JEditorPane) he.getSource();
                            try
                            {
                                 pane.setPage(he.getURL());
                            }
                            catch (IOException ioe)
                            {
                                 System.out.println(ioe.getMessage());
                            }
                       }
                  }
               });
         
         
          backBtn.addActionListener(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
                    try
                    {
                         ep = new JEditorPane("http://student.cs.ucc.ie/03/ekc1/projectHelp/test.html#index");
                    }
                    catch (IOException ioe)
                    {
                         System.out.println(ioe.getMessage());
                    }
            }
        });

         
          JScrollPane viewer = new JScrollPane(ep);

          GridBagLayout gbl = new GridBagLayout();
          GridBagConstraints gbc = new GridBagConstraints();
          thePanel.setLayout(gbl);
          gbc.fill = GridBagConstraints.BOTH;
          gbc.anchor = GridBagConstraints.CENTER;
          gbc.insets = new Insets(4, 4, 4, 4);
          addComp(helpLbl, thePanel, gbl, gbc, 0, 0, 1, 150, 0, 0);
          //addComp(backBtn, thePanel, gbl, gbc, 0, 150, 1, 1, 0, 0);
          addComp(viewer, thePanel, gbl, gbc, 1, 0, 400, 400, 0, 0);

          return thePanel;
     }
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8181974
Is your applet being served from http://student.cs.ucc.ie?
0
 

Author Comment

by:need_help_pls
ID: 8182129
yeah.. applet is served from student.cs.ucc.ie
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8182179
Comment out the ImageIcon bit and let me know what happens
0
 

Author Comment

by:need_help_pls
ID: 8182637
the same - makes no difference...
when i hit the help btn in the gui my controller calls the above method create help, when i hit the help btn i get errors along the lines of :

java.security.AccessControlException: access denied (java.net.SocketPermission s
tudent.cs.ucc.ie resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
        at java.security.AccessController.checkPermission(AccessController.java:
401)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8182694
OK. I think you'll have to eliminate the potential problems one at a time, so comment out one thing at a time.
Try empty constructor and getStream on the editor pane
0
 

Author Comment

by:need_help_pls
ID: 8202845
ok:

sorry bout this its just that this is part of my final year project that is due to present on thursday so im kind of scared now:

my applet still doesnt work in the browser i have made the following changes below, and still all that happens is that it loads but wont work...

also, i still cannot get the help button to work in the applet viewer, however when i run it in the browser the panel will display but none of the links work????

im really confused!?!?!  any help would be great? emergency...

     public InputStream getData(String filename) throws Exception
     {
          InputStream is = null;
          try
          {
               //The applet is being run locally
               is = new FileInputStream(filename);
          }
          catch (SecurityException se)
          {
               //The applet is being run across the internet
               //getDocumentBase();
               //URL current = getDocumentBase();
               URL current = new URL("http://student.cs.ucc.ie/03/ekc1/project/GUIstuff/run.html");
               URL cgi = new URL(current.getProtocol(),
               current.getHost(), current.getPort(),

               current.getPath()+"/cgiread.cgi?filename="+filename);
               URLConnection con = cgi.openConnection();
               con.setDoOutput(true);
               con.setDoInput(true);
               con.setUseCaches(false);
               con.setRequestProperty("Content-type","text/plain");

               PrintStream out = new PrintStream(con.getOutputStream());
               out.print(filename);
               out.flush();
               out.close();
               
               is = con.getInputStream();
          }
          return is;
     }

     
     /**
      * Checks that the variable name supplied is valid
      * @return boolean
      */
     public boolean checkName(String theText)
     {
          try
          {
               BufferedReader validName = new BufferedReader(new InputStreamReader(getData("validChar.txt")));
               
               String letter = new String();
               
               while(validName.ready())
               {
                    StringTokenizer letterStk = new StringTokenizer(validName.readLine(), "\n");
                    letter = (String)letterStk.nextToken();
                   
                    if(theText.startsWith(letter))
                    {
                         return true;
                    }
               }
               if(!validName.ready())
               {
                    validName.close();
                    validName = new BufferedReader(new InputStreamReader(getData("validChar.txt")));
               }

               validName.close();
               return false;

          }
          catch(Exception ioe)
          {
               System.out.println("File not found");
               ioe.printStackTrace();
               return false;
          }
         
     }


where cgiread.cgi is:
#!/usr/bin/perl

@values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) {
    ($varname, $mydata) = split(/=/,$i);
    if ($varname == "filename")
    {
        $filename = $mydata;
    }
}

open(INFO, $filename);
@array=<INFO>;
close (INFO);
print "Content-type: text/plain\n\n";
foreach $line (@array)
{
print $line;
}
exit;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8202943
OK. The first thing you must do is to pay very close attention to the stack trace of any Exceptions. Check the plugin console
0
 

Author Comment

by:need_help_pls
ID: 8203017
im so sorry this is going to soud like a very silly question, it is just that i have never written/used any applet before, but how do i check the console when i am running the applet from a browser?
so not sure how to check what the problem is when i run it in the browser??

but, when i run it in the appletviewer i dont get any errors when running it until i hit the help button which gives: (i dont understand this error really - )

java.security.AccessControlException: access denied (java.net.SocketPermission s
tudent.cs.ucc.ie resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
        at java.security.AccessController.checkPermission(AccessController.java:
401)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)
        at java.net.InetAddress.getAllByName0(InetAddress.java:909)
        at java.net.InetAddress.getAllByName0(InetAddress.java:890)
        at java.net.InetAddress.getAllByName(InetAddress.java:884)
        at java.net.InetAddress.getByName(InetAddress.java:814)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:282)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:253)
        at sun.net.www.http.HttpClient.New(HttpClient.java:321)
        at sun.net.www.http.HttpClient.New(HttpClient.java:306)
        at sun.net.www.http.HttpClient.New(HttpClient.java:301)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:469)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:460)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:562)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:237
)
        at javax.swing.JEditorPane.getStream(JEditorPane.java:674)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:392)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:775)
        at javax.swing.JEditorPane.<init>(JEditorPane.java:249)
        at InterpreterGUI.createHelp(InterpreterGUI.java:362)
        at InterpreterGUI.helpFrame(InterpreterGUI.java:337)
        at InterpreterController.actionPerformed(InterpreterController.java:64)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
67)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1820)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:258)
        at java.awt.Component.processMouseEvent(Component.java:5021)
        at java.awt.Component.processEvent(Component.java:4818)
        at java.awt.Container.processEvent(Container.java:1525)
        at java.awt.Component.dispatchEventImpl(Component.java:3526)
        at java.awt.Container.dispatchEventImpl(Container.java:1582)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3359
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3074)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3004)
        at java.awt.Container.dispatchEventImpl(Container.java:1568)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:191)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8205363
OK, you can test it in appletviewer at first and then move to the browser later. Are you connecting outside your codebase in InterpreterGUI.createHelp(InterpreterGUI.java:362)?
0
 

Author Comment

by:need_help_pls
ID: 8205821
(InterpreterGUI.java:362)
ep = new JEditorPane("http://student.cs.ucc.ie/03/ekc1/projectHelp/test.html");


I run this code when using an appletviwer from my home directory on ocean(student.cs.ucc.ie), then a copy of this folder is uploaded to /csweb/03/ekc1/project/ which is ocean's web repository.  projectHelp/test.html is just another directory within that web repository.  All the code is identical to what is in my home directory.  When I run the code in my home directory, it does, as you can see above access the on-line version of test.html.

When i run in using an appletviewer from my home directory the aforementioned result of clicking the help btn occurs.  The java application works.
0
 

Author Comment

by:need_help_pls
ID: 8205868
(InterpreterGUI.java:362)
ep = new JEditorPane("http://student.cs.ucc.ie/03/ekc1/projectHelp/test.html");


I run this code when using an appletviwer from my home directory on ocean(student.cs.ucc.ie), then a copy of this folder is uploaded to /csweb/03/ekc1/project/ which is ocean's web repository.  projectHelp/test.html is just another directory within that web repository.  All the code is identical to what is in my home directory.  When I run the code in my home directory, it does, as you can see above access the on-line version of test.html.

When i run in using an appletviewer from my home directory the aforementioned result of clicking the help btn occurs.  The java application works.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8205882
In that case, you haven't followed my suggestion from earlier:

>>Try empty constructor and getStream on the editor pane
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8205912
You should construct the URL argument to that function as follows:

URL url = new URL(getCodeBase(), "somefile");

Find out what getCodeBase() returns so you can form the URL properly.
0
 

Author Comment

by:need_help_pls
ID: 8206065
sorry im not sure that i understand?  Im just looking at the apis for getStream and not sure how you mean me to use it..??
you mean the constructor for the EditorPane should be
ep = new JEditorPane();
but how do i go about setting the page then? using getStream?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8206077
URL url = new URL(getCodeBase(), "somefile");
ep.getStream(url);

i think!
0
 

Author Comment

by:need_help_pls
ID: 8206159
Z:\Project\GUIstuff>javac *.java
InterpreterGUI.java:365: cannot resolve symbol
symbol  : method getCodeBase  ()
location: class InterpreterGUI
                        URL url = new URL(getCodeBase(), "test.html");
                                          ^
InterpreterGUI.java:366: getStream(java.net.URL) has protected access in javax.s
wing.JEditorPane
                        ep.getStream(url);
                          ^
2 errors
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8206199
getCodeBase() needs to be in applet's scope.

Sorry - try setPage with that code instead of getStream
0
 

Author Comment

by:need_help_pls
ID: 8206226
uh-oh!  this code is all in my GUI class - I am not creating the applet here.  I have a separate class InterpreterMain that orignally invoked the GUI, that now creates the applet....  is there anyway around this??
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8206250
Pass the applet as a parameter to an appropriate constructor.
0
 

Author Comment

by:need_help_pls
ID: 8206267
I will try and explain that better.  my applet opens fine in the appletviewer and runs ok - the only problem i have with it in the applet viewer is when i hit the help button.  What should happen is that my actionlistener is my controller class will call gui.createHelp() which is the method pasted above that the code snipets are from.  this works fine in the applcation but not in the appletviwer.  (in the browser the editorpane loads but the link dont work - if that sheds any light on the matter)

ps:  I realise this must be very annoying, but i cant say how much i appreciate you taking the time for this - cant ask any class mates as they are all very busy too - so on my own and really stressed now - 1 day to go - arrrrggghhh!!! (maybe i should rethink my career choice!!!?!?!)   : )
0
 

Author Comment

by:need_help_pls
ID: 8206298
this is where i create the applet - how else should i do it if i need to pass it as a param to the gui class (if i picked up what you said correctly??)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/** A class that allows testing of interpreter, its GUI and the GUIs controller
 * (listener).
 * @author Katie Crowley 99037190 ekc1@student.cs.ucc.ie
 */

public class InterpreterMain extends JApplet
{
     public void init(){
          Interpreter interpreter = new Interpreter();
          InterpreterController controller = new InterpreterController();
          InterpreterGUI gui = new InterpreterGUI(controller);
          controller.setInterpreter(interpreter);
          controller.setGUI(gui);


        /* GUIs are simply subclasses of JPanel, so we add the GUI
           to a JFrame and make the JFrame visible.
        */

          //JFrame frm = new JFrame("JIN - Java Interpreter for Novice Programmers");
          Container contentPane = this.getContentPane();
          contentPane.add(gui);

          JMenuBar menuBar = new JMenuBar();
          JMenu fileMenu = gui.makeMenu();
          menuBar.add(fileMenu);
          this.setJMenuBar(menuBar);

          /*this.addWindowListener(new WindowAdapter()
               {  public void windowClosing(WindowEvent we)
                  {  System.exit(0);
                  }
               });

          this.pack();*/
          this.setSize(700, 550);
          //frm.setSize(900, 600);
          this.setVisible(true);

     }
     public static void main(String[] args)
     {
          /* Create interpreter, interpreter GUI and controller
          */

          Interpreter interpreter = new Interpreter();
          InterpreterController controller = new InterpreterController();
          InterpreterGUI gui = new InterpreterGUI(controller);
          controller.setInterpreter(interpreter);
          controller.setGUI(gui);


        /* GUIs are simply subclasses of JPanel, so we add the GUI
           to a JFrame and make the JFrame visible.
        */

          JFrame frm = new JFrame("JIN - Java Interpreter for Novice Programmers");
          Container contentPane = frm.getContentPane();
          contentPane.add(gui);

          JMenuBar menuBar = new JMenuBar();
          JMenu fileMenu = gui.makeMenu();
          menuBar.add(fileMenu);
          frm.setJMenuBar(menuBar);

          frm.addWindowListener(new WindowAdapter()
               {  public void windowClosing(WindowEvent we)
                  {  System.exit(0);
                  }
               });

          frm.pack();
          frm.setSize(700, 550);
          //frm.setSize(900, 600);
          frm.setVisible(true);

     }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8206310
Don't worry - these security constrictions are a pain!

>>the only problem i have with it in the applet viewer is when i hit the help button.  

My guess is it's down to the way the url is created, a suggested solution to which i've just given
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8206349
Maybe here?

>>InterpreterGUI gui = new InterpreterGUI(controller);

as

>>InterpreterGUI gui = new InterpreterGUI(controller, this);

0
 

Author Comment

by:need_help_pls
ID: 8206377
but the applet is created in InterpreterMain??
sorry the confusion is probably due to the fact that i have been looking at this code everyday for the past few months and now im just all over the place!?!?
0
 

Author Comment

by:need_help_pls
ID: 8206416
my labs are closing now, so I will check the site again in the morning.  hopefully things will be a bit clearer for me then also - thanks again, (goodnight/day whatever part of globe!!!)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209178
>>but the applet is created in InterpreterMain??

The applet reference is in scope here, so you should have no problem:

>>InterpreterGUI gui = new InterpreterGUI(controller, this);
0
 

Author Comment

by:need_help_pls
ID: 8209569
ok, so i changed the constructor for interpreterGUI to take it the applet and then ran it in the appletviewer with the following results:

java.lang.NullPointerException
        at InterpreterGUI.createHelp(InterpreterGUI.java:367)
        at InterpreterGUI.helpFrame(InterpreterGUI.java:339)
        at InterpreterController.actionPerformed(InterpreterController.java:64)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
67)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1820)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:258)
        at java.awt.Component.processMouseEvent(Component.java:5021)
        at java.awt.Component.processEvent(Component.java:4818)
        at java.awt.Container.processEvent(Container.java:1525)
        at java.awt.Component.dispatchEventImpl(Component.java:3526)
        at java.awt.Container.dispatchEventImpl(Container.java:1582)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3359
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3074)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3004)
        at java.awt.Container.dispatchEventImpl(Container.java:1568)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:191)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209606
Then you probably haven't passed the reference on properly to the InterpreterGUI.
0
 

Author Comment

by:need_help_pls
ID: 8209623
in InterpreterMain i have changed to :
public class InterpreterMain extends JApplet
{
     public void init()
     {
          Interpreter interpreter = new Interpreter();
          InterpreterController controller = new InterpreterController();
          InterpreterGUI gui = new InterpreterGUI(controller,this);
.... etc etc
}}

and in InterpreterGUI:

public InterpreterGUI(InterpreterController theController, JApplet j)
   {
      super();
       
       myApplet = j;
       
      /* Store the interpreter controller */
      controller = theController;
etc etc...
}

and in InterpreterGUI.createHelp()
               URL url = new URL(myApplet.getCodeBase(), "test.html");
               ep.setPage(url);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209664
Is this line 367?

>>URL url = new URL(myApplet.getCodeBase(), "test.html");
0
 

Author Comment

by:need_help_pls
ID: 8209682
line 367 = ep.setPage(url);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209700
1. Is ep valid?
2. Did you make sure that getCodeBase() returns what you think it does as i suggested before?
0
 

Author Comment

by:need_help_pls
ID: 8209725
code base returns :  file:/Z:/Project/GUIstuff/

ep should be valid... i have it declared as
private JEditorPane ep;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209746
1. I mean is the refence null, obviously
2. Is this url valid?
file:/Z:/Project/GUIstuff/test.html
0
 

Author Comment

by:need_help_pls
ID: 8209796
IT WORKS NOW!!!!!! not sure why but am so happy that it does!!!!!!   maybe i should just leave it run in the appletviewer???  would it be very difficult to get it working in the browser??? thank you sooooo much - im so grateful!!!!!!!!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8209817
>>not sure why

Why not? Surely you know what you've changed!?
0
 

Expert Comment

by:CleanupPing
ID: 9058673
need_help_pls:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9873435
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question