Jump to content

Emulating draw your thing

- - - - -

  • Please log in to reply
23 replies to this topic

#1
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
This is an online game that allows for one user to draw a certain object while the other users try to guess what that user is drawing. so i have set up the network what I want to know is how do i make what the drawing person is drawing appear on the jpanels of the other user's (like reflect th image being drawn on the other user's jpanel), i would also like to disable their jpanels so that they can't draw while the other user is drawing.

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Are you familiar with Socket programming in Java? You're going to need to know how to transmit information from one instance of your application to another over a network. If you're unfamiliar with Sockets, I suggest you start by reading tutorials on those first. Otherwise, if your question is purely design in nature, then what I would do is have the program sample the mouse's X-Y coordinates on the JPanel whenever the button is held down, and transmit those to the other connected players. On the receiving end, it's a simple matter of using Java's drawing API to draw lines between the points as they are received. There are some issues you'll have to consider such as packets arriving out of order, as is the case often with network communication, so you'll have to give each point a "serial number" so the receiving end knows in which order to connect them.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
Well yea I am aquainted with socket programming and have already done that part, what I am now having a problem with is the CorruptedHeaderException, not sure how to fix that so may be you might help and I don't think I know what you mean by

Quote

so you'll have to give each point a "serial number"


#4
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
One other thing is that each connection has to have a socket, a string object (for the player's name) and an outputStream how do I associate these three objects with each other.

#5
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

Quote

i would also like to disable their jpanels so that they can't draw while the other user is drawing.
You'll need to send a statement to the other players indicating that a player is drawing. Then, disable their draw JPanel until that player sends another statement indicating that they are finished drawing.

I haven't thought this out, but your players might need to be in separate threads. And when each player attempts to draw, lock this player, then unlock when done.

Quote

There are some issues you'll have to consider such as packets arriving out of order, as is the case often with network communication, so you'll have to give each point a "serial number" so the receiving end knows in which order to connect them.
This is true only with DatagramSocket programming correct?

Edited by lethalwire, 08 July 2011 - 01:59 PM.


#6
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas

lethalwire said:

This is true only with DatagramSocket programming correct?

Honestly, I'm not sure. I guess it depends on the implementation method you choose. I don't know if Java's Stream objects handle the reordering of packets into their original order or not. Basically, I'm thinking of some scenario where the first point is transmitted in one packet that might get delayed for some reason, so the 2nd point in the 2nd packet arrives before the first. If they are connected on the receiving JPanel in the order received, that would result in distortion of the image. Maybe someone has some insight into this, or if I'm overthinking this.

Mozana, what I meant by "serial number" was to number the points 1, 2, 3, and so on, in the order they are drawn, and transmit this information along with the point coordinates, so your receiving end knows when it has received one out of order, and can wait for the intermediate points before connecting the later point.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#7
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
OK the thing that i seem to be struggling with rite now is the CorruptedHeaderException and the concurrentModifioctionException caused by the collection containing the points. help

#8
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Need to see the stack trace and the body of code surrounding the line that threw the exception.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#9
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
Here is the snipet
[CODE]void run(){
Object obj = new Object();
while(true)
obj = input.readOject;\\This is d troublesome line
...
}[CODE]

#10
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
There's not a lot I can glean from that. What kind of data type is input? What are you trying to do here? What is readOject? (Spelling?)

Also, the stack trace would be nice.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#11
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
Ill post the stack trace then the code, i know i should have done it the other way.
Stack traceSEVERE: null
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1356)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at Client.run(Client.java:381)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
14 Jul 2011 12:31:19 PM Client run
SEVERE: null
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1356)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at Client.run(Client.java:381)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
14 Jul 2011 12:31:19 PM Client run

#12
Mozana

Mozana

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
The code for the run method, the client side reads from the server
 public void run() {

        Object read;// = new Object();

        while (true) {

            try {

                read = input.readObject();//this is where the stack trace traces the error back to                

            } catch (IOException ex) {

                Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);

            } catch (ClassNotFoundException ex) {

                Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);

            }

        }

    }





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users