By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

change frame to script

P: 3
Hi.
I have a program which changes a frame`s background on mouseover.
The problem is that I need several panels to change color on mouseover.....
If somebody could help.,...
Here is the code:

Expand|Select|Wrap|Line Numbers
  1. import java.awt.Color;
  2. import java.awt.event.MouseAdapter;
  3. import java.awt.event.MouseEvent;
  4. import javax.swing.JFrame;
  5.  
  6. /**
  7.  */
  8. public class MainFrame extends JFrame{
  9.  
  10.     /** Creates a new instance of MainFrame */
  11.     public MainFrame()
  12.     {
  13.         // add mouse listener
  14.         addMouseListener(new MouseAdapter() {
  15.  
  16.             // invoked when mouse enters the form
  17.             public void mouseEntered(MouseEvent e)
  18.             {
  19.                 // generate random color
  20.                 Color c = new Color((float)Math.random(), (float)Math.random(), 
  21.                         (float)Math.random());
  22.  
  23.                 // set background
  24.                 getContentPane().setBackground(c);
  25.             }
  26.         });
  27.     }
  28.  
  29.     /**
  30.      * @param args the command line arguments
  31.      */
  32.     public static void main(String args[]) {
  33.         java.awt.EventQueue.invokeLater(new Runnable() {
  34.             public void run()
  35.             {
  36.                 new MainFrame().setVisible(true);
  37.             }
  38.         });
  39.     }    
  40. }
  41.  
Dec 8 '06 #1
Share this Question
Share on Google+
1 Reply


DeMan
100+
P: 1,806
Have you got a handle for the panels? If so, you should be able to use much the same method
Dec 9 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.