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 {
public JFrame frame = new JFrame();
private JDesktopPane desktop = new JDesktopPane();
public void initialize(int port){
System.out.println("333333333333333333333"+port);
try {
ServerSocket sc = new ServerSocket(port);
drawGUI();
while(true){
System.out.println("333333333333333333333"+port);
Socket client = sc.accept();
System.out.println("New client Connected to the server");
new ClientHandler(client,desktop);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void drawGUI(){
frame.add(desktop,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024,800);
frame.setFocusable(true);
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();
}
public void drawGUI(){
interFrame.setLayout(new BorderLayout());
interFrame.getContentPane().add(cPanel,BorderLayout.CENTER);
interFrame.setSize(1024,100);
desktop.add(interFrame);
try {
interFrame.setMaximum(true);
} catch (PropertyVetoException ex) {
ex.printStackTrace();
}
cPanel.setFocusable(true);
interFrame.setVisible(true);
}
public void run(){
Rectangle clientScreenDim = null;
ObjectInputStream ois = null;
drawGUI();
try{
ois = new ObjectInputStream(cSocket.getInputStream());
clientScreenDim =(Rectangle) ois.readObject();
}catch(IOException ex){
ex.printStackTrace();
}catch(ClassNotFoundException ex){
ex.printStackTrace();
}
new ClientScreenReciever(ois,cPanel);
System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
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;
cPanel.addKeyListener(this);
cPanel.addMouseListener(this);
cPanel.addMouseMotionListener(this);
try {
System.out.println("fffffffffffffffffffffffffffffff"+this);
writer = new PrintWriter(cSocket.getOutputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
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();
}
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();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
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();
}
}