Results 1 to 20 of 20
  1. #1
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default Communicate betwwen two Applets

    Hi guys...........

    I have a problem. I want to communicate between two applets running in separate browser, but I can't. I have two .java file--

    1. SenderApplet.java
    2. ReceiverApplet.java

    SenderApplet.java used for input and ReceiverApplet.java used for output. In ReceiverApplet.html file I have done some javascript coding for open the SenderApplet.html file as popup(thats mean in searate window) and its open but not communicating with the ReceiverApplet.html file.
    So is it possible to communicate between two applet running in separate browser?

    And one more thing, when I merge these two .html file into another .html(SenderAppletReceiverApplet.html) file and run it in same page, same window it run perfectly and communicating with each other.

    // Receiver.java
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package Popup_Applet;


    import javax.swing.JApplet;

    import java.awt.BorderLayout;
    import java.awt.Color;

    import javax.swing.JApplet;
    import javax.swing.JTextArea;
    import javax.swing.JOptionPane;
    import javax.swing.JLabel;

    public class ReceiverApplet extends JApplet {

    JTextArea jta;
    JLabel jLbl;

    @Override
    public void init() {
    setSize(300, 300);
    setLayout(new BorderLayout());
    jta = new JTextArea(" ");
    add(jta, BorderLayout.CENTER);

    }

    public void putText(String s) {

    jta.append(s + "\n");


    }
    }



    // SenderApplet.java

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package Popup_Applet;


    import java.applet.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    import javax.swing.JApplet;
    import javax.swing.JSlider;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.JOptionPane;

    public class SenderApplet extends JApplet implements ActionListener {

    JSlider slider;
    JTextField tf;
    JButton button;
    JApplet ja;
    ReceiverApplet ma;

    public void init() {
    this.setLayout(new BorderLayout());


    tf = new JTextField(20);
    add(tf);
    tf.addActionListener(this);

    button = new JButton("CLICK");
    add(button,BorderLayout.SOUTH);
    button.addActionListener(this);


    }

    public void actionPerformed(ActionEvent e){

    ja = null;
    ja = (JApplet) getAppletContext().getApplet("ReceiverApplet");
    if(ja != null)
    {
    JOptionPane.showMessageDialog(rootPane, "not null");
    if(e.getSource() == button)
    {
    ma = (ReceiverApplet) ja;
    ma.putText(tf.getText());
    tf.setText("");
    }
    }
    else {
    JOptionPane.showMessageDialog(rootPane, "Null");
    tf.setText("");
    }
    }
    }


    and the .html files are

    //ReceiverApplet.html

    <HTML>
    <HEAD>
    <TITLE>Applet HTML Page</TITLE>
    <script language="javascript" type="text/javascript">
    <!--
    function popitup(url) {
    newwindow=window.open(url,'name','height=200,width =150');
    if (window.focus) {newwindow.focus()}
    return false;
    }

    // -->
    </script>
    </HEAD>
    <BODY>
    <P>
    <APPLET codebase="classes" code="Popup_Applet/ReceiverApplet.class" name="ReceiverApplet" width=350 height=200></APPLET>
    </P>
    <a href="SenderApplet.html" onclick="return popitup('SenderApplet.html')">Link to popup</a>
    </BODY>
    </HTML>


    //SenderApplet.html

    <HTML>
    <HEAD>
    <TITLE>Applet HTML Page</TITLE>
    </HEAD>
    <BODY>
    <P>
    <APPLET codebase="classes" code="Popup_Applet/SenderApplet.class" width=350 height=200></APPLET>
    </P>
    </BODY>
    </HTML>



    //SenderAppletReceiverApplet.html

    <HTML>
    <HEAD>
    <TITLE>Sender and Receiver applets.....................</TITLE>
    </HEAD>
    <BODY>
    <APPLET codebase="classes" code="Popup_Applet/ReceiverApplet.class" name="ReceiverApplet" width=750 height=100%></APPLET>
    <APPLET codebase="classes" code="Popup_Applet/SenderApplet.class" name="SenderApplet" width=230 height=100%></APPLET>
    </BODY>
    </HTML>




    Please help me..........
    Help me with proper code and example if u can...........
    Thanks everybody.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    When it doesn't work, what error messages are shown in the browser's java console?
    Copy and paste the error messages here.

  3. #3
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Thanks for your reply.
    When I run ReceiverApplet.html file from build folder and after that i have opened the SenderApplet.html file as popup by click on the "Link to popup", it open but can't communicate. and i have used mozila firefox 4.0.1.
    I have cleared all error messages before run these programs.
    And the error messages of error console are ------



    Warning: XUL box for _moz_generated_content_after element contained an inline #text child, forcing all its children to be wrapped in a block.
    Source File: chrome://browser/content/browser.xul
    Line: 0

    chromejs.s3.amazonaws.com : server does not support RFC 5746, see CVE-2009-3555

    searchjs.s3.amazonaws.com : server does not support RFC 5746, see CVE-2009-3555

    Error: missing ; before statement
    Source File: http://cap1.conduit-apps.com/uTorrent/20110207/json.as
    Line: 34, Column: 6
    Source Code:
    class JSON {

    Warning: Unknown property 'scrollbar-face-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-highlight-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-shadow-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-3dlight-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-arrow-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-track-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Unknown property 'scrollbar-darkshadow-color'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Error in parsing value for 'padding-left'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Error in parsing value for 'padding-right'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Expected end of value but found '10'. Error in parsing value for 'PADDING'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Error in parsing value for 'WIDTH'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Error in parsing value for 'width'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Error in parsing value for 'width'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    Warning: Expected end of value but found '5'. Error in parsing value for 'padding'. Declaration dropped.
    Source File: http://hosting.conduit.com/styles/ve...ver=1651991658
    Line: 1

    and so on..................
    Last edited by mitra; 07-20-2011 at 06:44 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    Those messages are NOT from the browser's java console.
    Here is a sample of what is first put in a java console:

    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner

    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

  5. #5
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Those messages are NOT from the browser's java console.
    Here is a sample of what is first put in a java console:

    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner

    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    Thank you for your help.
    But how can i open java console from my firefox browser?
    I have been using firefox 4.0.1.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    What are the settings in the OS's Settings|Control panel?
    Turn on the java console there.

  7. #7
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hello,

    I'm check all file java have ok, not problem

    I think problem problem is that code path call java applet in html
    Java Code:
    <APPLET codebase="classes" code="Popup_Applet/ReceiverApplet.class" name="ReceiverApplet" width=350 height=200></APPLET>
    I'm has change path of html file and it's action.
    This result: Popup_Applet.rar

    Have you nice day...,

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    If you can see the browser's java console, there could be error messages there telling you what the problem is.

  9. #9
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    yes, I found java console, and when I try to run ReceiverApplet.html, its shows me --------

    Java Plug-in 1.7.0
    Using JRE version 1.7.0-ea-b139 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Administrator
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    And still its not working when these .html files try to communicate each other from different window.
    When I try to communicate with ReceiverApplet by this line of code --

    "ja = (JApplet) getAppletContext().getApplet("ReceiverApplet"); // line 49 in ReceiverApplet.java "

    within a same page of browser it returns NOT NULL but when I try to communicate between two, runs in separate window or page it returns NULL.
    I cant understand what happened........
    Last edited by mitra; 07-21-2011 at 07:31 AM.

  10. #10
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hi,When used the code for you the full message of java console following:

    Java Code:
    Java Plug-in 1.6.0_23
    Using JRE version 1.6.0_23-b05 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\GEM
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    ---> This text only the help fo java console
    
    ----------------------- Bug Console-------------------
    load: class ReceiverApplet.class not found.
    java.lang.ClassNotFoundException: ReceiverApplet.class
    	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\Documents and Settings\GEM\My Documents\JCreator Pro\MyProjects\SenderApplet\src\classes\ReceiverApplet\class.class (The system cannot find the path specified)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	... 9 more
    Exception: java.lang.ClassNotFoundException: ReceiverApplet.class
    ^^! hopefully be useful for you....

  11. #11
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Thanks for ur help.

    but java console shows me just what I pasted before, and nothing else.
    Wht should I do?

  12. #12
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hi

    As I said before, the cause of the problem is that

    Hello,

    I'm check all file java have ok, not problem

    I think problem problem is that code path call java applet in html
    Code:

    <APPLET codebase="classes" code="Popup_Applet/ReceiverApplet.class" name="ReceiverApplet" width=350 height=200></APPLET>

    I'm has change path of html file and it's action.
    This result: Popup_Applet.rar

    Have you nice day...,

    if you cannot determine the path of *.class file, you has try copy all *.class and *.html to one folder and edit:

    <APPLET code="ReceiverApplet.class" name="ReceiverApplet" width=350 height=200></APPLET>


    you can reference: Popup_Applet.rar


    Good luck...

  13. #13
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by bnson View Post
    Hi

    As I said before, the cause of the problem is that




    if you cannot determine the path of *.class file, you has try copy all *.class and *.html to one folder and edit:

    <APPLET code="ReceiverApplet.class" name="ReceiverApplet" width=350 height=200></APPLET>


    you can reference: Popup_Applet.rar


    Good luck...

    Hi bnson...

    Its still not working, I have done what u said me.
    Is it working in your system?
    Forget about "SenderAppletReceiverApplet.html" file. Its working fine.I have just two .html files ---
    1. ReceiverApplet.html and
    2. SenderApplet.html.

    Just run ReceiverApplet.html file in your browser and then click on "Link to popup" hyperlink , a popup window will open, type something in the textfield just above the "CLICK ON ME" button and then click on the button. Now if the typed letters will show in the text area of the ReceiverApplet window, then it will work perfectly.

    So please check it once.....

    Thanks.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    when I try to communicate between two, runs in separate window or page it returns NULL.
    That is probably because there is NO communication between different instances of a browser each loading a different html page. The applets must be loaded in the SAME page to see one another.

  15. #15
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    That is probably because there is NO communication between different instances of a browser each loading a different html page. The applets must be loaded in the SAME page to see one another.
    Thanks Norm for ur reply.

    yes, thats i'm talking about.....
    So is there any way to do this?
    I mean to say --- is it possible to communicate between these two applets run into different window or pages?


    Thanks, thanks again.............

  16. #16
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hi,

    Sorry, I'm don't understand your purpose, now I'm understand.
    The code for you can not perform that purpose,....
    You should go the other way, reference Java Server and Client.
    After work I will send you example.

    Have you nice day,....

  17. #17
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by bnson View Post
    Hi,

    Sorry, I'm don't understand your purpose, now I'm understand.
    The code for you can not perform that purpose,....
    You should go the other way, reference Java Server and Client.
    After work I will send you example.

    Have you nice day,....

    Thanks bnson for your help.
    you can paste your code here or you can mail me at "Moderator edit: removed"

    Thanks a lot.........
    Have a nice day.
    Last edited by DarrylBurke; 07-22-2011 at 10:31 AM. Reason: Removed email address

  18. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default

    Please keep all discussion on the forum.

    db

  19. #19
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hi, Sorry late, I have a party weekend ^^!

    AppletServerClient_SenderReciver.rar

    1. The first run Sever_Receiver_Applet
    2. The last run RunClient_Sender_Applet

    *Note:
    I have not optimized the sensitivity of the interface, if you do not see it work, please use your mouse or adjust the window size or "Minimize" "Maximize" it's.
    If it's not run then use policy file.

    Good luck,....

  20. #20
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

Similar Threads

  1. different methods to communicate with DB
    By mallikanala in forum New To Java
    Replies: 2
    Last Post: 06-16-2011, 10:33 AM
  2. communicate with xml-rpc
    By tah_206207 in forum New To Java
    Replies: 2
    Last Post: 04-18-2011, 09:14 PM
  3. trying to communicate between classes
    By rippon in forum New To Java
    Replies: 8
    Last Post: 02-09-2011, 11:20 PM
  4. session Management betwwen two application
    By sachin srivastava in forum New To Java
    Replies: 2
    Last Post: 01-21-2009, 05:12 PM
  5. Communicate vb.NET with Java
    By cachi in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 12:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •