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