1 /* @test 2 @bug 4103095 3 @summary Test for getBounds() after a Frame resize. 4 @author andrei.dmitriev : area=awt.toplevel 5 @run main/manual GetBoundsResizeTest 6 */ 7 8 import java.applet.Applet; 9 import java.lang.*; 10 import java.awt.*; 11 import java.awt.event.*; 12 13 class Globals { 14 static boolean testPassed=false; 15 static Thread mainThread=null; 16 } 17 18 public class GetBoundsResizeTest extends Applet { 19 20 public static void main(String args[]) throws Exception { 21 GetBoundsResizeTest app = new GetBoundsResizeTest(); 22 app.start(); 23 Globals.mainThread = Thread.currentThread(); 24 try { 25 Thread.sleep(300000); 26 } catch (InterruptedException e) { 27 if (!Globals.testPassed) 28 throw new Exception("GetBoundsResizeTest failed."); 29 } 30 } 31 32 public void start() 33 { 34 String[] message = { 35 "Resize the window using the upper left corner.", 36 "Press the button to print the result of getBounds() to the terminal.", 37 "If getBounds() prints the correct values for the window", 38 "then click Pass, else click Fail." 39 }; 40 new TestDialog(new Frame(), "GetBoundsResizeTest", message).start(); 41 new GetBoundsResizeTester("GetBoundsResizeTester").start(); 42 } 43 } 44 45 //////////////////////////////////////////////////////////////////////// 46 // Test Dialog 47 //////////////////////////////////////////////////////////////////////// 48 49 class TestDialog extends Dialog 50 implements ActionListener { 51 52 static TextArea output; 53 Button passButton; 54 Button failButton; 55 String name; 56 57 public TestDialog(Frame frame, String name, String[] message) 58 { 59 super(frame, name + " Pass/Fail Dialog"); 60 this.name = name; 61 int maxStringLength = 0; 62 for (int i=0; i<message.length; i++) { 63 maxStringLength = Math.max(maxStringLength, message[i].length()); 64 } 65 output = new TextArea(10, maxStringLength); 66 add("North", output); 67 for (int i=0; i<message.length; i++){ 68 output.append(message[i] + "\n"); 69 } 70 Panel buttonPanel = new Panel(); 71 passButton = new Button("Pass"); 72 failButton = new Button("Fail"); 73 passButton.addActionListener(this); 74 failButton.addActionListener(this); 75 buttonPanel.add(passButton); 76 buttonPanel.add(failButton); 77 add("South", buttonPanel); 78 pack(); 79 } 80 81 public void start() 82 { 83 show(); 84 } 85 86 public void actionPerformed(ActionEvent event) 87 { 88 if ( event.getSource() == passButton ) { 89 Globals.testPassed = true; 90 System.err.println(name + " Passed."); 91 } 92 else if ( event.getSource() == failButton ) { 93 Globals.testPassed = false; 94 System.err.println(name + " Failed."); 95 } 96 this.dispose(); 97 if (Globals.mainThread != null) 98 Globals.mainThread.interrupt(); 99 } 100 } 101 102 103 //////////////////////////////////////////////////////////////////////// 104 // Test Class 105 //////////////////////////////////////////////////////////////////////// 106 107 class GetBoundsResizeTester extends Frame { 108 Button b = new Button("Press"); 109 110 GetBoundsResizeTester(String name) 111 { 112 super(name); 113 final Frame f = this; 114 Panel p = new Panel(); 115 f.add(p); 116 p.setLayout(new BorderLayout()); 117 b.addActionListener(new ActionListener() { 118 public void actionPerformed(ActionEvent be){ 119 Point cp = b.getLocationOnScreen(); 120 TestDialog.output.append("Current Frame.getBounds() = " + f.getBounds()+"\n"); 121 } 122 }); 123 p.add("Center", b); 124 f.pack(); 125 } 126 127 public void start () 128 { 129 setVisible(true); 130 Robot robot; 131 try { 132 robot = new Robot(); 133 robot.waitForIdle(); 134 }catch(Exception ignorex) { 135 } 136 Point cp = b.getLocationOnScreen(); 137 TestDialog.output.append("Original Frame.getBounds() = " + this.getBounds()+"\n"); 138 } 139 140 public static void main(String[] args) 141 { 142 new GetBoundsResizeTester("GetBoundsResizeTester").start(); 143 } 144 145 }