Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/Headless/HeadlessComponent.java
47311 views
/*1* Copyright (c) 2007, 2014, 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*/2223import java.awt.*;24import java.awt.event.*;25import java.util.Locale;2627/*28* @test29* @summary Check that Component methods do not throw unexpected exceptions30* in headless mode31* @run main/othervm -Djava.awt.headless=true HeadlessComponent32*/3334public class HeadlessComponent {35public static void main(String args[]) {36Component comp = new Component(){};37comp.addComponentListener(new ComponentAdapter() {});38comp.addFocusListener(new FocusAdapter(){});39comp.addHierarchyBoundsListener(new HierarchyBoundsAdapter(){});40comp.addHierarchyListener(e -> {});41comp.addInputMethodListener(new InputMethodListener() {42public void inputMethodTextChanged(InputMethodEvent event) {}43public void caretPositionChanged(InputMethodEvent event) {}44});45comp.addKeyListener(new KeyAdapter() {});46comp.addMouseListener(new MouseAdapter() {});47comp.addMouseMotionListener(new MouseMotionAdapter() {});48comp.addMouseWheelListener(e -> {});49comp.addPropertyChangeListener(e -> {});50comp.addNotify();51comp.getName();52comp.setName("goober");53comp.getParent();54comp.getPeer();55comp.getGraphicsConfiguration();56comp.getTreeLock();57comp.getToolkit();58comp.isValid();59comp.isDisplayable();60comp.isVisible();61comp.isShowing();62comp.isEnabled();63comp.setEnabled(false);64comp.setEnabled(true);65comp.enable();66comp.enable(false);67comp.enable(true);68comp.disable();69comp.isDoubleBuffered();70comp.enableInputMethods(false);71comp.enableInputMethods(true);72comp.setVisible(false);73comp.setVisible(true);74comp.show();75comp.show(false);76comp.show(true);77comp.hide();78comp.getForeground();79comp.setForeground(Color.red);80comp.isForegroundSet();81comp.getBackground();82comp.setBackground(Color.red);83comp.isBackgroundSet();84comp.getFont();85for (String font : Toolkit.getDefaultToolkit().getFontList()) {86for (int i = 8; i < 17; i++) {87Font f1 = new Font(font, Font.PLAIN, i);88Font f2 = new Font(font, Font.BOLD, i);89Font f3 = new Font(font, Font.ITALIC, i);90Font f4 = new Font(font, Font.BOLD | Font.ITALIC, i);9192comp.setFont(f1);93comp.getFontMetrics(f1);94comp.setFont(f2);95comp.getFontMetrics(f2);96comp.setFont(f3);97comp.getFontMetrics(f3);98comp.setFont(f4);99comp.getFontMetrics(f4);100}101}102comp.isFontSet();103104boolean exceptions = false;105try {106Container c = new Container();107c.add(comp);108comp.getLocale();109} catch (IllegalComponentStateException ex) {110exceptions = true;111}112if (!exceptions)113throw new RuntimeException("IllegalComponentStateException did not occur when expected");114115for (Locale locale : Locale.getAvailableLocales())116comp.setLocale(locale);117118comp.getColorModel();119comp.getLocation();120121exceptions = false;122try {123comp = new Component(){};124comp.getLocationOnScreen();125} catch (IllegalComponentStateException e) {126exceptions = true;127}128if (!exceptions)129throw new RuntimeException("IllegalComponentStateException did not occur when expected");130131comp.location();132comp.setLocation(1, 2);133comp.move(1, 2);134comp.setLocation(new Point(1, 2));135comp.getSize();136comp.size();137comp.setSize(1, 32);138comp.resize(1, 32);139comp.setSize(new Dimension(1, 32));140comp.resize(new Dimension(1, 32));141comp.getBounds();142comp.bounds();143comp.setBounds(10, 10, 10, 10);144comp.reshape(10, 10, 10, 10);145comp.setBounds(new Rectangle(10, 10, 10, 10));146comp.getX();147comp.getY();148comp.getWidth();149comp.getHeight();150comp.getBounds(new Rectangle(1, 1, 1, 1));151comp.getSize(new Dimension(1, 2));152comp.getLocation(new Point(1, 2));153comp.isOpaque();154comp.isLightweight();155comp.getPreferredSize();156comp.preferredSize();157comp.getMinimumSize();158comp.minimumSize();159comp.getMaximumSize();160comp.getAlignmentX();161comp.getAlignmentY();162comp.doLayout();163comp.layout();164comp.validate();165comp.invalidate();166comp.getGraphics();167Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);168comp.setCursor(c);169comp.getCursor();170comp.isCursorSet();171comp.contains(1, 2);172comp.inside(1, 2);173comp.contains(new Point(1, 2));174comp.getComponentAt(1, 2);175comp.locate(1, 2);176comp.getComponentAt(new Point(1, 2));177comp.isFocusTraversable();178comp.isFocusable();179comp.setFocusable(true);180comp.setFocusable(false);181comp.requestFocus();182comp.requestFocusInWindow();183comp.transferFocus();184comp.getFocusCycleRootAncestor();185comp.isFocusCycleRoot(new Container());186comp.nextFocus();187comp.transferFocusBackward();188comp.transferFocusUpCycle();189comp.hasFocus();190comp.isFocusOwner();191comp.toString();192comp.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);193comp.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);194comp.setComponentOrientation(ComponentOrientation.UNKNOWN);195comp.getComponentOrientation();196comp.getAccessibleContext();197}198}199200201