Jump to content

Java Colour Palette

- - - - -

  • Please log in to reply
No replies to this topic

#1
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
import java.awt.*;

import javax.swing.*;

import java.awt.event.*;


public class JPalette extends JFrame {


   private JButton ChooseColour;

   private Color Colour= Color.lightGray;

   private Container c;


   public JPalette (){

      super( "JColour Changer" );


      c = getContentPane();

      c.setLayout( new FlowLayout() );


      ChooseColour= new JButton( "Colour Palette" );

      ChooseColour.addActionListener(new ActionListener() {

            public void actionPerformed( ActionEvent e ) {

               Colour =

                  JColorChooser.showDialog( JPalette.this,

                     "ChooseColour", Colour );


               if ( Colour== null )

                  Colour= Color.lightGray;


               c.setBackground(Colour);

               c.repaint();

            }

         }

      );

      c.add( ChooseColour);


      setSize( 400, 130 );

      show();

   }


   public static void main( String args[] )

   {

      JPalette app = new JPalette ();


      app.addWindowListener(

         new WindowAdapter() {

            public void windowClosing( WindowEvent e )

            {

               System.exit( 0 );

            }

         }

      );

   }

}
Enjoy.
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users