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

Solaris only: Adding more than 21 items to a Choice object hangs program.

    XMLWordPrintable

Details

    • 1.0.2
    • generic, sparc
    • solaris_2.4, solaris_2.5
    • Verified

    Description

      Solaris only: Adding more than 21 items to a Choice control hangs java program.

      Steps to reproduce
      Compile and run the attached code
      Type 20 into the Count text field
      Press <Add Items>
      <Click> on the choice control
      Replace 20 with 1 in the Count text field
      Press <Add Items>
      <Click> on the choice control
      // note: the choice control will not repsond

      import java.awt.*;
      import java.applet.Applet;

      public class ChoiceTest extends Applet
      {
         private Choice choice;

         public ChoiceTest()
         {
            setLayout( new BorderLayout() );
            add("North", new ChoiceTestCP(this) );
            add("Center", choice = new Choice() );
            choice.addItem("[none]");
         }

         public void init()
         {
            resize(400, 400);
         }

         public void addItem(String name)
         {
            choice.addItem(name);
         }

         public static void main(String argv[])
         {
            AppletFrame.startApplet("ChoiceTest", "Choice Test", argv);
         }
      }


      class ChoiceTestCP extends Panel
      {
         private ChoiceTest applet;
         private final String ADD_ITEM = "Add Item";
         private final String ADD_ITEMS = "Add Items";
         private int counter;
         private TextField field;

         public ChoiceTestCP(ChoiceTest ct)
         {
            applet = ct;
            counter = 0;
            add( new Label("Count") );
            add( field = new TextField( "1", 10 ) );
            add( new Button(ADD_ITEMS) );
         }

         public boolean action(Event evt, Object obj)
         {

            if( evt.target instanceof Button )
            {
               String label = obj.toString();
               if( label.equals(ADD_ITEM) )
               {
                  applet.addItem( Integer.toString( ++counter ) );
               }
               else if( label.equals(ADD_ITEMS) )
               {
                  int limit = Integer.parseInt( field.getText().trim() );
                  for( int i = 0; i < limit; ++i )
                     applet.addItem( Integer.toString( ++counter ) );
               }
               else
                  return false;

               return true;
               

            }
            else
               return super.action(evt, obj);
         }

      }


      /* Generic Applet to Application Frame
       * @(#)AppletFrame.java 1.4 02 Dec 1995 15:28:07
       * @author Kevin A. Smith
       *
       */

      import java.awt.Frame;
      import java.awt.Event;
      import java.awt.Dimension;
      import java.applet.Applet;

      // Applet to Application Frame window
      class AppletFrame extends Frame
      {

          public static void startApplet(String className,
                                         String title,
                                         String args[])
          {
             // local variables
             Applet a;
             Dimension appletSize;

             try
             {
                // create an instance of your applet class
                a = (Applet) Class.forName(className).newInstance();
             }
             catch (ClassNotFoundException e) { return; }
             catch (InstantiationException e) { return; }
             catch (IllegalAccessException e) { return; }

             // initialize the applet
             a.init();
             a.start();
        
             // create new application frame window
             AppletFrame f = new AppletFrame(title);
        
             // add applet to frame window
             f.add("Center", a);
        
             // resize frame window to fit applet
             // assumes that the applet sets its own size
             // otherwise, you should set a specific size here.
             appletSize = a.size();
             f.pack();
             f.resize(appletSize);

             // show the window
             f.show();
        
          } // end startApplet()
        
        
          // constructor needed to pass window title to class Frame
          public AppletFrame(String name)
          {
             // call java.awt.Frame(String) constructor
             super(name);
          }

          // needed to allow window close
          public boolean handleEvent(Event e)
          {
             // Window Destroy event
             if (e.id == Event.WINDOW_DESTROY)
             {
                // exit the program
                System.exit(0);
                return true;
             }
             
             // it's good form to let the super class look at any
             // unhandled events
             return super.handleEvent(e);

          } // end handleEvent()

      } // end class AppletFrame

      The description field as copied from bug report 1248978 follows:

      [5/7/96 xykong]

      The following application program is copied from
      the JAVA tutorial with slight modification.

      Note that I have added more choice items in
      the init() method for Choice c.

      The total choices in the example is 22. This
      program will not run. However, if I comment out
      the number 22 choice, the program will run.

      /*
       * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
       *
       * Permission to use, copy, modify, and distribute this software
       * and its documentation for NON-COMMERCIAL purposes and without
       * fee is hereby granted provided that this copyright notice
       * appears in all copies. Please refer to the file "copyright.html"
       * for further important copyright and licensing information.
       *
       * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
       * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
       * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
       * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
       * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
       * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
       */
      import java.awt.*;

      public class GUIWindow extends Frame {
          boolean inAnApplet = true;
          final String FILEDIALOGMENUITEM = "File dialog...";

          public GUIWindow() {
              Panel bottomPanel = new Panel();
              Panel centerPanel = new Panel();
              setLayout(new BorderLayout());

              //Set up the menu bar.
              MenuBar mb = new MenuBar();
              Menu m = new Menu("Menu");
              m.add(new MenuItem("Menu item 1"));
              m.add(new CheckboxMenuItem("Menu item 2"));
              m.add(new MenuItem("Menu item 3"));
              m.add(new MenuItem("-"));
              m.add(new MenuItem(FILEDIALOGMENUITEM));
              mb.add(m);
              setMenuBar(mb);

              //Add small things at the bottom of the window.
              bottomPanel.add(new TextField("TextField"));
              bottomPanel.add(new Button("Button"));
              bottomPanel.add(new Checkbox("Checkbox"));
              Choice c = new Choice();
              c.addItem("Choice Item 1");
              c.addItem("Choice Item 2");
              c.addItem("Choice Item 3");
      c.addItem("Choice Item 4");
              c.addItem("Choice Item 5");
              c.addItem("Choice Item 6");
              c.addItem("Choice Item 7");
              c.addItem("Choice Item 8");
              c.addItem("Choice Item 9");
              c.addItem("Choice Item 10");
              c.addItem("Choice Item 11");
              c.addItem("Choice Item 12");
              c.addItem("Choice Item 13");
              c.addItem("Choice Item 14");
              c.addItem("Choice Item 15");
              c.addItem("Choice Item 16");
              c.addItem("Choice Item 17");
              c.addItem("Choice Item 18");
              c.addItem("Choice Item 19");
              c.addItem("Choice Item 20");
              c.addItem("Choice Item 21");
              c.addItem("Choice Item 22"); // if I commented it out, the application will run

              bottomPanel.add(c);
              add("South", bottomPanel);

              //Add big things to the center area of the window.
              centerPanel.setLayout(new GridLayout(1,2));
              //Put a canvas in the left column.
              centerPanel.add(new MyCanvas());
              //Put a label and a text area in the right column.
              Panel p = new Panel();
              p.setLayout(new BorderLayout());
              p.add("North", new Label("Label", Label.CENTER));
              p.add("Center", new TextArea("TextArea", 5, 20));
              centerPanel.add(p);
              add("Center", centerPanel);

              //Put a list on the right side of the window.
              List l = new List(3, false);
              for (int i = 1; i <= 10; i++) {
                  l.addItem("List item " + i);
              }
              add("East", l);
          }

          public boolean action(Event event, Object arg) {
              //The only action event we pay attention to is when the
              //user requests we bring up a FileDialog.
              if (event.target instanceof MenuItem) {
                  if (((String)arg).equals(FILEDIALOGMENUITEM)) {
                      FileDialog fd = new FileDialog(this, "FileDialog");
                      fd.show();
                  }
              }
              return true;
          }

          public boolean handleEvent(Event event) {
              //If we're running as an application, closing the window
              //should quit the application.
              if (event.id == Event.WINDOW_DESTROY) {
                  if (inAnApplet) {
                      dispose();
                  } else {
                      System.exit(0);
                  }
              }
              return super.handleEvent(event);
          }

          public static void main(String args[]) {
              GUIWindow window = new GUIWindow();
              window.inAnApplet = false;

              window.setTitle("The AWT Components");
              window.pack();
              window.show();
          }

      }

      //We can't just instantiate Canvas, since its default implementation
      //gives us nothing interesting to look at or do. So here's a Canvas
      //subclass that draws something slightly interesting.
      class MyCanvas extends Canvas {

          public void paint(Graphics g) {
              int w = size().width;
              int h = size().height;
              g.drawRect(0, 0, w - 1, h - 1);
              g.drawString("Canvas", (w - g.getFontMetrics().stringWidth("Canvas"))/2,
                            10);

              g.setFont(new Font("Helvetica", Font.PLAIN, 8));
              g.drawLine(10,10, 100,100);
              g.fillRect(9,9,3,3);
              g.drawString("(10,10)", 13, 10);
              g.fillRect(49,49,3,3);
              g.drawString("(50,50)", 53, 50);
              g.fillRect(99,99,3,3);
              g.drawString("(100,100)", 103, 100);
          }

          //If we don't specify this, the canvas might not show up at all
          //(depending on the layout manager).
          public Dimension minimumSize() {
              return new Dimension(150,130);
          }

          //If we don't specify this, the canvas might not show up at all
          //(depending on the layout manager).
          public Dimension preferredSize() {
              return minimumSize();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              amfowler Anne Fowler (Inactive)
              kasmithsunw Kevin Smith (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: