Click here to Skip to main content
15,889,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
now i am getting images of client,mouse action listener command not working
please solve me this problem

i am totally new to this really i am not able to follow this code
here they have used thread i dont know how does it work.
start(); what does this function do..



here i have craeted one frame and add tabbedpanel
in srever pane--having one text field to get the port no and one button "connect client"

if that button is pressed new ServerInitiator() called

if (action!=null && action.equals("Connect Client")){

                        String port = lMainPanelObj.lListiningPortField.getText();
                        System.out.println("heeee System Connected"+port);
                        new ServerInitiator().initialize(Integer.parseInt(port));
                        System.out.println("heeee System77777777777777777777 Connected");
                  }


In this i am facing problem in frames ,

public class ServerInitiator {
      //Main server frame
      public 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 = JOptionPane.showInputDialog("Please enter listening port");
      //   new ServerInitiator().initialize(Integer.parseInt(port));
   // }

      public void initialize(int port){
                  System.out.println("333333333333333333333"+port);
            try {
                  ServerSocket sc = new ServerSocket(port);
                  //Show Server GUI
                  drawGUI();
                  //Listen to server port and accept clients connections
                  while(true){
                        System.out.println("333333333333333333333"+port);
                        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.add(desktop,BorderLayout.CENTER);
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setSize(1024,800);
                  frame.setFocusable(true);
                  //Show the frame in a maximized state
                  //frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
                  frame.setVisible(true);
      }
}


here it is calling <b>new ClientHandler(client,desktop);</b>

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) {
            System.out.println("Hello ram i am here");
            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(1024,100);
            desktop.add(interFrame);
         try {
                  //Initially show the internal frame maximized
                  interFrame.setMaximum(true);
            } catch (PropertyVetoException ex) {
                  ex.printStackTrace();
            }
            //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);
            System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
            //Start sending events to the client
            new ClientCommandsSender(cSocket,cPanel,clientScreenDim);
      }

}


here it is calling <b>new

ClientScreenReciever(ois,cPanel);</b>
                                 new <b>ClientCommandsSender(cSocket,cPanel,clientScreenDim);</b>

i am facing problem in
<b>ClientCommandsSender(cSocket,cPanel,clientScreenDim)</b>

here am facing problem

KeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);

public class ClientCommandsSender implements KeyListener,
            MouseMotionListener,MouseListener {

      private Socket cSocket = null;
      private JPanel cPanel = null;
      private PrintWriter writer = null;
      private Rectangle clientScreenDim = null;

      ClientCommandsSender(Socket s, JPanel p, Rectangle r) {
            cSocket = s;
            cPanel = p;
            clientScreenDim = r;

            //Associate event listners to the panel
            cPanel.addKeyListener(this);
            cPanel.addMouseListener(this);
            cPanel.addMouseMotionListener(this);
            try {
                  //Prepare PrintWriter which will be used to send commands to
                  //the client
                  System.out.println("fffffffffffffffffffffffffffffff"+this);
                  writer = new PrintWriter(cSocket.getOutputStream());
            } catch (IOException ex) {
                  ex.printStackTrace();
            }
           
      }

      //Not implemeted yet
      public void mouseDragged(MouseEvent e) {
      }

      public void mouseMoved(MouseEvent e) {

            double xScale = clientScreenDim.getWidth()/cPanel.getWidth();
            System.out.println("xScale: " + xScale);
            double yScale = clientScreenDim.getHeight()/cPanel.getHeight();
            System.out.println("yScale: " + yScale);
            System.out.println("Mouse Moved");
            writer.println(EnumCommands1.MOVE_MOUSE.getAbbrev1());
            writer.println((int)(e.getX() * xScale));
            writer.println((int)(e.getY() * yScale));
            writer.flush();
      }

      //this is not implemented
      public void mouseClicked(MouseEvent e) {
      }

      public void mousePressed(MouseEvent e) {
            System.out.println("Mouse Pressed");
            writer.println(EnumCommands1.PRESS_MOUSE.getAbbrev1());
            int button = e.getButton();
            int xButton = 16;
            if (button == 3) {
                  xButton = 4;
            }
            writer.println(xButton);
            writer.flush();
      }

      public void mouseReleased(MouseEvent e) {
            System.out.println("Mouse Released");
            writer.println(EnumCommands1.RELEASE_MOUSE.getAbbrev1());
            int button = e.getButton();
            int xButton = 16;
            if (button == 3) {
                  xButton = 4;
            }
            writer.println(xButton);
            writer.flush();
      }

      //not implemented
      public void mouseEntered(MouseEvent e) {
      }

      //not implemented
      public void mouseExited(MouseEvent e) {

      }

      //not implemented
      public void keyTyped(KeyEvent e) {
      }

      public void keyPressed(KeyEvent e) {
            System.out.println("Key Pressed");
            writer.println(EnumCommands1.PRESS_KEY.getAbbrev1());
            writer.println(e.getKeyCode());
            writer.flush();
      }

      public void keyReleased(KeyEvent e) {
            System.out.println("Mouse Released");
            writer.println(EnumCommands1.RELEASE_KEY.getAbbrev1());
            writer.println(e.getKeyCode());
            writer.flush();
      }

}
Posted
Updated 10-Mar-10 2:28am
v2

rampraveen wrote:
mouse action listener command not working


What does this mean? We cannot guess what your code is doing or what the results of your actions are. Please explain in detail, and include snippets of the code that you think is not working.
 
Share this answer
 
rampraveen wrote:
i am totally new to this really i am not able to follow this code


Well in that case I suggest you go back to basics (see the Java Tutorials[^]) and spend some time studying the language and its classes. There really is no point in continuing this unless you are at least able to understand what the code does. I am afraid that people here do not have the time to take this project and try to figure out what it does.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900