1 /* 2 * Copyright (c) 2011, 2013, 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 /* 25 * @test 26 * @summary Quicklook test ButtonBasics -- Test some basic functionality of Buttons 27 * @summary com.apple.junit.java.awt.button 28 */ 29 30 import java.awt.Button; 31 import java.awt.Frame; 32 33 public class ButtonBasics extends Frame { 34 Button button1; 35 36 public static void main (String[] args) throws Exception { 37 ButtonBasics ql = null; 38 try { 39 ql = new ButtonBasics(); 40 ql.quickLook(); 41 ql.manipulate(); 42 if (ql.result() == false) { 43 throw new Exception("Couldn't set the label of the button."); 44 } 45 } 46 finally { 47 ql.dispose(); 48 } 49 } 50 51 // constructor 52 public ButtonBasics() { 53 super("Button Example"); 54 } 55 56 void quickLook() throws Exception { 57 button1 = new Button("FAILED"); 58 add("Center",button1); 59 pack(); 60 setVisible(true); 61 } 62 63 void manipulate() throws Exception { 64 String a = "PASSED"; 65 int i = 0; 66 while (i++ < a.length()) { 67 button1.setLabel(a.substring(0,i)); 68 Thread.sleep(200); 69 } 70 } 71 72 public boolean result() { 73 if (button1.getLabel().equals("PASSED")) { 74 return true; 75 } 76 else { 77 return false; 78 } 79 } 80 } 81 82 83 84