Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ColorPeg.java

By: rburgosnavas on Dec 17th, 2012  |  syntax: Java  |  size: 1.59 KB  |  views: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.rburgos.mastermindtestlayout;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.beans.Transient;
  7.  
  8. import javax.swing.JComponent;
  9.  
  10.  
  11. @SuppressWarnings("serial")
  12. public class ColorPeg extends JComponent
  13. {
  14.     Dimension prefSize;
  15.     Color c;
  16.    
  17.     public ColorPeg(Color c)
  18.     {
  19.         prefSize = new Dimension(40, 40);
  20.         this.c = c;
  21.     }
  22.  
  23.         @Override
  24.     public void paintComponent(Graphics g)
  25.         {
  26.                 super.paintComponent(g);
  27.                 g.setColor(c);
  28.         g.fillRoundRect(1, 1, this.getWidth()-2, this.getHeight()-2, 15, 15);
  29.         g.setColor(c.brighter());
  30.         g.fillRoundRect(10, 10, this.getWidth()-15, this.getHeight()-15, 15, 15);
  31.         }
  32.        
  33.         @Override
  34.     public Dimension getPreferredSize()
  35.     {
  36.         return prefSize;
  37.     }
  38.  
  39.     @Override
  40.     public void setPreferredSize(Dimension preferredSize)
  41.     {
  42.         // TODO Auto-generated method stub
  43.         // super.setPreferredSize(preferredSize);
  44.         prefSize.setSize(preferredSize);
  45.     }
  46.  
  47.     @Override
  48.     @Transient
  49.     public Dimension getMaximumSize()
  50.     {
  51.         // TODO Auto-generated method stub
  52.         // return super.getMaximumSize();
  53.         return (new Dimension(200, 200));
  54.     }
  55.  
  56.     @Override
  57.     @Transient
  58.     public Dimension getMinimumSize()
  59.     {
  60.         // TODO Auto-generated method stub
  61.         // return super.getMinimumSize();
  62.         return (new Dimension(50, 50));
  63.     }
  64.    
  65.     public Color getColor()
  66.     {
  67.         return c;
  68.     }
  69.    
  70.     public void setColor(Color c)
  71.     {
  72.         this.c = c;
  73.     }
  74. }
clone this paste RAW Paste Data