Skip to content
Snippets Groups Projects
Commit 3f069117 authored by Hai HoDac's avatar Hai HoDac
Browse files

added blinks

parent 98d50cb0
Branches
No related tags found
No related merge requests found
...@@ -296,9 +296,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -296,9 +296,9 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
try { try {
drawingController.broadcastDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize); drawingController.broadcastDrawing(client.getUserName(), drawing, currentMode.toString(), shapeColor, strokeSize);
if (currentMode == Mode.TEXT){ // if (currentMode == Mode.TEXT){
notifyUsingTimer(); // notifyUsingTimer();
} // }
// else { // else {
// drawingController.broadcastDrawingUserStopped(client.getUserName()); // drawingController.broadcastDrawingUserStopped(client.getUserName());
// } // }
...@@ -310,30 +310,30 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis ...@@ -310,30 +310,30 @@ public class DrawingArea extends JPanel implements MouseMotionListener, MouseLis
drawing = null; drawing = null;
} }
private void notifyUsingTimer() throws RemoteException { // private void notifyUsingTimer() throws RemoteException {
//
Timer timer = new Timer(4000, new ActionListener() // Timer timer = new Timer(4000, new ActionListener()
{ // {
//
@Override // @Override
public void actionPerformed(ActionEvent e) // public void actionPerformed(ActionEvent e)
{ // {
try { // try {
client.getDrawingController().broadcastDrawingUserStopped(client.getDefaultUserName()); // client.getDrawingController().broadcastDrawingUserStopped(client.getUserName());
} catch (RemoteException ex) { // } catch (RemoteException ex) {
ex.printStackTrace(); // ex.printStackTrace();
} // }
//
} // }
//
}); // });
try { // try {
client.getDrawingController().broadcastDrawingUser(client.getDefaultUserName()); // client.getDrawingController().broadcastDrawingUser(client.getUserName());
} catch (RemoteException ex) { // } catch (RemoteException ex) {
ex.printStackTrace(); // ex.printStackTrace();
} // }
timer.start(); // timer.start();
} // }
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
......
...@@ -4,6 +4,8 @@ import remote.IDrawingUpdate; ...@@ -4,6 +4,8 @@ import remote.IDrawingUpdate;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
...@@ -50,6 +52,29 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -50,6 +52,29 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setColor(color); client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().setColor(color);
client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().drawString(text, startPoint.x, startPoint.y); client.getApplicationMain().getPaintGUI().getDrawingArea().getG2().drawString(text, startPoint.x, startPoint.y);
client.getApplicationMain().getPaintGUI().getDrawingArea().repaint(); client.getApplicationMain().getPaintGUI().getDrawingArea().repaint();
removeClientTimer removeClient = new removeClientTimer(fromClient, client);
removeClient.start();
//
// Timer timer = new Timer(1000, new ActionListener()
// {
// private int i = 0;
// @Override
// public void actionPerformed(ActionEvent e)
// {
// DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel();
// System.out.println("action performed" + Integer.toString(i));
// int elementIndex = -1;
// if(temp.contains(fromClient)){
// elementIndex = temp.indexOf(fromClient);
// temp.remove(elementIndex);
// System.out.println("removed from list");
// }
// }
// });
// timer.start();
return true; return true;
} }
...@@ -136,3 +161,33 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate ...@@ -136,3 +161,33 @@ public class DrawingUpdate extends UnicastRemoteObject implements IDrawingUpdate
return true; return true;
} }
} }
class removeClientTimer extends Thread {
private String fromClient;
private Client client;
public removeClientTimer (String fromClient, Client client) {
this.fromClient = fromClient;
this.client = client;
}
@Override
public void run()
{
try {
DefaultListModel temp = client.getApplicationMain().getChatScreen().getAllUserModel();
if(!temp.contains(fromClient)) temp.addElement(fromClient);
sleep(1000);
int elementIndex = -1;
if(temp.contains(fromClient)){
elementIndex = temp.indexOf(fromClient);
temp.remove(elementIndex);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment