Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Colors in Java are composed by <code>RGB</code>values.</p> <pre><code>Color c = new Color(red, green, blue) </code></pre> <p><code>Red</code>, <code>Green</code>and <code>Blue</code> all have <code>integer</code> values between 0 and 255. Netbeans visual editor allows you to set both <code>maximum</code> and <code>minimum</code> values for your slider.</p> <p>To add transparency to a color use</p> <pre><code>Color c = new Color(red, green, blue, alpha) </code></pre> <p><code>Red</code>, <code>Green</code>, <code>Blue</code> and <code>Alpha</code>all have float values between 0.0 and 1.0.</p> <p>To change color when the slider is moved, add an event for when the mouse is dragged (you can do this using the visual editor) and use <code>slider.getValue()</code> to retrieve the value.</p> <p>To paint the rectangle near the <em>sliders</em> (there should be at least 3 sliders, one for each rbg component) retrieve the slider position and dimensions with <code>slider.getBounds()</code> (bounds contains <code>x</code> and <code>y</code> coordinates plus <code>width</code> and <code>height</code>)</p> <p>Example (draws a rectangle 30x30 20 pixels right the sliders)</p> <pre><code>private void mouseDragged(java.awt.event.MouseEvent evt) { color = new Color(sliderRed.getValue(), sliderGreen.getValue(), sliderBlue.getValue()); this.repaint(); } public void paint(Graphics g) { g.setColor(color) g.fillRect(sliderRed.getBounds().x + sliderRed.getBounds().width + 20, sliderRed.getBounds().y, 30, 30); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload