Posted By


oakdragon on 01/02/15

Tagged


Statistics


Viewed 128 times
Favorited by 0 user(s)

JFrame Relocate


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.