Results 1 to 4 of 4
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    287
    Rep Power
    3

    Default Project is Working on JFrame. But Not working on JApplet

    Hi!

    I am developing an application to share my client screen with server, it is working well on swing.
    But i want to develop as web application,
    i am trying to using applet. But i am facing the fallowing problem..,


    1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
    2) The problem may be to display the JDesktopPane or JInternalFrame.


    My working Server Code extends withe JFrame

    Java Code:
    
    package remoteserver;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import javax.swing.JApplet;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    
    
    public class ServerInitiator{
        //Main server frame
        private static JFrame frame = new JFrame();
        
        //JDesktopPane represents the main container that will contain all
        //connected clients' screens
        private JDesktopPane desktop = new JDesktopPane();
        
        public static void main(String args[]){
            String port = "1527";
          
            new ServerInitiator().initialize(Integer.parseInt(port));
    
        }
    
        public void initialize(int port){
    
            try {
                ServerSocket sc = new ServerSocket(port);
                //Show Server GUI
                drawGUI();
                //Listen to server port and accept clients connections
                while(true){
                    Socket client = sc.accept();
                    System.out.println("New client Connected to the server");
                    //Per each client create a ClientHandler
                    new ClientHandler(client,desktop);
                     
          
                }
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
           
        }
    
        /*
         * Draws the main server GUI
         */
        public void drawGUI(){
                frame.setBounds(100, 100,200,200);
                frame.add(desktop,BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //Show the frame in a maximized state
                frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
               
        }
    }

    I am trying to convert the JFrame container into JApplet (Problematic Code)

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package remoteserver;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.ContainerListener;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import javax.swing.JApplet;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import static javax.swing.text.html.HTML.Tag.CODE;
    
    /**
     *
     * @author Android
     */
    
    
    public class ServerScreen extends JApplet {
    
        /**
         * Initialization method that will be called after the applet is loaded into
         * the browser.
         */
        private JDesktopPane desktop;
        Container pane;
        public void init() {
            // TODO start asynchronous download of heavy resources
            desktop = new JDesktopPane();
            pane=getContentPane();
            pane.setLayout(new BorderLayout());
            //ServerInitiator server_init=new ServerInitiator();
            String port = "1527";
            //server_init.initialize(Integer.parseInt(port));      
            initialize(Integer.parseInt(port));
    
            desktop.setOpaque(false);
    
        }
        
        public void initialize(int port){
    
            try {
                ServerSocket sc = new ServerSocket(port);
                //Show Server GUI
                drawGUI();
                //Listen to server port and accept clients connections
                while(true){
                    Socket client = sc.accept();
                    System.out.println("New client Connected to the server");
                    //Per each client create a ClientHandler
                    new ClientHandler(client,desktop);
                }
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
           
        }
    
        // TODO overwrite start(), stop() and destroy() methods
    
        private void drawGUI() {
             desktop.setVisible(true);
             //setContentPane ( desktop );
              //desktop.setBounds(100, 100,200,200);
              pane.add(desktop,BorderLayout.CENTER);
              pane.setBounds(100, 100,200,200);
              pane.setVisible(true);
              
        }
    }


    My Handler Class for Container


    Java Code:
    
    
    package remoteserver;
    
    import java.awt.BorderLayout;
    import java.awt.Rectangle;
    import java.beans.PropertyVetoException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.net.Socket;
    import javax.swing.JDesktopPane;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JOptionPane;
    import javax.swing.JFrame;
    class ClientHandler extends Thread {
    
        private JDesktopPane desktop = null;
        private Socket cSocket = null;
        private JInternalFrame interFrame = new JInternalFrame("Client Screen",
                                                                true, true, true);
        private  JPanel cPanel = new JPanel();
        
        public ClientHandler(Socket cSocket, JDesktopPane desktop) {
            JOptionPane.showMessageDialog(cPanel,"Client Connected");
            this.cSocket = cSocket;
            this.desktop = desktop;
            start();
        }
    
        /*
         * Draw GUI per each connected client
         */
        public void drawGUI(){
            interFrame.setLayout(new BorderLayout());
            interFrame.getContentPane().add(cPanel,BorderLayout.CENTER);
           // interFrame.setSize(100,100);
            interFrame.setBounds(100, 100,200,200);
            desktop.add(interFrame);
            desktop.setBounds(100, 100,200,200);
           
            //this allows to handle KeyListener events
            cPanel.setFocusable(true);
            interFrame.setVisible(true);
        }
    
        public void run(){
    
            //used to represent client screen size
            Rectangle clientScreenDim = null;
            //Used to read screenshots and client screen dimension
            ObjectInputStream ois = null;
            //start drawing GUI
            drawGUI();
    
            try{
                //Read client screen dimension
                ois = new ObjectInputStream(cSocket.getInputStream());
                clientScreenDim =(Rectangle) ois.readObject();
            }catch(IOException ex){
                ex.printStackTrace();
            }catch(ClassNotFoundException ex){
                ex.printStackTrace();
            }
            //Start recieveing screenshots
            new ClientScreenReciever(ois,cPanel);
            //Start sending events to the client
            new ClientCommandsSender(cSocket,cPanel,clientScreenDim);
            
        }
     
    }

    I am looking for your guide to handle the Applet, can anyone guide me please..,

    Thank You!

    Have A Happy Day..,
    - Raj

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default Re: Project is Working on JFrame. But Not working on JApplet

    What is the "server" talking to?
    Could it be falling foul of the restrictions on Applets talking to something outside their source address?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,052
    Rep Power
    6

    Default Re: Project is Working on JFrame. But Not working on JApplet

    There must be an exception happening, find it and examine it.

    (and likely what Tolls says is the truth, it would help you to research the sandbox restrictions of applets).
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    287
    Rep Power
    3

    Default Re: Project is Working on JFrame. But Not working on JApplet

    Ok sure..,

    I will check the exception..,
    - Raj

Similar Threads

  1. Replies: 10
    Last Post: 11-23-2013, 06:47 PM
  2. KeyListener isn't working while jFrame not active
    By aslanali555 in forum AWT / Swing
    Replies: 5
    Last Post: 08-22-2013, 10:17 PM
  3. JFrame toFront() not working
    By KArelVH in forum AWT / Swing
    Replies: 2
    Last Post: 04-15-2009, 08:50 PM
  4. SquareRoot Jframe semi working
    By 2o2 in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2008, 03:20 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 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
  •