Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4073895

printAll causes NullPointerException when used on Component derived class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.2
    • client-libs
    • None
    • x86
    • windows_95



      Name: joT67522 Date: 08/22/97


      After starting the application, select File->Print
      Soon after selecting all parameters, the following exception occures:

      Exception occurred during event dispatching:
      java.lang.NullPointerException:
              at java.awt.Rectangle.intersects(Rectangle.java:283)
              at java.awt.Container.paint(Container.java:642)
              at TestFrame.paint(TestFrame.java:62)
              at java.awt.Component.print(Component.java:1160)
              at java.awt.Container.print(Container.java:666)
              at sun.awt.windows.WCanvasPeer.print(WCanvasPeer.java:56)
              at sun.awt.windows.WPanelPeer.print(WPanelPeer.java:32)
              at java.awt.Component.printAll(Component.java:1172)
              at TestFrame.actionPerformed(TestFrame.java:82)
              at java.awt.MenuItem.processActionEvent(MenuItem.java:336)
              at java.awt.MenuItem.processEvent(MenuItem.java:307)
              at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:144)
              at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:136)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:65)

      The code listings are here:

      //////////////////////////////////////////////////////////////////////
      // TestFrame.java
      //
      // Test bed for ???
      //
      // (C) 1997 Drasko Kokic
      //////////////////////////////////////////////////////////////////////


      import java.awt.*;
      import java.applet.*;
      import java.awt.event.*;
      import java.net.*;
      import java.io.*;
      import java.lang.*;
      import java.util.*;


      public class TestFrame extends Frame implements ActionListener
        {

          public TestFrame ()
            {
              super ("Test Frame");
           // setResizable (false);
           // setLayout (new FancyLayout ());
              setBackground (Color.lightGray);
              Menu m;
              MenuItem mi;
              MenuBar mb = new MenuBar ();
               m = new Menu ("File");
                m.add (new MenuItem ("Open"));
                m.add (new MenuItem ("Close"));
                m.add (mi = new MenuItem ("Print"));
                 mi.setActionCommand ("Print"); mi.addActionListener (this);
                m.add (mi = new MenuItem ("Exit"));
                 mi.setActionCommand ("Exit"); mi.addActionListener (this);
              mb.add (m);
               m = new Menu ("Edit");
                m.add (new MenuItem ("Cut"));
                m.add (new MenuItem ("Copy"));
                m.add (new MenuItem ("Paste"));
              mb.add (m);
               m = new Menu ("Action");
                m.add (mi = new MenuItem ("new Singelton"));
                 mi.setActionCommand ("Singelton"); mi.addActionListener (this);
                m.add (mi = new MenuItem ("new JukeBox"));
                 mi.setActionCommand ("JukeBox"); mi.addActionListener (this);
              mb.add (m);
               m = new Menu ("View");
                m.add (new MenuItem ("???"));
              mb.add (m);
               m = new Menu ("Help");
                m.add (new MenuItem ("About"));
              mb.add (m);
              setMenuBar (mb);
            }


          public void paint (Graphics g)
            {
              super.paint (g);
            }


          public void actionPerformed (ActionEvent ae)
            {
              String cmd = ae.getActionCommand();
              System.out.println ("command :"+cmd);
              if (cmd.equals("Exit"))
                System.exit (0);
              if (cmd.equals("Singelton"))
                aaa.testData (1);
              if (cmd.equals("JukeBox"))
                aaa.testData (2);
              if (cmd.equals("Print"))
                {
                  PrintJob pj = getToolkit().getPrintJob (this, "Printing Job", null);
                  if (pj != null)
                    {
                      Graphics g = pj.getGraphics();
                      printAll (g);
                      g.dispose();
                      pj.end();
                    }
                }
            }


          static AAA aaa = new AAA ();

          public static void main (String args[])
            {
              TestFrame tf = new TestFrame ();
              tf.add (aaa); // if this get remarked, no problem with printAll !!!
              tf.pack (); tf.setVisible (true);
            }

        }

      //////////////////////////////////////////////////////////////////////
      // AAA.java
      //
      // ???
      //
      // (C) 1997 Drasko Kokic
      //////////////////////////////////////////////////////////////////////


      import java.awt.*;
      import java.applet.*;
      import java.awt.event.*;
      import java.net.*;
      import java.io.*;
      import java.lang.*;
      import java.util.*;


      class AAA extends Component
        {

          AAA ()
            {
              super();
              System.out.println (this);
              enableEvents (AWTEvent.MOUSE_EVENT_MASK);
              enableEvents (AWTEvent.MOUSE_MOTION_EVENT_MASK);

            }


          public void testData (int t)
            {
              System.out.println ("testData: "+t);
            }


          public Dimension getPreferredSize ()
            {
              return new Dimension (300, 300);
            }


          public Dimension getMinimumSize ()
            {
              return getPreferredSize ();
            }


          public void paint (Graphics g)
            {
         // System.out.println (this+" paint():");
              g.setColor (Color.lightGray);
              g.draw3DRect (0, 0, getSize().width-1, getSize().height-1, false);
              g.setColor (Color.black);
              super.paint (g);
            }


          public void processEvent (AWTEvent e)
            {
         // System.out.println (e);
              super.processEvent (e);
            }


          public void processMouseEvent (MouseEvent me)
            {
         // System.out.println (me);
              super.processMouseEvent (me);
            }


          public void processMouseMotionEvent (MouseEvent me)
            {
         // System.out.println (me);
              super.processMouseMotionEvent (me);
            }


        }


      Problem still exists with J1.1.2
      company - European Space Agency , email - ###@###.###
      ======================================================================

            rkhansunw Robi Khan (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: