Path: blob/master/test/jdk/java/awt/FileDialog/FileDialogForPackages/FileDialogForPackages.java
41153 views
/*1* Copyright (c) 2013, 2018, 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*/222324import jdk.test.lib.Platform;25import test.java.awt.regtesthelpers.Sysout;2627import java.applet.Applet;28import java.awt.Button;29import java.awt.FileDialog;30import java.awt.Frame;31import java.awt.GridLayout;32import java.awt.event.ActionEvent;33import java.awt.event.ActionListener;3435public class FileDialogForPackages extends Applet implements ActionListener {36private static final String APPLICATIONS_FOLDER = "/Applications";3738private volatile Button showBtn;39private volatile FileDialog fd;4041@Override42public void init() {43if (!Platform.isOSX()) {44Sysout.createDialogWithInstructions(new String[]{45"Press PASS, this test is for MacOS X only."});46return;47}4849System.setProperty("apple.awt.use-file-dialog-packages", "true");5051setLayout(new GridLayout(1, 1));5253fd = new FileDialog(new Frame(), "Open");54fd.setDirectory(APPLICATIONS_FOLDER);5556showBtn = new Button("Show File Dialog");57showBtn.addActionListener(this);58add(showBtn);59String[] instructions = {60"1) Click on 'Show File Dialog' button. A file dialog will come up.",61"2) Navigate to the Applications folder if not already there",62"3) Check that the application bundles can be selected and can not be navigated",63"4) If it's true then the test passed, otherwise it failed."};64Sysout.createDialogWithInstructions(instructions);65}6667@Override68public void start() {69setSize(200, 200);70show();71}7273@Override74public void actionPerformed(ActionEvent e) {75if (e.getSource() == showBtn) {76fd.setVisible(true);77String output = fd.getFile();78if (output != null) {79Sysout.println(output + " is selected");80}81}82}83}848586