This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am a beginner and just learning to use swing widgets. I want to make a color maker to see what various rgb combos look like. I want three sliders, with values from 0-255, get the values, and re-color a region so I can see the effect. I have the sliders working, but don't know how to get the value from the change listener to the panel drawer. Here is what I have so far.
// An inner class for the slider event class RedChangeListener implements ChangeListener { public void stateChanged(ChangeEvent e){ JSlider redSource = (JSlider)e.getSource(); if (!redSource.getValueIsAdjusting()) { redValue = (int)redSource.getValue(); System.out.println (redValue); } } }
// Make the Draw Panel an inner class class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) {
int redValue = 127; /* This is where I would like to put the value from the slider. int greenValue = 127; int blueValue = 127; Color newColor = new Color(redValue, greenValue, blueValue);
//erase old oval by repainting rectangle g.fillRect(0, 0, this.getWidth(), this.getHeight());