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

code for fixing 4125937 causes regression

XMLWordPrintable

    • 1.2beta4
    • generic
    • windows_nt
    • Not verified

      The code used to fix bug 4125937 in awt_Frame.cpp does not solve
      the problem for lw component and causes regression for heavy weight
      component.

      You can use the following example to test for heavy weight
      component(Canvas) and replace the Canvas to Component to
      test for lw component.

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;

      public class lwfocus extends Panel
      {

        PassiveClient pc1 = new PassiveClient();
        PassiveClient pc2 = new PassiveClient();

        public lwfocus(String title) {
          super();
          setLayout(new GridLayout(2, 1, 10, 10));
          add(pc1);
          add(pc2);
        }

        public void start() {
        }
          
        public void stop() {
        }

        public static void main(String argv[]) {
          Frame frame = new Frame("lightweight focus");
          lwfocus test = new lwfocus("hello");

          test.setSize(400,400);
          test.start();

          frame.add("Center", test);
          frame.setSize(400, 400);

          WindowListener listener = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
      e.getWindow().dispose();
      System.exit(0);
            };
          };
          frame.addWindowListener(listener);
          frame.validate();
          frame.setVisible(true);
        }

      }
      class PassiveClient extends Canvas implements FocusListener {
          boolean haveFocus = false;
          PassiveClient() {
              super();
      setSize(400, 100);
      setBackground(Color.cyan);
      setVisible(true);
      setEnabled(true);
      addMouseListener(new MouseFocusListener(this));
      addFocusListener(this);
          }

          public void paint(Graphics g) {
      g.setColor(getBackground());
      Dimension size = getSize();
      g.fillRect(0, 0, size.width, size.height);
      if (haveFocus) {
      g.setColor(Color.black);
      g.drawRect(0, 0, size.width - 1, size.height - 1);
      g.drawRect(1, 1, size.width - 3, size.height - 3);
      }
      g.setColor(getForeground());
          }
          
          public void focusGained(FocusEvent event) {
              haveFocus = true;
      paint(getGraphics());
      System.out.println();
      System.out.println("<<<<" + this + "Got focus!! " + event + ">>>>");
      System.out.println();
          }
          
          public void focusLost(FocusEvent event) {
              haveFocus = false;
      paint(getGraphics());
      System.out.println();
      System.out.println("<<<<" + this + "Lost focus!! " + event + ">>>>");
      System.out.println();
          }
      }
      class MouseFocusListener extends MouseAdapter {

          private Component target;
          
          MouseFocusListener(Component target) {
              this.target = target;
          }

          public void mouseClicked(MouseEvent e) {
              target.requestFocus();
          }

      }

            son Oleg Sukhodolsky (Inactive)
            sherman Xueming Shen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: