Solved

Communications between applets

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maven java path setting 5 50
word0 challenge 3 56
GUI builder for Eclipse? 8 8
Java DateChooser? 2 5
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now