Solved

Communications between applets

Posted on 1997-05-04
3
171 Views
Last Modified: 2013-11-23
I've got two applets that I would like to have communicate with each other, (actually it's just one way communication).  According to the books I've seen on the subject, it is supposed to be as easy as defining an instance of the applet
Applet reciver = getAppletContext().getApplet("client");
Then all you need to do is to call reciver.MethodName();  where MethodName() is a method in class client.  When I do this I get a message from my compiler (VJ++ 1.1) that MethodName() is not a method of class applet.  But shouldn't it be looking in class reciver and not class applet?  How do I establish communications between applets. (Code below)

//FlashBoard.java
import DataStructures.LinkedList;
import FlashBoardDataObjects.*;
import java.awt.*;
import java.applet.*;
import java.util.*;
import IDD_DIALOG1;


public class FlashBoard extends Applet
{
      IDD_DIALOG1 ctrls = new IDD_DIALOG1 (this);
      LinkedList list = new LinkedList();
      Applet client = getAppletContext().getApplet("output");

      public void init()
      {

            Date Now = new Date();
            String nDate = Now.toString();
            
        ctrls.CreateControls();
                        
            ctrls.CreateControls();
            ctrls.IDC_COMBO3.addItem("High");
            ctrls.IDC_COMBO3.addItem("Medium");
            ctrls.IDC_COMBO3.addItem("Low");
            ctrls.IDC_COMBO2.addItem("NCC");
            ctrls.IDC_COMBO2.addItem("Service Center");
            ctrls.IDC_COMBO2.addItem("Help Desk");
            ctrls.IDC_COMBO1.addItem("Open");
            ctrls.IDC_COMBO1.addItem("Updated");
            ctrls.IDC_COMBO1.addItem("Closed");
            ctrls.IDC_DATE.setText(nDate);
            Event ButtPress = new Event(ctrls.IDOK, Event.ACTION_EVENT, "Dummy String");
            deliverEvent(ButtPress);
      }

      public boolean handleEvent(Event evt)
      {
            
            Date Now = new Date();
            String nDate = Now.toString();
            FlashBoardData GetData = new FlashBoardData();

            if((evt.target==ctrls.IDOK) && (evt.id==Event.ACTION_EVENT))
            {
                  GetData.Description = ctrls.IDC_DESCRIPTION.getText();
                  GetData.Group = ctrls.IDC_COMBO2.getSelectedItem();
                  GetData.Priority = ctrls.IDC_COMBO1.getSelectedItem();
                  GetData.fDate = ctrls.IDC_DATE.getText();
                  GetData.Ticket = ctrls.IDC_EDIT1.getText();
                  GetData.Update = ctrls.IDC_UPDATE.getText();
                  list.Add(GetData);
            }
            client.update(list);
            return super.handleEvent(evt);
      }


}

//output.java
import java.applet.*;
import DataStructures.*;
import java.awt.*;
import FlashBoardDataObjects.*;

public class output extends Applet
{

      TextArea OutputView = new TextArea(25, 50);
      FlashBoardData GetData = new FlashBoardData();

      public void  init()
      {
            add(OutputView);
      }

      public void update(LinkedList list)
      {
            String out = new String();
            
            if(!list.IsNull())
            {
                  GetData = list.PullFirst();
                  out = ("Date: "+ GetData.fDate+'\n');
                  out = out.concat(" Ticket#" +GetData.Ticket+'\n');
                  out      = out.concat(" Description: "+ GetData.Description+'\n');
                  //out = out.concat(" Status: "+MyData.Status+'\n');
                  out = out.concat(" Update: "+GetData.Update+'\n');
                  out      = out.concat(" Priority: "+GetData.Priority+'\n');
                  out = out.concat(" Group: "+GetData.Group+'\n');      
                  OutputView.setText(out);
            }
      }
}

0
Comment
Question by:edc
  • 2
3 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220098
Could you post your HTML code, I think you are not assigning names to your applets.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220099
Specificaly, does your HTML APPLET Tag contain code to the effect of:

<APPLET CODE="FlashBoard.class" WIDTH=100 HEIGHT=150 NAME="FlashBoard"> </APPLET>

<APPLET CODE="output.class" WIDTH=100 HEIGHT=150 NAME="output"> </APPLET>

?

Your code looks prety good, but if you haven't used the NAME tag in HTML, Java has no way to resolve getAppletContext().getApplet("output");

0
 
LVL 3

Accepted Solution

by:
pc012197 earned 100 total points
ID: 1220100
Instead of

Applet client = getAppletContext().getApplet("output");

use

output client = (output)(getAppletContext().getApplet("output");

getApplet() returns an object of class Applet. You have to explicitly cast it to class output if you want to access methods of an output-instance from within class FlashBoard.



0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project error 5 56
HTTPSessionBindingListernter not configured in deployment descriptor 2 53
varialbe initialization 11 33
Java string replace 11 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 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