Color Pallet in Swing


import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;


public class MovingBannerColors extends JApplet implements Runnable,ChangeListener
  {
  
/*<Applet code="MovingBannerColors.class" height=400 width=400>
   </Applet>
*/
String s;
JLabel lbl;
JColorChooser palete;
public void init()
  {
  
  
     Container frame = getContentPane();    
        lbl = new JLabel("Welcome to My Blog -*- ");      
        frame.setLayout(new BorderLayout());
        palete=new JColorChooser();
        lbl.setFont(new Font("Helvetica", Font.BOLD, 30));
        lbl.setForeground(Color.blue);
        frame.add(lbl, BorderLayout.NORTH);
        frame.add(palete,BorderLayout.SOUTH);
        
        s= "Welcome to My Blog -*- ";
       palete.getSelectionModel().addChangeListener(this);
   }          
                public void stateChanged(ChangeEvent e)
                 {
                
                    lbl.setForeground(palete.getColor());
                }
              
              
                
 
 
public void start()
  {
Thread t=new Thread(this);
t.start();
}



public void run()
  {
   for(;;)
      {
      
      try{
      char c=s.charAt(0);      
       s=s.substring(1)+c;
      
       lbl.setText(s);
      
      
      Thread.sleep(200);
           }
       catch(InterruptedException e)
        {}
    
      }
}
}

No comments:

Post a Comment

Thanks for visiting my Blog!

Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog