Path: blob/master/test/jdk/java/awt/Dialog/ChildProperties/ChildDialogProperties.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 805757427* @summary Verify that child Dialog does not inherit parent's Properties28* @run main ChildDialogProperties29*/3031import java.awt.Color;32import java.awt.Dialog;33import java.awt.Font;34import java.awt.Frame;35import java.awt.Label;3637public class ChildDialogProperties {3839private Dialog parentDialog;40private Dialog dialogChild;41private Frame parentFrame;42private Dialog frameChildDialog;43private Label parentLabel;44private Font parentFont;45private Label childLabel;4647private static final int WIDTH = 200;48private static final int HEIGHT = 200;4950public void testChildPropertiesWithDialogAsParent() {5152parentDialog = new Dialog((Dialog) null, "parent Dialog");53parentDialog.setSize(WIDTH, HEIGHT);54parentDialog.setLocation(100, 100);55parentDialog.setBackground(Color.RED);5657parentLabel = new Label("ParentForegroundAndFont");58parentFont = new Font("Courier New", Font.ITALIC, 15);59parentDialog.setForeground(Color.BLUE);60parentDialog.setFont(parentFont);6162parentDialog.add(parentLabel);63parentDialog.setVisible(true);6465dialogChild = new Dialog(parentDialog, "Dialog's child");66dialogChild.setSize(WIDTH, HEIGHT);67dialogChild.setLocation(WIDTH + 200, 100);68childLabel = new Label("ChildForegroundAndFont");69dialogChild.add(childLabel);7071dialogChild.setVisible(true);7273if (parentDialog.getBackground() == dialogChild.getBackground()) {74dispose();75throw new RuntimeException("Child Dialog Should NOT Inherit "76+ "Parent Dialog's Background Color");77}7879if (parentDialog.getForeground() == dialogChild.getForeground()) {80dispose();81throw new RuntimeException("Child Dialog Should NOT Inherit "82+ "Parent Dialog's Foreground Color");83}8485if (parentDialog.getFont() == dialogChild.getFont()) {86dispose();87throw new RuntimeException("Child Dialog Should NOT Inherit "88+ "Parent Dialog's Font Style/Color");89}9091}9293public void testChildPropertiesWithFrameAsParent() {9495parentFrame = new Frame("parent Frame");96parentFrame.setSize(WIDTH, HEIGHT);97parentFrame.setLocation(100, 400);98parentFrame.setBackground(Color.BLUE);99parentLabel = new Label("ParentForegroundAndFont");100parentFont = new Font("Courier New", Font.ITALIC, 15);101parentFrame.setForeground(Color.RED);102parentFrame.setFont(parentFont);103parentFrame.add(parentLabel);104parentFrame.setVisible(true);105106frameChildDialog = new Dialog(parentFrame, "Frame's child");107frameChildDialog.setSize(WIDTH, HEIGHT);108frameChildDialog.setLocation(WIDTH + 200, 400);109childLabel = new Label("ChildForegroundAndFont");110frameChildDialog.add(childLabel);111frameChildDialog.setVisible(true);112113if (parentFrame.getBackground() == frameChildDialog.getBackground()) {114dispose();115throw new RuntimeException("Child Dialog Should NOT Inherit "116+ "Parent Frame's Background Color");117}118119if (parentFrame.getForeground() == frameChildDialog.getForeground()) {120dispose();121throw new RuntimeException("Child Dialog Should NOT Inherit "122+ "Parent Frame's Foreground Color");123}124125if (parentFrame.getFont() == frameChildDialog.getFont()) {126dispose();127throw new RuntimeException("Child Dialog Should NOT Inherit "128+ "Parent Frame's Font Style/Color");129}130}131132private void dispose() {133134if (parentDialog != null) {135parentDialog.dispose();136}137if (parentFrame != null) {138parentFrame.dispose();139}140}141142public static void main(String[] args) throws Exception {143144ChildDialogProperties obj = new ChildDialogProperties();145// TestCase1: When Parent is Dialog, Child is Dialog146obj.testChildPropertiesWithDialogAsParent();147// TestCase2: When Parent is Frame, chis is Dialog148obj.testChildPropertiesWithFrameAsParent();149obj.dispose();150}151152}153154155