Solved

Communications between applets

Posted on 1997-05-04
3
175 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
[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
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

724 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