Relocate JFrame


SUBMITTED BY: knightley

DATE: Sept. 3, 2015, 9:32 a.m.

FORMAT: Java

SIZE: 550 Bytes

HITS: 608

  1. // relocate only works on defualt monitor
  2. public void relocate(JFrame f){
  3. /*If this function is called, it will relocate
  4. the window to a new random position on the screen
  5. */
  6. Random r = new Random();
  7. // Find Screen size
  8. Toolkit tk = Toolkit.getDefaultToolkit();
  9. Dimension d = tk.getScreenSize();
  10. // use the Dimension find and reset width and height
  11. int x = r.nextInt(d.width - getWidth());
  12. int y = r.nextInt(d.height - getHeight());
  13. f.setLocation(x,y);
  14. };

comments powered by Disqus