Solved

Interface constructor

Posted on 2004-08-10
3
426 Views
Last Modified: 2010-05-18
If I have:

-----------------------
ClientCallbacks.java
-----------------------
public interface ClientCallbacks extends java.rmi.Remote
{
    public void receiveMessage(String msg) throws java.rmi.RemoteException;
}

----------------------
ChatImpl.java
---------------------
    public void connect(ClientCallbacks cl) throws java.rmi.RemoteException
     {
           
     }

---------------------
Client.java
---------------------

ClientCallbacks callbacks;  
Connect.addActionListener(new ActionListener()
{
      public void actionPerformed(ActionEvent e)
        {
           // Complete to add action for connect.
       }
 }
);


As you can see, the connect.addActionListener wants to call the method Connect() in ChatImpl.java. How can I code that?? Would this work?

         Chat cs = new ChatImpl();
         cs.connect(callbacks);

??
0
Comment
Question by:jtcy
[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
3 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 11770469
jtcy - How can we know whether it would work? Why don't you try it? If it is not working then - describe what is actually happenaing.
0
 
LVL 6

Expert Comment

by:valipotor
ID: 11770730
>> Connect.addActionListener(new ActionListener()
>> {
>>      public void actionPerformed(ActionEvent e)
>>        {
>>           // Complete to add action for connect.
>>       }
>>  }
>> );

Define Connect.
0
 
LVL 6

Accepted Solution

by:
expertmb earned 50 total points
ID: 11771001
>>Chat cs = new ChatImpl();
     >>    cs.connect(callbacks);

this works if

//Chat.java

interface Chat{
  public void connect(ClientCallbacks cl) throws java.rmi.RemoteException;
}

ChatImpl implements Chat{

    public void connect(ClientCallbacks cl) throws java.rmi.RemoteException
     {
          //do something
     }

}
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
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 …
Suggested Courses

636 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