Solved

Communications between applets

Posted on 1997-05-04
3
172 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

838 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