[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Communications between applets

Posted on 1997-05-04
3
Medium Priority
?
186 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

649 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