1 /*
   2  * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.*;
  25 import java.awt.event.*;
  26 
  27 /*
  28  * @author Aruna Samji
  29  */
  30 
  31 public class GUIMerlinFocus extends Frame {
  32     //GUI for KeyboardFocusManagerEvent
  33     Button button;
  34     List list;
  35 
  36     volatile boolean buttonFocusGained, listFocusGained, listFocusLost,
  37             buttonFocusLost, currentkeyboardFocusManager, buttonClicked,
  38             KeyPressed;
  39 
  40     String buttonClickedStr;
  41 
  42     CustomDefaultKeyBoardFocusManager1 cdk;
  43 
  44     //GUI for WindowFocusEvents
  45     Frame frame1;
  46     Dialog dialog1;
  47 
  48     Frame frame2;
  49     Dialog dialog2;
  50 
  51     Frame frame3;
  52     TextField textfield;
  53     Button button1;
  54     TextArea textarea;
  55     Panel rootPanel;
  56 
  57     volatile  boolean frame1Activated, frame2Deactivated,
  58             dialog1Activated, dialog2Deactivated,
  59             button1FocusGained, textareaFocusGained, textfieldFocusLost;
  60 
  61     //GUI for OppositeComponentTest
  62     Frame frame4;
  63     Button button2;
  64     List list2;
  65     TextField textfield2;
  66 
  67     Component focusLostComp;
  68     Component focusGainedComp;
  69 
  70     //GUI for FocusTraversalPolicyTest
  71     Frame testFrame;
  72     Button button5;
  73     List list5;
  74     Panel rootPanel1;
  75     Button button6;
  76     Choice choice5;
  77     TextField textfield5;
  78     Checkbox checkbox5;
  79     Component focusLost5;
  80     Component focusGained5;
  81 
  82     Frame testFrame1;
  83     Button button7;
  84     List list6;
  85     Panel rootPanel2;
  86 
  87     FocusTraversalPolicy cp;
  88 
  89     Frame frame5;
  90     Panel firstpanel;
  91     Panel secondpanel;
  92     Button firstbutton;
  93     Button secondbutton;
  94     Choice firstchoice;
  95     Choice secondchoice;
  96     TextField firsttextfield;
  97     TextField secondtextfield;
  98 
  99     Component complost;
 100     Component compgain;
 101 
 102     DefaultKeyboardFocusManager manager;
 103 
 104     //GUI for ProgrammaticTraversalTest
 105     Frame testFrame2;
 106     Button button8;
 107     List list8;
 108     Panel rootPanel8;
 109     Button button9;
 110     Choice choice8;
 111     TextField textfield8;
 112     Checkbox checkbox8;
 113     Component focusLost2;
 114     Component focusGained2;
 115 
 116     KeyboardFocusManager manager2;
 117 
 118     //GUI for RequestFocusOwnerTest
 119     Frame testframe3;
 120     TextField textfield14;
 121     Button button14;
 122     TextArea textarea14;
 123     Checkbox checkbox14;
 124 
 125     //GUI for GlobalFocusOwnerTest
 126     Frame testframe4;
 127     TextField textfield15;
 128 
 129     volatile boolean tempfocus,
 130             keypressed15, keyreleased15,
 131             button1flag, focusgain;
 132 
 133     DefaultKeyboardFocusManager de;
 134 
 135     public void setBooleans() {
 136 
 137         buttonFocusGained = false;
 138         listFocusGained = false;
 139         listFocusLost = false;
 140         buttonFocusLost = false;
 141         currentkeyboardFocusManager = false;
 142         buttonClicked = false;
 143         KeyPressed = false;
 144 
 145         frame1Activated = false;
 146         frame2Deactivated = false;
 147         dialog1Activated = false;
 148         dialog2Deactivated = false;
 149 
 150         button1FocusGained = false;
 151         textareaFocusGained = false;
 152         textfieldFocusLost = false;
 153 
 154         keypressed15 = false;
 155         keyreleased15 = false;
 156         button1flag = false;
 157         focusgain = false ;
 158     }
 159 
 160     public void framesSetLocationAndSize() {
 161         frame1.setSize(500, 100);
 162         frame1.setLocation(100, 100);
 163         frame2.setSize(500, 100);
 164         frame2.setLocation(100, 200);
 165     }
 166 
 167     public void dialogsSetLocationAndSize() {
 168         dialog1.setSize(500, 100);
 169         dialog1.setLocation(100, 300);
 170         dialog2.setSize(500, 100);
 171         dialog2.setLocation(100, 400);
 172     }
 173 
 174     public GUIMerlinFocus() {
 175         setBooleans();
 176         this.setSize(500, 270);
 177         this.setLayout(new FlowLayout());
 178         this.setBackground(Color.blue);
 179         cdk = new CustomDefaultKeyBoardFocusManager1(this);
 180         button = new Button("Button");
 181 
 182         list = new java.awt.List();
 183         list.add("one");
 184         list.add("two");
 185 
 186         button.addFocusListener(new FocusListener() {
 187             public void focusGained(FocusEvent fe) { buttonFocusGained = true; }
 188             public void focusLost(FocusEvent fe) { buttonFocusLost = true; }
 189         });
 190 
 191         list.addKeyListener(new KeyAdapter() {
 192             public void keyPressed(KeyEvent ke) { KeyPressed = true; }
 193         });
 194 
 195         list.addFocusListener(new FocusListener() {
 196             public void focusGained(FocusEvent fe) { listFocusGained = true; }
 197             public void focusLost(FocusEvent fe) { listFocusLost = true; }
 198         });
 199 
 200         button.addActionListener(e -> {
 201             if (e.getSource() == button) {
 202                 buttonClickedStr = "AWTEventDispatcher "
 203                         + "dispatches the event by itself:"
 204                         + "After ButtonClick";
 205                 buttonClicked = true;
 206             }
 207         });
 208 
 209         this.add(button);
 210         this.add(list);
 211         //End of GUI for KeyboardFocusManagerEvent
 212 
 213         //GUI for WindowFocusEvents
 214         frame1 = new Frame("Frame 1");
 215         dialog1 = new Dialog(frame1, "Dialog 1");
 216 
 217         frame2 = new Frame("Frame 2");
 218         dialog2 = new Dialog(frame2, "Dialog 2");
 219 
 220         frame1.setBackground(Color.red);
 221         frame1.addWindowListener(new WindowAdapter() {
 222             public void windowActivated(WindowEvent we) {
 223                 if (we.getSource() == frame1) frame1Activated = true;
 224             }
 225         });
 226 
 227         frame2.setBackground(Color.blue);
 228         frame2.addWindowListener(new WindowAdapter() {
 229             public void windowDeactivated(WindowEvent we) {
 230                 if (we.getSource() == frame2) frame2Deactivated = true;
 231             }
 232         });
 233 
 234         dialog1.setBackground(Color.green);
 235         dialog1.addWindowListener(new WindowAdapter() {
 236             public void windowActivated(WindowEvent we) {
 237                 if (we.getSource() == dialog1) dialog1Activated = true;
 238             }
 239         });
 240 
 241         dialog2.setBackground(Color.yellow);
 242         dialog2.addWindowListener(new WindowAdapter() {
 243             public void windowDeactivated(WindowEvent we) {
 244                 if (we.getSource() == dialog2) dialog2Deactivated = true;
 245             }
 246         });
 247 
 248         frame3 = new Frame("WindowFocusEvents");
 249         frame3.setLayout(new FlowLayout());
 250         frame3.setBackground(Color.red);
 251 
 252         rootPanel = new Panel();
 253         rootPanel.setBackground(Color.yellow);
 254 
 255         textfield = new TextField("TextField");
 256         textfield.addFocusListener(new FocusAdapter() {
 257             public void focusLost(FocusEvent fe) {
 258                 textfieldFocusLost = true;
 259             }
 260         });
 261 
 262         button1 = new Button("Button");
 263         button1.setEnabled(false);
 264         button1.addFocusListener(new FocusAdapter() {
 265             public void focusGained(FocusEvent fe) {
 266                 button1FocusGained = true;
 267             }
 268         });
 269 
 270         textarea = new TextArea("TextArea", 3, 10);
 271         textarea.addFocusListener(new FocusAdapter() {
 272             public void focusGained(FocusEvent fe) {
 273                 textareaFocusGained = true;
 274             }
 275         });
 276 
 277         rootPanel.add(textfield, 0);
 278         rootPanel.add(button1, 1);
 279         rootPanel.add(textarea, 2);
 280         rootPanel.setBounds(20, 20, 350, 200);
 281 
 282         frame3.setBounds(0, 0, 500, 270);
 283         frame3.add(rootPanel);
 284         //End of GUI for WindowFocusEvents
 285 
 286         //GUI for OppositeComponentTest
 287         //Component
 288         frame4 = new Frame("OppositeComponentTest");
 289         button2 = new Button("Button");
 290         button2.addFocusListener(new FocusListener() {
 291             public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); }
 292             public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); }
 293         });
 294 
 295         textfield2 = new TextField("TextField");
 296         textfield2.addFocusListener(new FocusListener() {
 297             public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); }
 298             public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); }
 299         });
 300 
 301         list2 = new java.awt.List(2);
 302         list2.add("Item 1");
 303         list2.add("Item 2");
 304         list2.add("Item 3");
 305         list2.addFocusListener(new FocusListener() {
 306             public void focusLost(FocusEvent fe) { focusGainedComp = fe.getOppositeComponent(); }
 307             public void focusGained(FocusEvent fe) { focusLostComp = fe.getOppositeComponent(); }
 308         });
 309 
 310         frame4.setLayout(new FlowLayout());
 311         frame4.add(button2);
 312         frame4.add(textfield2);
 313         frame4.add(list2);
 314         frame4.setBackground(Color.green);
 315         frame4.setSize(500, 255);
 316         //End of GUI for OppositeComponentTest
 317 
 318         //GUI for FocusTraversalPolicyTest
 319         testFrame = new Frame("FocusTraversalPolicy");
 320         testFrame.setLayout(new FlowLayout());
 321         testFrame.setBackground(Color.blue);
 322 
 323         testFrame1 = new Frame("FocusTraversalPolicy");
 324         testFrame1.setLayout(new FlowLayout());
 325         testFrame1.setBackground(Color.blue);
 326         testFrame1.setSize(500, 270);
 327 
 328         rootPanel1 = new Panel();
 329         rootPanel1.setBackground(Color.yellow);
 330 
 331         rootPanel2 = new Panel();
 332         rootPanel2.setBackground(Color.yellow);
 333 
 334         button5 = new Button("Button1");
 335         button5.addFocusListener(new FocusListener() {
 336             public void focusLost(FocusEvent fe) {
 337                 focusLost5 = fe.getComponent();
 338                 focusLost5 = fe.getComponent();
 339             }
 340 
 341             public void focusGained(FocusEvent fe) {
 342                 focusGained5 = fe.getComponent();
 343                 focusGained5 = fe.getComponent();
 344             }
 345         });
 346 
 347         button7 = new Button("Button3");
 348         button7.addFocusListener(new FocusListener() {
 349             public void focusLost(FocusEvent fe) {
 350                 focusLost5 = fe.getComponent();
 351                 focusLost5 = fe.getComponent();
 352             }
 353 
 354             public void focusGained(FocusEvent fe) {
 355                 focusGained5 = fe.getComponent();
 356                 focusGained5 = fe.getComponent();
 357             }
 358         });
 359 
 360         list5 = new List(2);
 361         list5.add("Item 1");
 362         list5.add("Item 2");
 363         list5.add("Item 3");
 364         list5.add("Item 4");
 365         list5.addFocusListener(new FocusListener() {
 366             public void focusLost(FocusEvent fe) {
 367                 focusLost5 = fe.getComponent();
 368                 focusLost5 = fe.getComponent();
 369             }
 370 
 371             public void focusGained(FocusEvent fe) {
 372                 focusGained5 = fe.getComponent();
 373                 focusGained5 = fe.getComponent();
 374             }
 375         });
 376 
 377         list6 = new List(2);
 378         list6.add("Item 1");
 379         list6.add("Item 2");
 380         list6.add("Item 3");
 381         list6.add("Item 4");
 382         list6.addFocusListener(new FocusListener() {
 383             public void focusLost(FocusEvent fe) {
 384                 focusLost5 = fe.getComponent();
 385                 focusLost5 = fe.getComponent();
 386             }
 387 
 388             public void focusGained(FocusEvent fe) {
 389                 focusGained5 = fe.getComponent();
 390                 focusGained5 = fe.getComponent();
 391             }
 392         });
 393 
 394         button6 = new Button("Button2");
 395         button6.addFocusListener(new FocusListener() {
 396             public void focusLost(FocusEvent fe) {
 397                 focusLost5 = fe.getComponent();
 398                 focusLost5 = fe.getComponent();
 399             }
 400 
 401             public void focusGained(FocusEvent fe) {
 402                 focusGained5 = fe.getComponent();
 403                 focusGained5 = fe.getComponent();
 404             }
 405         });
 406 
 407         choice5 = new Choice();
 408         choice5.add("item 1");
 409         choice5.add("item 2");
 410         choice5.add("item 3");
 411         choice5.add("item 4");
 412         choice5.addFocusListener(new FocusListener() {
 413             public void focusLost(FocusEvent fe) {
 414                 focusLost5 = fe.getComponent();
 415                 focusLost5 = fe.getComponent();
 416             }
 417 
 418             public void focusGained(FocusEvent fe) {
 419                 focusGained5 = fe.getComponent();
 420                 focusGained5 = fe.getComponent();
 421             }
 422         });
 423 
 424         textfield5 = new TextField("TextField");
 425         textfield5.addFocusListener(new FocusListener() {
 426             public void focusLost(FocusEvent fe) {
 427                 focusLost5 = fe.getComponent();
 428                 focusLost5 = fe.getComponent();
 429             }
 430 
 431             public void focusGained(FocusEvent fe) {
 432                 focusGained5 = fe.getComponent();
 433                 focusGained5 = fe.getComponent();
 434             }
 435         });
 436 
 437         checkbox5 = new Checkbox("CheckBox");
 438         checkbox5.addFocusListener(new FocusListener() {
 439             public void focusLost(FocusEvent fe) {
 440                 focusLost5 = fe.getComponent();
 441                 focusLost5 = fe.getComponent();
 442             }
 443 
 444             public void focusGained(FocusEvent fe) {
 445                 focusGained5 = fe.getComponent();
 446                 focusGained5 = fe.getComponent();
 447             }
 448         });
 449 
 450         testFrame.add(button5);
 451         testFrame.add(list5);
 452         testFrame.add(button6);
 453         testFrame.add(choice5);
 454         testFrame.add(checkbox5);
 455         testFrame.add(textfield5, 4);
 456 
 457         rootPanel1.add(button7);
 458         rootPanel1.add(list6);
 459 
 460         cp = new CustomPolicy(button5, list5, button6, choice5, textfield5, checkbox5);
 461 
 462         testFrame.setFocusTraversalPolicy(cp);
 463 
 464         testFrame1.add(rootPanel1);
 465 
 466         testFrame.setSize(500, 270);
 467         //Forward and backward traversal
 468         manager = new DefaultKeyboardFocusManager();
 469         frame5 = new Frame("FocusTraversalPolicy");
 470         frame5.setBackground(Color.yellow);
 471 
 472         firstpanel = new Panel();
 473         firstpanel.setBackground(Color.red);
 474 
 475         secondpanel = new Panel();
 476         secondpanel.setBackground(Color.green);
 477 
 478         firstbutton = new Button("First");
 479         firstbutton.addFocusListener(new FocusListener() {
 480             public void focusLost(FocusEvent fe) {
 481                 complost = (Component) fe.getSource();
 482             }
 483 
 484             public void focusGained(FocusEvent fe) {
 485                 compgain = null;
 486                 compgain = (Component) fe.getSource();
 487             }
 488         });
 489 
 490         secondbutton = new Button("Second");
 491         secondbutton.addFocusListener(new FocusListener() {
 492             public void focusLost(FocusEvent fe) {
 493                 complost = (Component) fe.getSource();
 494             }
 495 
 496             public void focusGained(FocusEvent fe) {
 497                 compgain = null;
 498                 compgain = (Component) fe.getSource();
 499             }
 500         });
 501 
 502         firstchoice = new Choice();
 503         firstchoice.add("First");
 504         firstchoice.add("First");
 505         firstchoice.add("First");
 506         firstchoice.addFocusListener(new FocusListener() {
 507             public void focusLost(FocusEvent fe) {
 508                 complost = (Component) fe.getSource();
 509             }
 510 
 511             public void focusGained(FocusEvent fe) {
 512                 compgain = null;
 513                 compgain = (Component) fe.getSource();
 514             }
 515         });
 516 
 517         secondchoice = new Choice();
 518         secondchoice.add("Second");
 519         secondchoice.add("Second");
 520         secondchoice.add("Second");
 521         secondchoice.addFocusListener(new FocusListener() {
 522             public void focusLost(FocusEvent fe) {
 523                 complost = (Component) fe.getSource();
 524             }
 525 
 526             public void focusGained(FocusEvent fe) {
 527                 compgain = null;
 528                 compgain = (Component) fe.getSource();
 529             }
 530         });
 531 
 532         firsttextfield = new TextField("First");
 533         firsttextfield.addFocusListener(new FocusListener() {
 534             public void focusLost(FocusEvent fe) {
 535                 complost = (Component) fe.getSource();
 536             }
 537 
 538             public void focusGained(FocusEvent fe) {
 539                 compgain = null;
 540                 compgain = (Component) fe.getSource();
 541             }
 542         });
 543 
 544         secondtextfield = new TextField("Second");
 545         secondtextfield.addFocusListener(new FocusListener() {
 546             public void focusLost(FocusEvent fe) {
 547                 complost = (Component) fe.getSource();
 548             }
 549 
 550             public void focusGained(FocusEvent fe) {
 551                 compgain = null;
 552                 compgain = (Component) fe.getSource();
 553             }
 554         });
 555 
 556         firstpanel.add(firstbutton);
 557         firstpanel.add(firstchoice);
 558         firstpanel.add(firsttextfield);
 559         firstpanel.addFocusListener(new FocusListener() {
 560             public void focusLost(FocusEvent fe) {
 561                 complost = (Component) fe.getSource();
 562             }
 563 
 564             public void focusGained(FocusEvent fe) {
 565                 compgain = null;
 566                 compgain = (Component) fe.getSource();
 567             }
 568         });
 569 
 570         secondpanel.add(secondbutton);
 571         secondpanel.add(secondchoice);
 572         secondpanel.add(secondtextfield);
 573         secondpanel.setFocusCycleRoot(true);
 574         secondpanel.addFocusListener(new FocusListener() {
 575             public void focusLost(FocusEvent fe) {
 576                 complost = (Component) fe.getSource();
 577             }
 578 
 579             public void focusGained(FocusEvent fe) {
 580                 compgain = null;
 581                 compgain = (Component) fe.getSource();
 582             }
 583         });
 584 
 585         frame5.addFocusListener(new FocusListener() {
 586             public void focusLost(FocusEvent fe) {
 587                 complost = (Component) fe.getSource();
 588             }
 589 
 590             public void focusGained(FocusEvent fe) {
 591                 compgain = null;
 592                 compgain = (Component) fe.getSource();
 593             }
 594         });
 595         frame5.add(firstpanel, BorderLayout.NORTH);
 596         frame5.add(secondpanel, BorderLayout.SOUTH);
 597 
 598         //End of GUI for FocusTraversalPolicyTest
 599 
 600         //GUI for ProgrammaticTraversalTest
 601         testFrame2 = new Frame("ProgrammaticTraversal");
 602         testFrame2.setLayout(new FlowLayout());
 603 
 604         rootPanel8 = new Panel();
 605         rootPanel8.setLayout(new FlowLayout());
 606         rootPanel8.setBackground(Color.yellow);
 607 
 608         button8 = new Button("Button1");
 609         button8.addFocusListener(new FocusListener() {
 610             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 611             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 612         });
 613 
 614         list8 = new List(2);
 615         list8.add("Item 1");
 616         list8.add("Item 2");
 617         list8.add("Item 3");
 618         list8.add("Item 4");
 619         list8.addFocusListener(new FocusListener() {
 620             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 621             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 622         });
 623 
 624         button9 = new Button("Button2");
 625         button9.addFocusListener(new FocusListener() {
 626             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 627             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 628         });
 629 
 630         choice8 = new Choice();
 631         choice8.add("Item 1");
 632         choice8.add("Item 2");
 633         choice8.add("Item 3");
 634         choice8.add("Item 4");
 635         choice8.addFocusListener(new FocusListener() {
 636             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 637             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 638         });
 639 
 640         textfield8 = new TextField("Text Field");
 641         textfield8.addFocusListener(new FocusListener() {
 642             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 643             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 644         });
 645 
 646         checkbox8 = new Checkbox("Check Box");
 647         checkbox8.addFocusListener(new FocusListener() {
 648             public void focusLost(FocusEvent fe) { focusLost2 = fe.getComponent(); }
 649             public void focusGained(FocusEvent fe) { focusGained2 = fe.getComponent(); }
 650         });
 651 
 652         rootPanel8.add(button8);
 653         rootPanel8.add(list8);
 654         rootPanel8.add(button9);
 655         rootPanel8.add(choice8);
 656         rootPanel8.add(textfield8, 4);
 657         rootPanel8.add(checkbox8);
 658 
 659         testFrame2.add(rootPanel8);
 660         testFrame2.setBackground(Color.red);
 661         testFrame2.pack();
 662         testFrame2.setSize(500, 270);
 663 
 664         manager2 = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 665 
 666         //End of GUI for ProgrammaticTraversalTest
 667 
 668         //GUI for RequestFocusOwnerTest
 669         testframe3 = new Frame("RequestFocusOwner");
 670         testframe3.setLayout(new FlowLayout());
 671         testframe3.setBackground(Color.yellow);
 672 
 673         textfield14 = new TextField("TextField");
 674         textarea14 = new TextArea("TextArea", 3, 10);
 675         checkbox14 = new Checkbox("Click Me");
 676         button14 = new Button("Press me");
 677 
 678         testframe3.add(button14);
 679         testframe3.add(checkbox14);
 680         testframe3.add(textarea14);
 681         testframe3.add(textfield14);
 682         testframe3.setSize(500, 270);
 683 
 684         //End of GUI for RequestFocusOwnerTest
 685 
 686         //GUI for GlobalFocusOwnerTest
 687         de = new DefaultKeyboardFocusManager();
 688         testframe4 = new Frame("testFrame");
 689         testframe4.setLayout(new FlowLayout());
 690         testframe4.setBackground(Color.green);
 691 
 692         textfield15 = new TextField("TextField");
 693         textfield15.addFocusListener(new FocusListener() {
 694             public void focusLost(FocusEvent fe) {
 695                 tempfocus = fe.isTemporary();
 696             }
 697 
 698             public void focusGained(FocusEvent fe) {
 699                 if (fe.getSource().equals(textfield15))
 700                     focusgain = true;
 701             }
 702         });
 703 
 704         textfield15.addKeyListener(new KeyListener() {
 705             public void keyPressed(KeyEvent ke) { keypressed15 = true; }
 706             public void keyReleased(KeyEvent ke) { keyreleased15 = true; }
 707             public void keyTyped(KeyEvent ke) { }
 708         });
 709 
 710         testframe4.add(textfield15);
 711         testframe4.setSize(500, 270);
 712     }
 713 
 714     class CustomPolicy extends FocusTraversalPolicy {
 715         Button button5;
 716         List list5;
 717         Button button6;
 718         Choice choice5;
 719         TextField textfield5;
 720         Checkbox checkbox5;
 721 
 722         public CustomPolicy(Button button5, List list5, Button button6,
 723                             Choice choice5, TextField textfield5, Checkbox checkbox5) {
 724             this.button5 = button5;
 725             this.list5 = list5;
 726             this.button6 = button6;
 727             this.choice5 = choice5;
 728             this.textfield5 = textfield5;
 729             this.checkbox5 = checkbox5;
 730         }
 731 
 732         public Component getComponentAfter(Container fr,Component comp) {
 733             if (comp == button5)
 734                 return choice5;
 735             else if (comp == list5)
 736                 return textfield5;
 737             else if (comp == button6)
 738                 return button5;
 739             else if (comp == choice5)
 740                 return list5;
 741             else
 742                 return button6;
 743         }
 744 
 745         public Component getComponentBefore(Container fr,Component comp) {
 746             if (comp == button5)
 747                 return button6;
 748             else if (comp == list5)
 749                 return choice5;
 750             else if (comp == button6)
 751                 return textfield5;
 752             else if (comp == choice5)
 753                 return button5;
 754             else
 755                 return list5;
 756         }
 757 
 758         public Component getDefaultComponent(Container fr) {
 759             return choice5;
 760         }
 761 
 762         public Component getFirstComponent(Container fr) {
 763             return choice5;
 764         }
 765 
 766         public Component getLastComponent(Container fr) {
 767             return checkbox5;
 768         }
 769     }
 770 
 771     class CustomDefaultKeyBoardFocusManager1 extends DefaultKeyboardFocusManager {
 772 
 773         public Component comp;
 774         boolean cdkdispatchKeyEvent = false;
 775         boolean cdkprocessKeyEvent = false;
 776 
 777         public CustomDefaultKeyBoardFocusManager1(Component ce) {
 778             this.comp = ce;
 779         }
 780 
 781         public boolean dispatchKeyEvent(KeyEvent e) {
 782             super.dispatchKeyEvent(e);
 783             cdkdispatchKeyEvent=true;
 784             return false;
 785         }
 786 
 787         public boolean dispatchEvent(java.awt.AWTEvent ae) {
 788             super.dispatchEvent(ae);
 789             return false;
 790         }
 791 
 792         public void processKeyEvent(Component comp,KeyEvent ke) {
 793             cdkprocessKeyEvent = true;
 794             super.processKeyEvent(comp,ke);
 795         }
 796 
 797         protected Container getGlobalCurrentFocusCycleRoot() {
 798             return super.getGlobalCurrentFocusCycleRoot();
 799         }
 800 
 801         protected Component getGlobalFocusOwner() throws SecurityException {
 802             return super.getGlobalFocusOwner();
 803         }
 804 
 805         protected Window getGlobalFocusedWindow() throws SecurityException {
 806             return super.getGlobalFocusedWindow();
 807         }
 808     }
 809 }
 810 
 811