September 07, 2010, 04:48:50 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Vibrating JFrame such as the msn messenger "nudge" function  (Read 985 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: June 01, 2009, 06:37:13 AM »

Original written by Arthur but modified by me

Code
GeSHi (java):
  1. package gui;
  2.  
  3. /* * To change this template, choose Tools | Templates * and open the template in the editor. */
  4. import java.awt.BorderLayout;
  5. import java.awt.FlowLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import javax.swing.UIManager;
  12. /** * * @author Arthur */
  13. public class VibratingWindow extends JFrame
  14. {
  15. private static final long serialVersionUID = 1L;
  16. public VibratingWindow()
  17. {
  18. setTitle("Vibrating Window");
  19. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. setLayout(new BorderLayout());
  21. JPanel buttonPanel = new JPanel();
  22. JButton vibrateButton = new JButton("VIBRATE");
  23. buttonPanel.setLayout(new FlowLayout());
  24. buttonPanel.add(vibrateButton); add(buttonPanel, BorderLayout.SOUTH);
  25. setSize(600, 300); setVisible(true);
  26. vibrateButton.addActionListener(new ActionListener()
  27. {
  28. public void actionPerformed(ActionEvent e)
  29. {
  30. vibrate();
  31. }
  32. });
  33. }
  34.  
  35. private void vibrate() {
  36. final int originalX = this.getLocationOnScreen().x;
  37. final int originalY = this.getLocationOnScreen().y;
  38. try {
  39. for(int i = 0; i < 20; i++) {
  40. Thread.sleep(10);
  41. setLocation(this.getLocationOnScreen().x, this.getLocationOnScreen().y + 10);
  42. Thread.sleep(10);
  43. setLocation(this.getLocationOnScreen().x, this.getLocationOnScreen().y - 10);
  44. Thread.sleep(10);
  45. setLocation(this.getLocationOnScreen().x - 10, this.getLocationOnScreen().y); Thread.sleep(10);
  46. setLocation(originalX, originalY); }
  47. }
  48. catch (Exception err) { err.printStackTrace();
  49. }
  50. }
  51.  
  52. public static void main(String[] args) throws Exception {
  53. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  54. VibratingWindow vibrator = new VibratingWindow();
  55. vibrator.setLocation(300, 300);
  56. }
  57. }
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: June 01, 2009, 06:37:13 AM »

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.245 seconds with 34 queries.

Google visited last this page Yesterday at 05:07:04 AM