Link to home
Start Free TrialLog in
Avatar of eugene007
eugene007

asked on

Java networked whiteboard

I have a client server code for a network base whiteboard application. I have tried running and debugging this code, however I came across alot of errors on the client side. The code can be downloaded from: http://www.cs.umd.edu/class/spring2005/cmsc433/p5/p5.jar

The errors I obtain while running the client side is:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Drawing.getShapes(Drawing.java:21)
        at Drawing.paintComponent(Drawing.java:62)
        at javax.swing.JComponent.paint(JComponent.java:1006)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4972)

        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
        at javax.swing.JComponent._paintImmediately(JComponent.java:4868)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4675)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)

        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:114)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Drawing.getShapes(Drawing.java:21)
        at Drawing.paintComponent(Drawing.java:62)
        at javax.swing.JComponent.paint(JComponent.java:1006)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4972)

        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
        at javax.swing.JComponent._paintImmediately(JComponent.java:4868)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4675)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)

        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:114)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


The server on the other hand keeps showing this message:

Starting remote canvas on rmi://home-527d:10880/Board

How do I solve this problem?

Your help is kindly appreciated.

Regards

Eugene
ASKER CERTIFIED SOLUTION
Avatar of Bart Cremers
Bart Cremers
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eugene007
eugene007

ASKER

So I need to create a shapebuffer object and parse it as a reference to createAndShowGUI method?
Yep, in case of a non-local setup, you'll need this. And probably some other areas where you need something similar.
But ShapeBuffer is an interface.
what I did for the main method for the whiteboard file is this:

    public static void main(String[] args) throws Exception {
      String boardURL;
      ShapeBuffer temp = new LocalBoard();

      final ShapeBuffer b = temp;
        final Whiteboard w = new Whiteboard();

      //Schedule a job for the event-dispatching thread:
      //creating and showing this application's GUI.
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                w.createAndShowGUI(b);
            }
          });
    }

and now the whiteboard appears. however the text option does not work.
The Text option is the same, look where it throws the nullpointer exception and find out what could be the cause (a null reference). Make sure you initialize the reference and that problem should be solved to.
I did this. I came up with a new class for the client side.

import java.awt.*;

public class CS4330xx extends AbstractText
{
    public CS4330xx(int x, int y)
    {
        super(x,y,"hello",Color.BLACK,1);
    }
   
    public boolean pointInShape(int x, int y, Graphics g, int margin)
    {
        return true;
    }
      
    public void draw(Graphics g)
    {
      
    }
}

In a file called TextTool.java I made this changes

public void dragStart(int x, int y, Graphics g)
{
        AbstractText text = new CS4330xx(x,y);
        ..............................
}

but the text option does not work.
You'll need to check the comments in the code. They'll show you the right way.
now it seems to be working :)