Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

start another applet from an applet

Posted on 1999-06-28
15
Medium Priority
?
423 Views
Last Modified: 2013-12-29
how can i start a second applet from an applet?
0
Comment
Question by:wchiang
[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
  • 8
  • 6
15 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 200 total points
ID: 1244703
use

getAppletContext.showDocument(URL_OF_THE_OTHER_APPLETS_HTML, "_blank");

Cheers,
  Nik
0
 

Author Comment

by:wchiang
ID: 1244704
diakov,
I used this line of code:

getAppletContext.showDocument("C:\Program Files\Internet Explorer\Html\EaErrSmV.html", " ");

when I tried to save it, I got the message "invalid escape sequence" on the "\P" in the line. Any ideas?

thanks,
wchiang

0
 
LVL 8

Expert Comment

by:diakov
ID: 1244705
May be I didn't give enough details. With URL I meant an URL object. I notice several generic weaknesses in the code you pasted:
"C:\Program Files\Internet Explorer\Html\EaErrSmV.html"
should be
"file://C:/Program Files/Internet Explorer/Html/EaErrSmV.html"
or if you insist on using the "\" it should be doubled - "\\" as in Java \ is a beginning of an escape sequence.

URL u;
try
{
  u = new URL("file://C:/Program Files/Internet Explorer/Html/EaErrSmV.html"); //for file
  u = new URL("http://mywebserver.com/Html/EaErrSmV.html"); //for a URL address
}
catch (Exception e)
{
  e.printStackTrace();
}

then you do the

getAppletContext.showDocument(u, "_blank");

where "_blank" is tell the browser to open the new URL in a new window. There are several more commands (look in the API reference) like "_parent", etc.

Cheers,
  Nik

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:wchiang
ID: 1244706
diakov,
I made the changes in the following code. when I ran it, the applet viewer showed the first applet. When I click on "OK", the console shows the data retrieved from the server, but the second applet still doesn't show up. What's wrong?

wchiang

public void btnOK_ActionPerformed(java.awt.event.ActionEvent actionEvent)
{
      strlogon = new String(gettxfLogon().getText().toString());

      if ((strlogon.length() != 8) ||
            !Character.isLetter(strlogon.charAt(0)) ||
            !Character.isLetter(strlogon.charAt(1)) ||
            !Character.isLetter(strlogon.charAt(2)) ||
            !Character.isLetter(strlogon.charAt(3)) ||
            !Character.isLetter(strlogon.charAt(4)) ||
            !Character.isLetter(strlogon.charAt(5)) ||
            !Character.isLetter(strlogon.charAt(6)) ||
            !Character.isLetter(strlogon.charAt(7)))
            {gettxfStatu().setText("Please enter correct logon ID.");}
      else
            {
                  strCtrSw = "READ";
            
                  strCltMs = new String("EAD|" +
                                                strCtrSw +
                                                gettxfLogon().getText().toString().toUpperCase() +
                                                getchoStatu().getSelectedItem().toString().toUpperCase() +
                                                getchoType().getSelectedItem().toString().toUpperCase() +
                                                gettxfStrDt().getText().toString().toUpperCase() +
                                                gettxfEndDt().getText().toString().toUpperCase() +
                                                "\n");

                  //System.out.println(strCltMs);
                  String spaces = "a";
                  int len = strCltMs.length();
                  int remaining = 44 - len;
      
                  for(int i = 0; i<remaining-3; i++ )
                        spaces = spaces + "a";

                  strCltMs = strCltMs + spaces;

                  //EaErrNet net = new EaErrNet(strCltMs, this);
                  eaErrNet = new EaErrNet(strCltMs);
                  eaErrNet.start();

                  //eaErrSmV = new EaErrSmV();
                  //eaErrSmV.start();

                  try
                  {
                        uSmV = new URL("file://C:/Program Files/Internet Explorer/Html/EaErrSmV.html/");
                  }

                  catch (Exception e)
                  {
                        e.printStackTrace();
                  }
                  
                  getAppletContext().showDocument(uSmV, "_blank");
                  
            }
}
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244707
It is OK that it does not work. You probably got a security exception. To be sure, check the messages in the Java console of your IE (or Netscape).

There is a simple rule that all 'unsigned' applets follow:
the applet has a source of origin. If the applet comes from a web server, it has very limited access to the local machine it is downloaded to. One of the things it cannot do is to open a file on the local machine.

Solution 1: Put the file you are opening on the web server and change the URL to the proper address.

Solution 2: Sign the original applet. Afterward try to grant disk access permission.

Solution 3: Open the original applet's page from the local disk, then it will have lighter access rights and a showDocument will succeed.

I'd suggest solution 1, since it is most natural and everybody uses it.

Cheers,
  Nik

P.S. Do not forget to look in Java console and tell me what happens there upon loading of your applet.

0
 

Author Comment

by:wchiang
ID: 1244708
diakov,
I don't see any error messages in the console. The standard out shows the test data that I got from the server. There's nothing in standard in. I'll try your suggestions and see what happens.
wchiang

0
 

Author Comment

by:wchiang
ID: 1244709
diakov,
another thought just occurred to me: I'm using visualage java so do I need to export the ErrSmV.class file to a particular directory if I'm opening it locally? To open it from the server, I assume I should ftp this class file and the EaErrSmv.html to any directory on the server?
wchiang
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244710
that is correct. the other file, the one that you're going to open in a new window should be there as well, but then you have to use URL (not directory), much like the URL you will type in the web browser for the initial page.

Cheers,
  Nik
0
 

Author Comment

by:wchiang
ID: 1244711
diakov,
since I don't have access to a web server right now, could you give me more directions on either solution 2 or 3 so i could try it that way? As far as I know, I am opening the first applet locally, so what else needs to be done?
wchiang
0
 

Author Comment

by:wchiang
ID: 1244712
diakov,
since I didn't get an error message on the console when running the first applet (as it tried to open the second one), do you still think this is a secuirty issue on my client?
wchiang
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244713
I'm running out of ideas so I'll give you as many item as I can think of:

- set up description: page 1 with an applet 1 embedded in a applet tag is open on the local computer (right?). page 2 is shown from applet 1 with showDocument(). (right?)

- there is an 'if' in your source, check whether the else statement (where the html 2 resides) is reached. Probably not.

- check the html 2. whether an applet is there.

- be more creative, make a simple example with a simple apple that shows a second html page, to check the new code I suggest, because the problem is probably in your other code.

Cheers,
  Nik
0
 

Author Comment

by:wchiang
ID: 1244714
diakov,
I'll pursue this later 'cause I have to work on something else for now. Thanks for all the help!
wchiang
0
 

Expert Comment

by:decent
ID: 1244715
I guess the question itself was wrong or not well formed and the discussion continued unnecessarily. It is just a simple case of opening another web page from an applet and that can be done using a net.URL object. I thought the guy was trying to ask about inter-applet communications.

I am new here. But there seem to be flooding of UNNECESSARY CONTINUATION of answers here. The topic should have closed a long back, but the user is just trying to ask everything without trying to READ or DO something. This is not a sign of a serious developer.
0
 

Author Comment

by:wchiang
ID: 1244716
decent,
My question probably was not well formed because I didn't have a good understanding of the topic. I was hoping to get a quick fix without spending too much time reading.

Diakov,
Did I give you the points yet? If not, I'd be happy to do so.
wchiang
0
 
LVL 8

Expert Comment

by:diakov
ID: 1244717
thanks.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

715 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