I'm not too familiar with JApplet and paint and repaint(). Any help is appreciated.
I have an outside class "A" that extends JApplet and draws somestuff in its paint() I also have a private class "B" that sits inside A and also extends JApplet and draws stuff in its paint(). A's paint() evokes B's paint() so when A is ran both A an B are drawn.
I use a mouselistener to detect when a mouse is clicked and that's when B should repaint() and draw some new stuff and remove older stuff.
When I press my mouse, however, I see that B's repaint() does nothing. I print a couple debug messages to the console and I can tell that when B's repaint() is called nothing happens, i.e., the program should go through B's paint() again but it doesn't.
Here is the general structure, and again, any help is appreciated
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class A extends JApplet {
private class B extends JApplet implements MouseListener{
public B() { }
public void paint (Graphics g) {
// g.drawline ...
//System.out...
}
public void mousePressed(MouseEvent e) {
//System.out....
repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out....
repaint();
}
// ... rest of mouse listener interface
}
public void init() {
// setSize() ...
}
public void paint(Graphics g) {
// g.drawRectange ...
// Draw other stuff
B b = new B();
B.paint(g)
}
}
The problem is that nothing is reacting to the
repaint()request in yourBclass. It might trigger a repaint of theBclass but that doesn't mean that theAclass gets repainted, nobody told him. Like as you said:That's right, but it doesn't mean it's the same the other way around.
When you want that the
Aclass should repaint it's content you have to callrepaint()on theAobject, since that's the class you want to be repainted.