Results 1 to 7 of 7
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default anybody understands chinese?

    I am studying code examples of the jfc book and found a example on a chinese site.
    The mouse released code of a simple drawing application shows a strange addition which,
    I believe has nothing to do with the programm. Look the code from the try block!
    This code opens a socket and sends packages with each mouse released click to a chinese address: wow!
    There is a chinese comment (what does it say) as well!
    What is that code actually doing, I mean what is it sending?
    The only relevant code of the try block concerning the program is:
    currentShape = null; of the if block (behind //)
    Here is the link for that code:
    baiban8.rar GraphicsBorderedCanvas.java
    the Chinese comment:
    //这里返回的就是你对像的字节数组了


    Java Code:
    public void mouseReleased(MouseEvent evt) {
            if ((evt.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                if (currentShape != null) {
                    drawShape();        // Remove shape
                    currentShape.changeEnd(evt.getX(), evt.getY());
                    currentShape.makePermanent();
                    drawShape();        // Redraw it
    
                    // Inform listeners
                    int count = drawingOps.size();
                    firePropertyChange(SHAPE_PROPERTY, new Integer(count - 1),
                                        new Integer(count));
    
                    //currentShape = null;
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    
    
    
    
                    try{
                    ByteArrayOutputStream buffers = new ByteArrayOutputStream();
    
                    ObjectOutputStream out = new ObjectOutputStream(buffers);
    
                   // System.out.println("currentShape is "  + currentShape);
                    out.writeObject(currentShape);
                    out.close();
    
                    byte mes1[]= buffers.toByteArray(); //这里返回的就是你对像的字节数组了
    
                    InetAddress inetaddress=InetAddress.getByName("235.0.0.125");
                    DatagramPacket datagrampacket1=
                        new DatagramPacket(mes1,mes1.length,inetaddress,8000);
                    System.out.println(mes1.length);
                    MulticastSocket multicastsocket1=new MulticastSocket(8000);
                    multicastsocket1.send(datagrampacket1);
    
                    currentShape = null;
                    repaint();
                    }
                    catch(Exception ee){
                        System.out.println(ee);
    
                    }
    
    
    
                }
            }
        }
    Last edited by willemjav; 11-15-2013 at 08:37 AM.

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

    Default Re: anybody understands chinese?

    The sending per click is not so bad, but the fact that a new socket connection is opened with each click is pretty much laughable. Don't do that :)

    In any case: try an online translation service, this forum is not your personal information service. Stick to questions about Java.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

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

    Default Re: anybody understands chinese?

    Do you actually need to know what that chinese means?
    It's commenting a line that is pretty obvious as to what it's doing. It probably just says "need the byte array as the constructor for DatagramPacket requires one".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: anybody understands chinese?

    The point is that this code has nothing to do with the present application
    which is just an old fashioned drawing program of the 80th.
    By taking out that code the application works still ok.
    It is sending a graphical shape:
    out.writeObject(currentShape);
    It does not make sense to me?

    But anyway......
    thanks both: It is not my code, it is from the jfc book
    and somebody messed it up, bit for what reason?
    OK I'll stick to my studying it all, gimbal2
    Last edited by willemjav; 11-15-2013 at 12:00 PM.

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: anybody understands chinese?

    This is the correct version of the code:

    Java Code:
    public void mouseReleased(MouseEvent evt) {
            if ((evt.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
                if (currentShape != null) {
                    drawShape();        // Remove shape
                    currentShape.changeEnd(evt.getX(), evt.getY());
                    currentShape.makePermanent();
                    drawShape();        // Redraw it
    
                    // Inform listeners
                    int count = drawingOps.size();
                    firePropertyChange(SHAPE_PROPERTY, new Integer(count - 1),
                                        new Integer(count));
    
                    currentShape = null;
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            }
         }

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

    Default Re: anybody understands chinese?

    Someone at that address really really wants to be sent lots of shapes?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

Similar Threads

  1. Replies: 0
    Last Post: 02-13-2013, 06:05 AM
  2. Chinese characters in Excel
    By Jayashreevmenon in forum Advanced Java
    Replies: 4
    Last Post: 08-04-2011, 11:51 AM
  3. Java in Chinese
    By ehochedez in forum NetBeans
    Replies: 0
    Last Post: 09-20-2009, 03:59 PM
  4. this looks chinese to me
    By xgi1008 in forum New To Java
    Replies: 18
    Last Post: 10-05-2008, 08:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •