1 /* 2 test 3 @bug 4985250 4 @summary COMPONENT_MOVED/RESIZED tardy events shouldn't be generated. 5 @author tav@sparc.spb.su 6 @run applet MovedResizedTardyEventTest.html 7 */ 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.applet.Applet; 12 import java.lang.reflect.InvocationTargetException; 13 14 public class MovedResizedTardyEventTest extends Applet { 15 Frame f1 = new Frame("F-1"); 16 Frame f2 = new Frame("F-2"); 17 18 boolean eventFlag = false; 19 20 public static void main(String[] args) { 21 Applet a = new MovedResizedTardyEventTest(); 22 a.start(); 23 } 24 25 public void start() { 26 f1.setVisible(true); 27 f2.setVisible(true); 28 29 try { 30 Thread.sleep(500); 31 } catch (InterruptedException e) {} 32 33 f1.addComponentListener(new ComponentAdapter() { 34 public void componentMoved(ComponentEvent e) { 35 MovedResizedTardyEventTest.this.eventFlag = true; 36 System.err.println(e); 37 } 38 public void componentResized(ComponentEvent e) { 39 MovedResizedTardyEventTest.this.eventFlag = true; 40 System.err.println(e); 41 } 42 }); 43 44 f1.toFront(); 45 46 waitForIdle(); 47 48 try { // wait more... 49 Thread.sleep(500); 50 } catch (InterruptedException e) {} 51 52 if (eventFlag) { 53 throw new RuntimeException("Test failed!"); 54 } 55 } 56 57 void waitForIdle() { 58 try { 59 Toolkit.getDefaultToolkit().sync(); 60 sun.awt.SunToolkit.flushPendingEvents(); 61 EventQueue.invokeAndWait( new Runnable() { 62 public void run() {} // Dummy implementation 63 }); 64 } catch(InterruptedException ie) { 65 System.err.println("waitForIdle, non-fatal exception caught:"); 66 ie.printStackTrace(); 67 } catch(InvocationTargetException ite) { 68 System.err.println("waitForIdle, non-fatal exception caught:"); 69 ite.printStackTrace(); 70 } 71 } 72 }