Solved

Interface constructor

Posted on 2004-08-10
3
378 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

758 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

22 Experts available now in Live!

Get 1:1 Help Now