Ok, I know I keep coming here for Java help. I would love to go to a newsgroup but I honestly have no idea how to access them.
Here is the situation.
Class: CubeWindow, extends JFrame, implements WindowListener and KeyListener.
CubeWindow constructor creates two JPanels and some components that will go inside the JPanels. It listens to itself for KeyEvents and WindowEvents.
Inner Class CubeScroller extends JSlider implements ChangeListener.
CubeScroller constructor calls JSlider constructor and listens to itself for stateChange events.
if (source == rControl) {
int r = rControl.getValue();
int g = gControl.getValue();
int b = bControl.getValue();
String rgb = new String("RGB Setting: " + r + ", " + g + ", " + b + ".");
rgbDisplay.setText(rgb);
Color newColor = new Color(r, g, b);
paper.setBackground(newColor);
“paper” is one of the JPanels. It has no components put inside of it. The code above is simply one of the cases for the stateChange event for one of three very similar sliders.
So, to be perfectly clear, JFrame holds two JPanels. One JPanel is empty and is the target of events from the JSliders. the other JPanel holds the JSliders.
When I use the code given above, the “paper” JPanel changes color very nicely. I can access the whole color spectrum. No problems.
NOW, i eventually want to draw in the paper frame. When I attempt to do so I create another inner class called Paper which extends JPanel. I call the super() constructor for the Paper constructor (and do nothing else) and override its paint method to draw a single line (this is ALL the Paint() method does). that is the entirety of the class definition. Thus, instead of “paper” being a JPanel it is now a “Paper” object, sublassed from JPanel. Seems simple enough…
In the control JPanel are two sliders which set the x and y coordinates for a line (the other point stays 0, 0). Each time those particular sliders change I call paper.repaint().
If I then attempt to run the code it ends up that I cannot change the background color at all, ghosts of the slider I’m using appears in the paper panel (no matter which slider), and the line gets drawn but old ones don’t disappear.
What the hell is going on??? Why is anything different? What do i need to put in that overridden paint() method to get the background to correctly display, and the lines to work, and the damn ghosts to go away?
I can display any code which may help, or email the entire file (just a few k and its only one class file-- everything is inner classes when necessary). But I am totally baffled. It seems since I subclass JPanel nothing should really be causing this. :mad:
I should add, if I have the red green and blue sliders change the color of the line to draw there is no problem either… (I think that’s how I got it to work, but it still never cleared the Paper panel, but no ghosts anyway). So there is definitely som strange interaction with the paper.setBackground and its overridden paint() method.
I did hunt all over Sun’s website for some ideas, and I have been reading my Java books for further advice, but nothing was apparent. (I’ve been working on this all day, nonstop, frustrating fucking thing).