39 import java.lang.reflect.InvocationTargetException; 40 import java.util.TooManyListenersException; 41 import javax.swing.JFrame; 42 import javax.swing.JTextArea; 43 import javax.swing.SwingUtilities; 44 import test.java.awt.regtesthelpers.Util; 45 46 public class DisposeFrameOnDragTest { 47 48 private static JTextArea textArea; 49 50 public static void main(String[] args) throws Throwable { 51 52 SwingUtilities.invokeAndWait(new Runnable() { 53 @Override 54 public void run() { 55 constructTestUI(); 56 } 57 }); 58 59 Util.waitForIdle(null); 60 try { 61 Point loc = textArea.getLocationOnScreen(); 62 Util.drag(new Robot(), 63 new Point((int) loc.x + 3, (int) loc.y + 3), 64 new Point((int) loc.x + 40, (int) loc.y + 40), 65 InputEvent.BUTTON1_MASK); 66 } catch (AWTException ex) { 67 throw new RuntimeException("Could not initiate a drag operation"); 68 } 69 Util.waitForIdle(null); 70 } 71 72 private static void constructTestUI() { 73 final JFrame frame = new JFrame("Test frame"); 74 textArea = new JTextArea("Drag Me!"); 75 try { 76 textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() { 77 @Override 78 public void drop(DropTargetDropEvent dtde) { 79 //IGNORE 80 } 81 82 @Override 83 public void dragOver(DropTargetDragEvent dtde) { 84 frame.dispose(); 85 } 86 }); 87 } catch (TooManyListenersException ex) { 88 throw new RuntimeException(ex); 89 } | 39 import java.lang.reflect.InvocationTargetException; 40 import java.util.TooManyListenersException; 41 import javax.swing.JFrame; 42 import javax.swing.JTextArea; 43 import javax.swing.SwingUtilities; 44 import test.java.awt.regtesthelpers.Util; 45 46 public class DisposeFrameOnDragTest { 47 48 private static JTextArea textArea; 49 50 public static void main(String[] args) throws Throwable { 51 52 SwingUtilities.invokeAndWait(new Runnable() { 53 @Override 54 public void run() { 55 constructTestUI(); 56 } 57 }); 58 59 Robot testRobot = null; 60 try { 61 testRobot = new Robot(); 62 } catch(AWTException ex) { 63 throw new RuntimeException("Error while creating Robot"); 64 } 65 66 Util.waitForIdle(testRobot); 67 68 Point loc = textArea.getLocationOnScreen(); 69 Util.drag(testRobot, 70 new Point((int) loc.x + 3, (int) loc.y + 3), 71 new Point((int) loc.x + 40, (int) loc.y + 40), 72 InputEvent.BUTTON1_MASK); 73 74 Util.waitForIdle(testRobot); 75 76 testRobot.delay(200); 77 } 78 79 private static void constructTestUI() { 80 final JFrame frame = new JFrame("Test frame"); 81 textArea = new JTextArea("Drag Me!"); 82 try { 83 textArea.getDropTarget().addDropTargetListener(new DropTargetAdapter() { 84 @Override 85 public void drop(DropTargetDropEvent dtde) { 86 //IGNORE 87 } 88 89 @Override 90 public void dragOver(DropTargetDragEvent dtde) { 91 frame.dispose(); 92 } 93 }); 94 } catch (TooManyListenersException ex) { 95 throw new RuntimeException(ex); 96 } |